Feng Wang commited on
Commit
65998a0
·
1 Parent(s): 7ab6881

chore(demo): add ncnn cpp README

Browse files
Files changed (1) hide show
  1. demo/ncnn/cpp/README.md +83 -0
demo/ncnn/cpp/README.md ADDED
@@ -0,0 +1,83 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # YOLOX-CPP-NCNN
2
+
3
+ Cpp file compile of YOLOX object detection base on [ncnn](https://github.com/Tencent/ncnn).
4
+
5
+ ## Tutorial
6
+
7
+ ### Step1
8
+ Clone [ncnn](https://github.com/Tencent/ncnn) first, then please following [build tutorial of ncnn](https://github.com/Tencent/ncnn/wiki/how-to-build) to build on your own device.
9
+
10
+ ### Step2
11
+ Use provided tools to generate onnx file.
12
+ For example, if you want to generate onnx file of yolox-s, please run the following command:
13
+ ```shell
14
+ cd <path of yolox>
15
+ python3 tools/export_onnx.py -n yolox-s
16
+ ```
17
+ Then, a yolox.onnx file is generated.
18
+
19
+ ### Step3
20
+ Generate ncnn param and bin file.
21
+ ```shell
22
+ cd <path of ncnn>
23
+ cd build/tools/ncnn
24
+ ./onnx2ncnn yolox.onnx yolox.param yolox.bin
25
+ ```
26
+
27
+ Since Focus module is not supported in ncnn. Warnings like:
28
+ ```shell
29
+ Unsupported slice step !
30
+ ```
31
+ will be printed. However, don't worry! C++ version of Focus layer is already implemented in yolox.cpp.
32
+
33
+ ### Step4
34
+ Open **yolox.param**, and modify it.
35
+ Before (just an example):
36
+ ```
37
+ 295 328
38
+ Input images 0 1 images
39
+ Split splitncnn_input0 1 4 images images_splitncnn_0 images_splitncnn_1 images_splitncnn_2 images_splitncnn_3
40
+ Crop Slice_4 1 1 images_splitncnn_3 647 -23309=1,0 -23310=1,2147483647 -23311=1,1
41
+ Crop Slice_9 1 1 647 652 -23309=1,0 -23310=1,2147483647 -23311=1,2
42
+ Crop Slice_14 1 1 images_splitncnn_2 657 -23309=1,0 -23310=1,2147483647 -23311=1,1
43
+ Crop Slice_19 1 1 657 662 -23309=1,1 -23310=1,2147483647 -23311=1,2
44
+ Crop Slice_24 1 1 images_splitncnn_1 667 -23309=1,1 -23310=1,2147483647 -23311=1,1
45
+ Crop Slice_29 1 1 667 672 -23309=1,0 -23310=1,2147483647 -23311=1,2
46
+ Crop Slice_34 1 1 images_splitncnn_0 677 -23309=1,1 -23310=1,2147483647 -23311=1,1
47
+ Crop Slice_39 1 1 677 682 -23309=1,1 -23310=1,2147483647 -23311=1,2
48
+ Concat Concat_40 4 1 652 672 662 682 683 0=0
49
+ ...
50
+ ```
51
+ * Change first number for 295 to 295 - 9 = 286(since we will remove 10 layers and add 1 layers, total layers number should minus 9).
52
+ * Then remove 10 lines of code from Split to Concat, but remember the last but 2nd number: 683.
53
+ * Add YoloV5Focus layer After Input (using previous number 683):
54
+ ```
55
+ YoloV5Focus focus 1 1 images 683
56
+ ```
57
+ After(just an exmaple):
58
+ ```
59
+ 286 328
60
+ Input images 0 1 images
61
+ YoloV5Focus focus 1 1 images 683
62
+ ...
63
+ ```
64
+
65
+ ### Step5
66
+ Use onnx_optimze to generate new param and bin:
67
+ ```shell
68
+ # suppose you are still under ncnn/build/tools/ncnn dir.
69
+ ../ncnnoptimize model.param model.bin yolox.param yolox.bin 65536
70
+ ```
71
+
72
+ ### Step6
73
+ Copy or Move yolox.cpp file into ncnn/examples, modify the CMakeList.txt, then build yolox
74
+
75
+ ### Step7
76
+ Inference image with executable file yolox, enjoy the detect result:
77
+ ```shell
78
+ ./yolox demo.jpg
79
+ ```
80
+
81
+ ## Acknowledgement
82
+
83
+ * [ncnn](https://github.com/Tencent/ncnn)