Android deployment of YOLOv5, based on tflite

environment

  • window 10 64bit

  • yolov5 v6.2

  • torch1.7.1+cuda101

  • tensorflow-gpu 2.9.1

foreword

In the previous article, with the help of NCNN, run YOLOv5 target detection on Android and yolov5 target detection on Android. Using the torchscript method, we used ncnnand torchscriptmethods respectively to YOLOv5deploy androidto the mobile phone. In this article we will use another way tfliteto deploy, so use whichever you like.

Specific steps

The latest v6.2 version code is used here, and the official yolov5s.ptmodel . To use your own data set, you need to train yourself first. For the training steps, you can refer to the link at the end of the article.

The model conversion process also tensorflowrequires the environment, install it

pip instal tensorflow-gpu

Then you can use export.pythe script to convert, the command is as follows

python export.py --weights yolov5s.pt --include tflite --img 416

The parameter weightsspecifies .ptthe model, --includethe parameter specifies the target model to be converted, and --imgthe parameter specifies the image size

It can be seen that the converted model is yolov5s-fp16.tflite, at the same time, under the same directory, there is also a folder yolov5s_saved_model, which contains .pbthe file , which is protobufthe file. Here is a detail, that is, .ptthe file is first converted to .pband then converted .tfliteto .

Next, use the script detect.pyto verify it, using .tflitethe model generated above

python detect.py --weights yolov5s-fp16.tflite --source data/images/bus.jpg --img 416

There is no problem with detection

09ba91d9d382aa2969b9883bbdabd15c.jpeg

With the model file, then you can come to androidthe end , I uploaded the sample code githubto , you can directlyclone

git clone https://github.com/xugaoxiang/yolov5_android_tflite.git

What needs to be replaced yolov5_android_tflite/app/src/main/assetsare 2 files under the folder, class.txtandyolov5s-fp16.tflite

After compiling and installing it on the mobile phone, you can start the camera-based target detection

References

  • Running YOLOv5 object detection on Android with NCNN

  • Windows 10 install cuda and cudnn

  • YOLOv5 model training

  • YOLOv5 version 5.0

  • Solution to Android studio gradle build failure

Guess you like

Origin blog.csdn.net/djstavaV/article/details/126737098
Recommended