yolov5-6.0 Android deployment and pit avoidance guide (under windows)


foreword

In the past few days, if you want to implement a deep learning model deployed on Android, take yolov5-6.0 as an example, the text is as follows:

Reference link: Reference


1. Preparation

1、Android Studio

Download URL: Android studio
installation reference: installation

2. ncnn-yolov5-android source code

Download address: ncnn_yolov5

3、ncnn-android-vulkan包

Download link: It is recommended to download ncnn-20210525-android-vulkan.zip on ncnn windows


2. Model conversion

Here, I will directly use the official yolov5s.pt as an example, and then first you have to set pt->onnx. This step, there are many tutorials on the Internet, which is skipped here.

1.onnx->NCNN

  • Simple and rude, a must for lazy people (recommended, can save a lot of trouble):
    convert directly through this website: onnx2ncnn
  • Convert through the ncnn package downloaded in 1.3

After the conversion is successful, you will get yolov5s.param and yolov5s.bin, as follows:
insert image description here


3. File placement and modification

1. Placement:

Put the compressed package downloaded in 1 and 3 under app/src/main/jni in 1 and 2 (move all the subfiles in ncnn here), as shown in the figure below: Then use our 1 and
insert image description here
1 Open the project in Android studio.

2. Model replacement

Replace the .param and .bin files in the original path with the .param and .bin files converted in 2.1. The path is as shown in the figure below:
insert image description here

3. CMakeLists.txt modification

The CMakeLists.txt path is as follows:
insert image description here

Modify the path of ncnn_DIR (if you place it according to 3 and 1), the modified file is as follows:
insert image description here

4. .param modification

Modify the .param file in 3.2, and only modify the last three parameters in Reshape, as follows:
insert image description here
Other parameters may be different, because it is related to the v5 version you choose.

5. cpp modification

Modify the yolov5ncnn_jni.cpp file, the file path is as follows:
insert image description here
modify the parts of stride 16 and stride 32 in the cpp file, the modified file is as follows:
insert image description here

The modified content here comes from the last two Permute in your own .param file, as follows:
insert image description here

6. Category modification (optional)

If you want to deploy your own model, then you need to modify it in yolov5ncnn_jni.cpp. Here I use the official model, so no modification is made, as follows:
insert image description here

7. Other toolkits:

Open the following interface in Android Studio:
insert image description here
Or insert image description here
check the toolkit as follows:
insert image description here
This is to select the version according to your own needs
insert image description here
. The version recommended by NDK is:
insert image description here

After these are checked, you can install them directly

Four, run

After these modifications are completed, connect the mobile phone to the computer and run it. The premise is that your mobile phone must turn on the developer mode and agree to USB debugging. Take my mobile phone (HUAWEI Mate40e) as an example, the way each mobile phone enters the developer mode It’s different, you can use Baidu by yourself:
insert image description here
insert image description here
just turn on these two options, and then run our app, and the project will appear on our mobile phone, as follows, the
insert image description here
effect picture is:
insert image description here


Four, BUG record

1. NDK problem

When running for the first time, the following error message appeared:
insert image description here
The most likely problem is our NDK installation problem, the solution can refer to here: Bug solution
It is recommended to use the second method here, which is simple and effective, and it is feasible to test it yourself.


Summarize

The above is the whole content of this article. If the whole article goes smoothly, you should not encounter many problems. I only encountered one. If there are still questions, please correct me in the comment area.

Guess you like

Origin blog.csdn.net/qq_55068938/article/details/128832779