Small knowledge, big challenge! This article is participating in the creation activity of “Essential Tips for Programmers”.
The environment
- Ubuntu 18.04 64 – bit
- GTX 1070Ti
- Anaconda with python 3.8
- Pytorch 1.7
- Cuda 10.1
preface
Just yesterday (October 13, 2021), YoloV5 released V6.0, which incorporates many new features from V5.0 and tweaks to the network architecture. New smaller (Nano) models P5(YOLOv5n) and P6(YOLOv5n6) were introduced. The Nano model retains the depth of the Yolov5s model, while the width is reduced from 0.5 to 0.25. After this operation, the total parameter is reduced by 75%, from 7.5M to 1.9M. In this case, This is ideal for mobile or CPU environments.
In terms of performance metrics, V6.0 has also improved, see the chart below
New features
The main new features of V6.0 are summarized below
-
Integrated the Roboflow
Roboflow, as mentioned earlier, exposes a number of very useful data sets, which can be used directly on V6.0 at github.com/ultralytics… Very convenient
-
Supports export of Tensorflow and Keras models
Py –include saved_model pb tflite TFJS to export tensorFlow, Keras, tflite, and tf.js models
-
Supports both OpenCV DNN and ONNX Runtime
The exported onNx supports both OpencV DNN and OnNx Runtime
python export --weights yolov5s.pt --include onnx --opset 12 --dynamic Copy the code
Python detect.py –weights yolov5s.onnx — DNN
-
Model structure
- with
Conv(k=6, s=2, p=2)
Instead ofFocus
Layer, mainly for the convenience of model export - use
SPPF
Instead ofSPP
层 - To reduce
P3
The backbone layerC3
- will
SPPF
Put it behind the trunk - In the last one
C3
Reintroduce shortcuts in the trunk layer - Update hyperparameter
- with
-
Flask REST API added
Web API support is provided, and remote testing is very convenient, as is common on open platforms
Flask API practice
Download V6.0 source code
Git clone - b v6.0 https://github.com/ultralytics/yolov5.git CD yolov5 / utils/flask -- rest APICopy the code
Install necessary dependencies and start services
PIP install flask # You can specify a specific port by using the port argument, such as --port 8080 python restapi.pyCopy the code
Yolov5 and yolov5s.pt files are stored in ~/. Cache /torch/hub
(base) xugaoxiang@1070Ti:~/workshop/yolov5/data/images$ ls ~/.cache/torch/hub/ultralytics_yolov5_master/ CONTRIBUTING.md detect.py export.py LICENSE __pycache__ requirements.txt tutorial.ipynb val.py data Dockerfile hubconf.py models README.md train.py utils yolov5s.ptCopy the code
This download action, by default, occurs every time the script executes. You can use the existing version by modifying restapi.py
Model = torch. Hub.load (" yolov5", "yolov5s", force_reload=False)Copy the code
After the service is started, we go to the client and use curl command to test it
The curl -x POST - F image = @ zidane. JPG 'http://192.168.1.140:5000/v1/object-detection/yolov5s'Copy the code
After success, you can get the result returned by the interface
(base) xugaoxiang@1070Ti:~/workshop/yolov5/data/images$ curl -X POST -F [email protected] 'http://192.168.1.140:5000/v1/object-detection/yolov5s' [{" xmin ": 752.0," ymin ": 46.0," xmax ": 1148.0," ymax ": 716.0," confidence ": 0.875," class ": 0," name ":" person "}, {" xmin ": 100.0," ymin" : 1002.0, 201.5, "xmax" : "ymax" : 718.5, "confidence" : 0.5795898438, "class" : 0, "name" : "person"}, {" xmin ": 438.25," ymin ": 422.0," xmax ": 509.75, ymax: 720.0," confidence ": 0.5219726562," class ": 27," name ":" tie "}]Copy the code
or
The postman test uses a POST request with the URL http://192.168.1.140
If python is used for requests, the project also provides an example example_request.py, using the Request module
Related reading
- Ubuntu installation cuda
- Install CUDA and CUDNN for Windows 10
- Yolov5 model training
- Yolov5 packaging exe
- PIP install yolov5
- Streamlit deployment yolov5
- Add an image interface to yolov5
- Run Yolov5 on Android
- Run Yolov5 on Android using Torchscript