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 export to onnx? #2

Closed
xinsuinizhuan opened this issue Feb 22, 2024 · 16 comments · May be fixed by #20
Closed

how to export to onnx? #2

xinsuinizhuan opened this issue Feb 22, 2024 · 16 comments · May be fixed by #20

Comments

@xinsuinizhuan
Copy link

python export.py --weights yolov9-c.pt --include onnx

export: data=G:\Item_done\yolo\yolo5\yolov9\yolov9-main\data\coco.yaml, weights=['yolov9-c.pt'], imgsz=[640, 640], batch_size=1, device=cpu, half=False, inplace=False, keras=False, optimize=False, int8=False, dynamic=False, simplify=False, opset=12, verbose=False, workspace=4, nms=False, agnostic_nms=False, topk_per_class=100, topk_all=100, iou_thres=0.45, conf_thres=0.25, include=['onnx']
YOLOv5 2024-2-22 Python-3.9.16 torch-2.0.1+cu118 CPU

Fusing layers...
Model summary: 724 layers, 51141120 parameters, 0 gradients, 238.7 GFLOPs
Traceback (most recent call last):
File "G:\Item_done\yolo\yolo5\yolov9\yolov9-main\export.py", line 606, in
main(opt)
File "G:\Item_done\yolo\yolo5\yolov9\yolov9-main\export.py", line 601, in main
run(**vars(opt))
File "C:\Users\lllstandout.conda\envs\yolov8\lib\site-packages\torch\utils_contextlib.py", line 115, in decorate_context
return func(*args, **kwargs)
File "G:\Item_done\yolo\yolo5\yolov9\yolov9-main\export.py", line 497, in run
if isinstance(m, (Detect, V6Detect)):
NameError: name 'V6Detect' is not defined

@WongKinYiu
Copy link
Owner

WongKinYiu commented Feb 22, 2024

Export functions are not yet supported. The models should do re-parameterization first, then do export.

@xinsuinizhuan
Copy link
Author

how to re-parameterization?

@xinsuinizhuan
Copy link
Author

how to tensorrt forward? I need to export to onnx,then tensorrt.

@WongKinYiu
Copy link
Owner

The re-parameterization functions are provided in yolov7 repo, but currently we have not integrated them into this repo.

@xinsuinizhuan
Copy link
Author

need to export onnx model,please integrated them into this repo quickly!

@BaofengZan
Copy link

need to export onnx model,please integrated them into this repo quickly!

Modify this code "if isinstance(m, (Detect, V6Detect))" to "if isinstance(m, (Detect, DualDDetect))" ,and you can get the onnx

@jdiaz97
Copy link

jdiaz97 commented Feb 22, 2024

need to export onnx model,please integrated them into this repo quickly!

Modify this code "if isinstance(m, (Detect, V6Detect))" to "if isinstance(m, (Detect, DualDDetect))" ,and you can get the onnx

I don't think that really works

@xenova
Copy link

xenova commented Feb 22, 2024

#20 should fix this 👍 (+ converted models can be found here)

@BaofengZan
Copy link

need to export onnx model,please integrated them into this repo quickly!

Modify this code "if isinstance(m, (Detect, V6Detect))" to "if isinstance(m, (Detect, DualDDetect))" ,and you can get the onnx

I don't think that really works

This solution works for me.I have completed the ONNX export, as well as inference with TRT and ONNX Runtime (ORT).Furthermore, the ONNX used by TRT includes an NMS node.

@spacewalk01
Copy link

@xenova's solution works

@jdiaz97
Copy link

jdiaz97 commented Feb 23, 2024

I can confirm that @xenova exports work

@tsqt2023
Copy link

(修改代码 “if isinstance(m, (Detect, V6Detect))” 改为 “if isinstance(m, (Detect, DualDDetect))” ,就可以得到 onnx)在进行如下修改后又得到一个新问题

Fusing layers...
Model summary: 724 layers, 51141120 parameters, 0 gradients, 238.7 GFLOPs
Traceback (most recent call last):
File "export.py", line 607, in
main(opt)
File "export.py", line 602, in main
run(**vars(opt))
File "/home/mouxing/anaconda3/envs/V8/lib/python3.8/site-packages/torch/autograd/grad_mode.py", line 27, in decorate_context
return func(*args, **kwargs)
File "export.py", line 507, in run
shape = tuple((y[0] if isinstance(y, tuple) else y).shape) # model output shape
AttributeError: 'list' object has no attribute 'shape'

@AICVer
Copy link

AICVer commented Feb 26, 2024

You can found how to export onnx model with the following
https://github.com/AICVer/yolov9.infer

@Egorundel
Copy link

@xinsuinizhuan I used it:
https://github.com/thaitc-hust/yolov9-tensorrt

I also first transfer weights.pt to ONNX with the NMS module, and then transfer to TensorRT Engine for inference.

@gpsamt
Copy link

gpsamt commented Mar 20, 2024

Hello!!
Fix the error shape = tuple((y[0] if isinstance(y, tuple) else y).shape) # model output shape
AttributeError: 'list' object has no attribute 'shape' "
Passing y directly to shape=y

y is a tuple but y[0] is a list. And this list has no .shape.

My export looked like this:

!python export.py --weights /content/drive/MyDrive/IAGeneration/Yolov9/yolov9/runs/train/exp3/weights/best.pt
--batch-size 1 --imgsz 640 --include torchscript onnx

My best.pt has 133.47 M
While my best.onnx has 262.22 M.
Is this normal?

The inference worked with:

!python detect.py --data /Yolov9/projdocyolov9red.yaml --weight best.onnx --conf 0.50 --source /data/imgs --device 0 --save-txt

But it took about 3 minutes to detect 100 images. This is normal?

@Varun3713-creator
Copy link

need to export onnx model,please integrated them into this repo quickly!

Modify this code "if isinstance(m, (Detect, V6Detect))" to "if isinstance(m, (Detect, DualDDetect))" ,and you can get the onnx
hai
I tried this but i am getting- NameError: name 'DualDDetect' is not defined
am I missing something?

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

Successfully merging a pull request may close this issue.