A very confusing issues about converting .pt to .onnx #11887
Unanswered
Greatlover
asked this question in
Q&A
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Bug
Hi, I'm getting the following error when trying to convert a Pytorch YoloV5 model to ONNX format:
Traceback (most recent call last):
File "E:\yolov5-master\py_to_onnx.py", line 17, in
torch.onnx.export(
File "E:\anaconda\envs\yolo_v5\lib\site-packages\torch\onnx\utils.py", line 504, in export
_export(
File "E:\anaconda\envs\yolo_v5\lib\site-packages\torch\onnx\utils.py", line 1506, in _export
with exporter_context(model, training, verbose):
File "E:\anaconda\envs\yolo_v5\lib\contextlib.py", line 117, in enter
return next(self.gen)
File "E:\anaconda\envs\yolo_v5\lib\site-packages\torch\onnx\utils.py", line 176, in exporter_context
with select_model_mode_for_export(
File "E:\anaconda\envs\yolo_v5\lib\contextlib.py", line 117, in enter
return next(self.gen)
File "E:\anaconda\envs\yolo_v5\lib\site-packages\torch\onnx\utils.py", line 137, in disable_apex_o2_state_dict_hook
for module in model.modules():
AttributeError: 'dict' object has no attribute 'modules'
No matter how I modify the code, using the official YoloV5 models or my own trained models, I get this error when converting to ONNX. Is there any way to resolve this? Any help would be greatly appreciated!
Environment
Python 3.9.0
pytroch 1.13.0+cu116
cuda 11.6
yolov5
Minimal Reproducible Example
Here is the .py code
import torch
import torch.nn
model_file = 'E:\yolov5-master\runs\train\exp9\weights\best.pt'
export_file = 'E:\yolov5-master\export_all\onnxs\try\train\fuck.onnx'
model = torch.load(model_file)
dummy_input = torch.randn(1, 2, 640, 640)
torch.onnx.export(
model,
dummy_input,
export_file,
opset_version=11
)
Additional
Here is the .py code
import torch
import torch.nn
model_file = 'E:\yolov5-master\runs\train\exp9\weights\best.pt'
export_file = 'E:\yolov5-master\export_all\onnxs\try\train\fuck.onnx'
model = torch.load(model_file)
dummy_input = torch.randn(1, 2, 640, 640)
torch.onnx.export(
model,
dummy_input,
export_file,
opset_version=11
)
Beta Was this translation helpful? Give feedback.
All reactions