zhiqwang / yolort

yolort is a runtime stack for yolov5 on specialized accelerators such as tensorrt, libtorch, onnxruntime, tvm and ncnn.
https://zhiqwang.com/yolort
GNU General Public License v3.0
718 stars 153 forks source link

[docs] yolort and yolov5 version matching problem #377

Open zhiqwang opened 2 years ago

zhiqwang commented 2 years ago

I used following commad to export the ONNX models, and I use the 5.0 tag of ultralytics/yolov5 to train the model.pt. It raises an AttributeError: conv object has no attribute weight. How can I do for this error?

python tools/export_model.py --checkpoint_path model.pt --size_divisible 32

Originally posted by @Deronjey in https://github.com/zhiqwang/yolov5-rt-stack/issues/159#issuecomment-1091446449

zhiqwang commented 2 years ago

We support version 3.1, 4.0 and 6.0 released by ultralytics/yolov5. And actually the version 5.0 models released by yolov5 is same with 4.0, so we can just set upstream_version="r4.0" if we're using the 5.0. Similarly the model structure in tag 6.1 is same with 6.0, so we can set the upstream_version to "r6.0" if our model is trained with 6.1.

We have also added the function of matching versions to CLI tool export_model.py as well. We can add the argument --version r4.0 to this CLI tool.

python3 tools/export_model.py --checkpoint_path model.pt --size_divisible 32 --version r4.0

Maybe we should add this tips at the docs, and contributions are welcome here.

Deronjey commented 2 years ago

Hi @zhiqwang Firstly, i'm sincerely appreciate you to help me. and i have saved my onnx by yolov5-rt-stack,however,when i open the onnx by netron,i find there are some subgraph and some node like "if" 'where',it's unfriendly for me to deploy.so what can i do for this?

zhiqwang commented 2 years ago

Hi @Deronjey , Which platform do you want to deploy to currently?

Deronjey commented 2 years ago

baidu kunlun K100

zhiqwang commented 2 years ago

Hi @Deronjey , you can try the following scripts to export the ONNX models:

from yolort.relay.trt_graphsurgeon import YOLOTRTGraphSurgeon

checkpoint_path = "yolov5s.pt"
yolo_gs = YOLOTRTGraphSurgeon(checkpoint_path, enable_dynamic=False)
onnx_export_path = "yolov5s_wo_nms.onnx"

yolo_gs.save(onnx_export_path)

And seems that we should install onnx-graphsurgeon first:

python3 -m pip install onnx_graphsurgeon --index-url https://pypi.ngc.nvidia.com