YOLOv5 converts onnx format files and visualizes them with netron

YOLOv5 converts onnx format files and visualizes them with netron

git clone YOLOv5

First of all, we need to enter the github official website, find the source code of yolov5, here is the link YOLOv5 click on the link to enter the YOLO series code library written by Glenn (it is a bit slow to use the intranet, it may need to refresh several times to Come out, wait patiently), if it goes well, we can see:
insert image description here

This blog is about the visualization of the network structure of YOLOv5, so we can select the version in the upper left corner. The default link here is the selected v5.0. If you want to play other versions, you can also click on v5.0 above Glenn's avatar to select a version. After clicking, you will see the picture below. Select Tags to view various versions. Here we take version 5.0 as an example.
insert image description here
Then we click on the green frame code on the right:
insert image description here
copy the https link that pops up below, and then under the local path where we want to place this project, right click and select git bash here (you need to download a git tool here, you can directly open it in the browser Search for git in the website, and you can download it after entering the official website). Enter the git terminal after clicking:
insert image description here
enter in the command line:

git clone https://github.com/ultralytics/yolov5.git

Then you can get this YOLOv5 project locally for free.
Since I am used to using pycharm to develop, open YOLOv5 as a project with pycharm at this time, click the Terminal column below, enter the terminal command line of the project: enter
insert image description here
:

pip install -r requirements.txt

You can download various packages that the project depends on. Of course, this is not complete, and some packages will report errors when they are running. At this time, we can manually pip install it, and it will not consume a lot of time.
Here we have completed the first step and deployed the YOLOv5 project on our computer.

Convert to onnx file format.

After entering this step, the first thing we need to know is that for the netron tool, in order to visualize our network architecture, we need to obtain a file in onnx format, and this file can be converted from our pt file, that is, we weights file. Here we can first enter the export.py file under the model file in the project. After running, we will get a pre-trained weight file like yolov5s.pt (of course this is just an example, for the weight file we trained ourselves same operation). Here, after we download the pre-training weight file, generally speaking, the code will report an error. Here we ignore it and get the pt file. Then we are in our pycharm terminal, or in the git tool. I open the git tool here to convert the onnx format.
insert image description here
After opening the git tool, we can first check whether our YOLOv5 project is contained in the directory of the current folder:

insert image description here
It can be clearly seen that I have included the project file here, and then we cd to the project:
insert image description here
at this point, we are already in the project directory. At this time, we enter in the command line of the git tool:

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

Then press Enter to run:
insert image description here
You can see that in the third-to-last line of log information, onnx export success, saved as yolov5s.onnx appears. At this point we can open our local folder, and we can find that the onnx file has been successfully obtained.
insert image description here

Use the netron tool to visualize

Then on to our final step, visualization.
Search directly on the browser (or you can also enter github and download the netron tool. The specific download method is explained online, so I wo n’t go into details here). device, enter netron, and the official website of netron will appear on the home page:
insert image description here
After clicking to enter, you will see this page:
insert image description here
If we want to download, we can click github on the right to directly enter its source code library for downloading. Or we can convert online, click open model on the left:
insert image description here
select our onnx format file, and then open it. After a while of netron rotation, we got our network structure visualization diagram:
insert image description here
here, the tutorial of using netron to visualize the network structure is over. netron is a very powerful algorithm development tool, which is of great help to us in understanding the network structure of an algorithm and its later improvement and development. It can let us enjoy the alchemy process more intuitively, hahaha.

Guess you like

Origin blog.csdn.net/ycx_ccc/article/details/127798201