yolov5 deployment 1 – pytorch-onnx

Hits: 0

[yolov5] deployment 1 – pytorch->onnx

Goal: pytorch->onnx->ncnn->android [one] ,
environment deployment
code from: https://github.com/ultralytics/yolov5 After training the yolov5 model, open the terminal in the yolov5 main directory and enter:[]

pip3 install onnx>=1.7.0  # for ONNX export
pip3 install coremltools==4.0  # for CoreML export

Two, pytorch->onnx conversion
1. Input command

python models/export.py --weights yolov5s.pt --img 640 --batch 1  # export at 640x640 with batch size 1

The problem is shown in the figure
. Reason: the export.py file is too deep, just call it out.
Modify the instruction:

python3 export.py --weights weights/yolov5s.pt --img 640 --batch 1

The result is shown in the figure:
3. View the file
Generate three files: yolov5s.mlmodel , yolov5s.onnx , yolov5s.torchscript.pt
4. Netron view the network structure
1. Install netron

pip3 install netron

  1. Use netron to view the picture
    Open the terminal in the folder with the .onnx file

import netron

As shown in the figure:

The browser will open, as shown in the figure:
Display the network structure
5, simplify the onnx file
1. Install the simplifier

pip3 install onnx-simplify

  1. Execute the command

python3 -m onnxsim  onnx_inputpath onnx_outputpath

After simplification, the operation of onnx->ncnn can be performed

You may also like...

Leave a Reply

Your email address will not be published.