yolov7-pose icon indicating copy to clipboard operation
yolov7-pose copied to clipboard

how to get yolov7-w6-pose-sim-yolo.onnx?

Open tuteming opened this issue 2 years ago • 8 comments

how to get yolov7-w6-pose-sim-yolo.onnx? we only have yolov7-w6-pose.onnx from yolov7-w6-pose.pt.

tuteming avatar Dec 08 '22 04:12 tuteming

Do you try to use yolov7-w6-pose.onnx?

I did get wrong results.... hmmmm

NTS-SW avatar Dec 15 '22 12:12 NTS-SW

Which code did you use to export the yolov7-w6-pose.pt to the onnx model?

JJLimmm avatar Jan 17 '23 08:01 JJLimmm

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.

  1. 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.

  2. Next, you can follow the instructions to create the build/ dir in this repo and make the build file for YOLO tensorrt layer plugin.

  3. 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.

  4. 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'])
  1. run this _export_pose_onnx.py_ script within the original yolov7 folder, to avoid python's relative import issues.

  2. 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)

  3. 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

  4. And you are done, use netron to visualize the model weights and it should match image 2

JJLimmm avatar Jan 17 '23 09:01 JJLimmm

Dear JJLimmm: I have try very times, but I get a wrong 1.jpg. image and the final result is image

yolov7-w6-pose.pt is changed?

Thanks.

tuteming avatar Apr 29 '23 04:04 tuteming

Dear JJLimmm: I have try very times, but I get a wrong 1.jpg. image and the final result is image

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.

daohaofunk avatar Nov 09 '23 09:11 daohaofunk

链接: https://pan.baidu.com/s/1XO7zDjCskQglegcXQ3lIoQ 提取码: j3ny

jia0511 avatar Mar 09 '24 00:03 jia0511

链接: https://pan.baidu.com/s/1XO7zDjCskQglegcXQ3lIoQ 提取码: j3ny

请问你推理结果正确吗

FunnyWii avatar Mar 27 '24 02:03 FunnyWii

Thanks !@jia0511 Can you provide the .pt file and pt->onnx conversion script?

the-cat-crying avatar Aug 22 '24 01:08 the-cat-crying