Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
tuteming opened this issue Dec 8, 2022 · 7 comments
Open

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

tuteming opened this issue Dec 8, 2022 · 7 comments

Comments

@tuteming
Copy link

tuteming commented Dec 8, 2022

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

@NTS-SW
Copy link

NTS-SW commented Dec 15, 2022

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

I did get wrong results.... hmmmm

@JJLimmm
Copy link

JJLimmm commented Jan 17, 2023

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

@JJLimmm
Copy link

JJLimmm commented Jan 17, 2023

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

@tuteming
Copy link
Author

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.

@daohaofunk
Copy link

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.

@jia0511
Copy link

jia0511 commented Mar 9, 2024

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

@FunnyWii
Copy link

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

请问你推理结果正确吗

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants