Yolov5 is deployed on the Android platform through ncnn

The relationship between ncnn and yolov5

Insert image description here

ncnn Android environment deployment

(1) Download ncnn-yolov5-android source code
download
(2) Download ncnn-android-vulkan package
download
Insert image description here
Select ncnn-20210525-android-vulkan.zip to download
(3) Unzip the downloaded ncnn-20210525-android-vulkan.zip Then put it under ncnn/cpp:
Insert image description here
Insert image description here

3.ncnn model conversion

First install the relevant libraries
Insert image description here
pip install onnx coremltools onnx-simplifier

(1) Use /yolov5/module/export.py to generate the onnx file.
In the yolov5 file, enter the command line with cmd and enter the following statement to convert the model (–weights means the location and name of the weight file that needs to be converted)
Insert image description here
python models/export.py --weights yolov5s .ptAfter
executing this sentence, three files, yolov5s.onnx, yolov5s.mlmodel and yolov5s.torchscript.pt, will be generated in the same folder as the weight file.

Convert onnx to ncnn

Insert image description here
Conversion tool URL

Insert image description here
Select the just generated onnx to convert ncnn. If the conversion is successful, it can be directly deployed to Android. However, if an error is reported, we need to make a small modification to the generated file to deploy Android.
Insert image description here
Solution to the above error report:
First, we download the two generated files.

Insert image description hereUse a text editor to open the .param file and prepare it. Here I opened it directly with pycharm. Here is
Insert image description here
a tool recommended: Netron. We can use this to open our .param file first to see the model data.
Netron

Insert image description here
Find Concat and record the penultimate parameter. (Will be used later)
Then add "YoloV5Focus focus 1 1 images" + the previously recorded parameter "/model.0/Concat_output_0"
under Input. The modified param is shown below. There were originally 181 lines. After deleting the Split, Crop, and Concat layers, and adding the YoloV5Focus layer, the 6 ops were replaced by 1 op. A total of 5 lines were reduced. Subtract 5 from the layer count at the beginning and rewrite it to 176.
Insert image description here
Insert image description here

Insert image description here

Insert image description here
The modifications of stride16 and stride32 are modified according to the number after Permute in the .param file, as follows:
Insert image description here

Insert image description here
Insert image description here
After changing these, it will be ok.
The following is the running effect:
Insert image description here

Guess you like

Origin blog.csdn.net/officewords/article/details/130230572