Skip to content

Commit

Permalink
ncnn-jni: add MNIST inference using NCNN (#186)
Browse files Browse the repository at this point in the history
  • Loading branch information
zhouwg authored May 22, 2024
1 parent e1c6cf4 commit 896a56c
Show file tree
Hide file tree
Showing 23 changed files with 2,538 additions and 421 deletions.
12 changes: 12 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,9 @@ here are some screenshots to demostrate CV inference by running the excellent <a
![988568755](https://github.com/zhouwg/kantv/assets/6889919/49c7e22e-0e4c-4ece-b690-04d59ac1382f)
![1730654667](https://github.com/zhouwg/kantv/assets/6889919/83ef3e44-92ee-4c00-b000-840a13097544)
<details>
<summary>some other screenshots</summary>
<ol>
Expand Down Expand Up @@ -356,6 +359,15 @@ Report issue in various Android-based phone or even submit PR to this project is
</ul>
### This project is suitable for(本项目适合于)
- Students:understand calculus/linear algebra/mathematical statistics and probability theory, have some experiences in C/C++ development, want to learn Android software development(UI development, NDK development and Android AI application development); 学生:了解微积分,线性代数,数理统计与概率论, 且有一定的C/C++开发经验, 希望学习Android开发(UI开发与NDK开发与Android端侧AI应用开发);
- Programmers: have some experiences in C/C++/Java software development, know nothing about real/hardcore AI technology, want to learn AI technology in depth(know how); 程序员:有一定的C/C++/Java开发经验,几乎不懂真正的AI技术,希望深入学习AI技术(know how);
- AI researchers/developers: validate/verify AI(ASR, TTS, CV, NLP, LLM...) algorithm in the framework provided in this project for Android device; AI特定领域(ASR, TTS, CV, NLP, LLM,...)的算法研究/开发人员:在本项目提供的框架中调试/验证Android设备上的AI特定领域算法;
- Authors/maintainers of AI inference framework: compare the advantages of <a href="https://github.com/ggerganov/ggml">ggml</a> and <a href="https://github.com/Tencent/ncnn">ncnn</a>; AI推理框架的开发人员: 对比ggml与ncnn两个端侧推理框架的优点,相互借鉴;
### License
```
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -277,11 +277,13 @@ public class CDEUtils {
//inference using NCNN
public static final int BENCHMARK_CV_RESNET = 9;
public static final int BENCHMARK_CV_SQUEEZENET = 10;
public static final int BENCHAMRK_ASR_NCNN = 11;
public static final int BENCHAMRK_TTS_NCNN = 12;
public static final int BENCHMARK_CV_MNIST_NCNN = 11;
public static final int BENCHMARK_ASR_NCNN = 12;
public static final int BENCHMARK_TTS_NCNN = 13;

//ncnn backend
public static final int NCNN_BACKEND_CPU = 0;
public static final int NCNN_BACKEND_GPU = 0;
public static final int NCNN_BACKEND_GPU = 1;


//keep sync with ggml-qnn.h
Expand Down Expand Up @@ -3959,11 +3961,15 @@ public static String getBenchmarkDesc(int benchmarkIndex) {
case BENCHMARK_CV_SQUEEZENET:
return "SQUEEZENET inference using NCNN";

case BENCHAMRK_ASR_NCNN:
case BENCHMARK_ASR_NCNN:
return "ASR inference using NCNN";

case BENCHAMRK_TTS_NCNN:
case BENCHMARK_TTS_NCNN:
return "TTS inference using NCNN";

case BENCHMARK_CV_MNIST_NCNN:
return "MNIST inference using NCNN";

}

return "unknown";
Expand Down
15 changes: 13 additions & 2 deletions cdeosplayer/cdeosplayer-lib/src/main/java/org/ncnn/ncnnjava.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,19 @@ public class ncnnjava
public native boolean closeCamera();
public native boolean setOutputWindow(Surface surface);

public native String detectResNet(Bitmap bitmap, boolean use_gpu);
public native String detectSqueezeNet(Bitmap bitmap, boolean use_gpu);

/**
* @param ncnnmodelParam param file of ncnn model
* @param ncnnmodelBin bin file of ncnn model
* @param userData ASR: /sdcard/kantv/jfk.wav / LLM: user input / TEXT2IMAGE: user input / ResNet&SqueezeNet&MNIST: image path / TTS: user input
* @param bitmap
* @param nBenchType 1: NCNN_RESNET 2: NCNN_SQUEEZENET 3: NCNN_MNIST
* @param nThreadCounts 1 - 8
* @param nBackendType 0: NCNN_BACKEND_CPU 1: NCNN_BACKEND_GPU
* @param nOpType type of NCNN OP
* @return
*/
public static native String ncnn_bench(String ncnnmodelParam, String ncnnmodelBin, String userData, Bitmap bitmap, int nBenchType, int nThreadCounts, int nBackendType, int nOpType);

static {
System.loadLibrary("ncnn-jni");
Expand Down
Binary file added cdeosplayer/kantv/src/main/assets/mnist-4.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added cdeosplayer/kantv/src/main/assets/mnist-int8.bin
Binary file not shown.
8 changes: 8 additions & 0 deletions cdeosplayer/kantv/src/main/assets/mnist-int8.param
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
7767517
6 6
Input in 0 1 data 0=28 1=28 2=1
Convolution conv0 1 1 data conv0 0=8 1=5 4=2 5=1 6=200 8=2 9=1
Pooling pool0 1 1 conv0 pool0 1=2 2=2 5=1
Convolution conv1 1 1 pool0 conv1 0=16 1=5 4=2 5=1 6=3200 8=2 9=1
Pooling pool1 1 1 conv1 pool1 1=3 2=3 5=1
InnerProduct fc 1 1 pool1 fc 0=10 1=1 2=2560 8=2
Binary file not shown.
Binary file added cdeosplayer/kantv/src/main/assets/mnist.bin
Binary file not shown.
8 changes: 8 additions & 0 deletions cdeosplayer/kantv/src/main/assets/mnist.param
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
7767517
6 7
Input in 0 1 data 0=28 1=28 2=1
Convolution conv0 1 1 data conv0 0=8 1=5 4=2 5=1 6=200 9=1
Pooling pool0 1 1 conv0 pool0 1=2 2=2 5=1
Convolution conv1 1 1 pool0 conv1 0=16 1=5 4=2 5=1 6=3200 9=1
Pooling pool1 1 1 conv1 pool1 1=3 2=3 5=1
InnerProduct fc 1 1 pool1 fc 0=10 1=1 2=2560
Binary file added cdeosplayer/kantv/src/main/assets/mnist.param.bin
Binary file not shown.
Binary file removed cdeosplayer/kantv/src/main/assets/scrfd_34g-opt2.bin
Binary file not shown.
Loading

0 comments on commit 896a56c

Please sign in to comment.