yolov7-pose
yolov7-pose copied to clipboard
how to get yolov7-w6-pose-sim-yolo.onnx?
how to get yolov7-w6-pose-sim-yolo.onnx? we only have yolov7-w6-pose.onnx from yolov7-w6-pose.pt.
Do you try to use yolov7-w6-pose.onnx?
I did get wrong results.... hmmmm
Which code did you use to export the yolov7-w6-pose.pt to the onnx model?
Hello all @tuteming @NTS-SW , to those that are confused. I have managed to convert the yolov7-w6-pose.pt model (taken from YOLOv7's main branch README.md) to onnx.
-
Firstly, you clone this repo either in the directory where the original yolov7 repo is in your local folder or within the original yolov7 repo itself.
-
Next, you can follow the instructions to create the build/ dir in this repo and make the build file for YOLO tensorrt layer plugin.
-
Change a portion in the code within the original yolov7 main branch repo /models/yolo.py under
class IKeypoint(nn.Module)
's forward() module. Copy and replace the section of the code that corresponds to the changes stated in the README.md. -
create a new script in the original yolov7 folder
_export_pose_onnx.py_
with the code below. Change the paths to the weights downloaded and where to save the exported onnx model accordingly.
import sys
sys.path.append('./') # to run '$ python *.py' files in subdirectories
import torch
import torch.nn as nn
import models
from models.experimental import attempt_load
from utils.activations import Hardswish, SiLU
weights = 'yolov7-w6-pose.pt'
device = torch.device('cuda:0')
model = attempt_load(weights, map_location=device) # load FP32 model
for k, m in model.named_modules():
m._non_persistent_buffers_set = set() # pytorch 1.6.0 compatibility
if isinstance(m, models.common.Conv): # assign export-friendly activations
if isinstance(m.act, nn.Hardswish):
m.act = Hardswish()
elif isinstance(m.act, nn.SiLU):
m.act = SiLU()
model.model[-1].export = True # set Detect() layer grid export
model.eval()
img = torch.randn(1, 3, 960, 960).to(device) # image size(1,3,320,192) iDetection
torch.onnx.export(model, img, 'yolov7-w6-pose.onnx', verbose=False, opset_version=12, input_names=['images'])
-
run this
_export_pose_onnx.py_
script within the original yolov7 folder, to avoid python's relative import issues. -
Once done, you can use netron to check the exported onnx model and you can see that the outputs matches the first image-,you%20will%20get%3A,-use%20YoloLayer_TRT_v7.0/script)
-
Next, change the path (line 7 and line 43) to the onnx model and run the code at ./YoloLayer_TRT_v7.0/script/add_custom_yolo_op.py
-
And you are done, use netron to visualize the model weights and it should match image 2
Dear JJLimmm:
I have try very times, but I get a wrong 1.jpg.
and the final result is
yolov7-w6-pose.pt is changed?
Thanks.
Dear JJLimmm: I have try very times, but I get a wrong 1.jpg.
and the final result is
yolov7-w6-pose.pt is changed?
Thanks.
Have you solved the problem when you applied the trt model on inference? I tried many times and got a similar output like you. And I was confused that the output-number of author's onnx file was 859, but I got 875.
链接: https://pan.baidu.com/s/1XO7zDjCskQglegcXQ3lIoQ 提取码: j3ny
链接: https://pan.baidu.com/s/1XO7zDjCskQglegcXQ3lIoQ 提取码: j3ny
请问你推理结果正确吗
Thanks !@jia0511 Can you provide the .pt file and pt->onnx conversion script?