Skip to content

Commit f0de34d

Browse files
authored
doc(ncnn): update README (Megvii-BaseDetection#1519)
doc(ncnn): update README
1 parent f44fcdd commit f0de34d

File tree

2 files changed

+37
-9
lines changed

2 files changed

+37
-9
lines changed

demo/ncnn/README.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# YOLOX-ncnn
2+
3+
Compile files 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+
6+
## Acknowledgement
7+
8+
* [ncnn](https://github.com/Tencent/ncnn)

demo/ncnn/cpp/README.md

Lines changed: 29 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,20 @@
11
# YOLOX-CPP-ncnn
22

33
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.
54

65
## Tutorial
76

87
### Step1
98
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.
109

1110
### 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.
1312
For example, if you want to generate onnx file of yolox-s, please run the following command:
1413
```shell
1514
cd <path of yolox>
1615
python3 tools/export_onnx.py -n yolox-s
1716
```
18-
Then, a yolox.onnx file is generated.
17+
Then a yolox.onnx file is generated.
1918

2019
### Step3
2120
Generate ncnn param and bin file.
@@ -25,14 +24,15 @@ cd build/tools/ncnn
2524
./onnx2ncnn yolox.onnx model.param model.bin
2625
```
2726

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:
2928
```shell
30-
Unsupported slice step !
29+
Unsupported slice step!
3130
```
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.
3332

3433
### 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).
35+
3636
Before (just an example):
3737
```
3838
295 328
@@ -49,7 +49,7 @@ Crop Slice_39 1 1 677 682 -23309=1,1 -23310=1,214748
4949
Concat Concat_40 4 1 652 672 662 682 683 0=0
5050
...
5151
```
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).
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).
5353
* Then remove 10 lines of code from Split to Concat, but remember the last but 2nd number: 683.
5454
* Add YoloV5Focus layer After Input (using previous number 683):
5555
```
@@ -71,14 +71,34 @@ Use ncnn_optimize to generate new param and bin:
7171
```
7272

7373
### 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.
7575

7676
### Step7
7777
Inference image with executable file yolox, enjoy the detect result:
7878
```shell
7979
./yolox demo.jpg
8080
```
8181

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.
84+
85+
```shell
86+
# take yolox-s as an example
87+
python3 tools/export_torchscript.py -n yolox-s -c /path/to/your_checkpoint_files
88+
```
89+
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
93+
./pnnx yolox/yolox.torchscript.pt inputshape=[1,3,640,640]
94+
# 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.
101+
82102
## Acknowledgement
83103

84104
* [ncnn](https://github.com/Tencent/ncnn)

0 commit comments

Comments
 (0)