You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: demo/ncnn/cpp/README.md
+29-9Lines changed: 29 additions & 9 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,21 +1,20 @@
1
1
# YOLOX-CPP-ncnn
2
2
3
3
Cpp file compile of YOLOX object detection base on [ncnn](https://github.com/Tencent/ncnn).
4
-
YOLOX is included in ncnn now, you could also try building from ncnn, it's better.
5
4
6
5
## Tutorial
7
6
8
7
### Step1
9
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.
10
9
11
10
### Step2
12
-
Use provided tools to generate onnx file.
11
+
First, we try the original onnx2ncnn solution by using provided tools to generate onnx file.
13
12
For example, if you want to generate onnx file of yolox-s, please run the following command:
14
13
```shell
15
14
cd<path of yolox>
16
15
python3 tools/export_onnx.py -n yolox-s
17
16
```
18
-
Then, a yolox.onnx file is generated.
17
+
Then a yolox.onnx file is generated.
19
18
20
19
### Step3
21
20
Generate ncnn param and bin file.
@@ -25,14 +24,15 @@ cd build/tools/ncnn
25
24
./onnx2ncnn yolox.onnx model.param model.bin
26
25
```
27
26
28
-
Since Focus module is not supported in ncnn. Warnings like:
27
+
Since Focus module is not supported in ncnn. You will see warnings like:
29
28
```shell
30
-
Unsupported slice step!
29
+
Unsupported slice step!
31
30
```
32
-
will be printed. However, don't worry! C++ version of Focus layer is already implemented in yolox.cpp.
31
+
However, don't worry on this as a C++ version of Focus layer is already implemented in yolox.cpp.
33
32
34
33
### Step4
35
-
Open **model.param**, and modify it.
34
+
Open **model.param**, and modify it. For more information on the ncnn param and model file structure, please take a look at this [wiki](https://github.com/Tencent/ncnn/wiki/param-and-model-file-structure).
* 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
+
* 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).
53
53
* Then remove 10 lines of code from Split to Concat, but remember the last but 2nd number: 683.
54
54
* Add YoloV5Focus layer After Input (using previous number 683):
55
55
```
@@ -71,14 +71,34 @@ Use ncnn_optimize to generate new param and bin:
71
71
```
72
72
73
73
### Step6
74
-
Copy or Move yolox.cpp file into ncnn/examples, modify the CMakeList.txt, then build yolox
74
+
Copy or Move yolox.cpp file into ncnn/examples, modify the CMakeList.txt to add our implementation, then build.
75
75
76
76
### Step7
77
77
Inference image with executable file yolox, enjoy the detect result:
78
78
```shell
79
79
./yolox demo.jpg
80
80
```
81
81
82
+
### Bounus Solution:
83
+
As ncnn has released another model conversion tool called [pnnx](https://zhuanlan.zhihu.com/p/427620428) which directly finishs the pytorch2ncnn process via torchscript, we can also try on this.
Then a `yolox.torchscript.pt` will be generated. Copy this file to your pnnx build directory (pnnx also provides pre-built packages [here](https://github.com/pnnx/pnnx/releases/tag/20220720)).
90
+
91
+
```shell
92
+
# suppose you put the yolox.torchscript.pt in a seperate folder
# for zsh users, please use inputshape='[1,3,640,640]'
95
+
```
96
+
Still, as ncnn does not support `slice` op as we mentioned in [Step3](https://github.com/Megvii-BaseDetection/YOLOX/tree/main/demo/ncnn/cpp#step3). You will still see the warnings during this process.
97
+
98
+
Then multiple pnnx related files will be genreated in your yolox folder. Use `yolox.torchscript.ncnn.param` and `yolox.torchscript.ncnn.bin` as your converted model.
99
+
100
+
Then we can follow back to our [Step4](https://github.com/Megvii-BaseDetection/YOLOX/tree/main/demo/ncnn/cpp#step4) for the rest of our implementation.
0 commit comments