You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
import onnx
import torch
from onnx2torch import convert
from onnx import version_converter
# Load the ONNX model.
model = onnx.load("yolov5n.onnx")
# Convert the model to the target version.
target_version = 14
converted_model = version_converter.convert_version(model, target_version)
torch_model_1 = convert(converted_model)
torch_model_1.eval()
torch.save(torch_model_1, 'model.pt')
For yolov5n.onnx it will raise error: NotImplementedError: Converter is not implemented (OperationDescription(domain='', operation_type='ArgMax', version=13))
For yolov8n.onnx the converted model goes wrong:
WARNING ⚠️ The file 'model.pt' appears to be improperly saved or formatted. For optimal results, use model.save('filename.pt') to correctly save YOLO models.
Traceback (most recent call last):
File "D:\test\loader.py", line 3, in <module>
model = YOLO("model.pt")
File "D:\Python310\lib\site-packages\ultralytics\models\yolo\model.py", line 23, in __init__
super().__init__(model=model, task=task, verbose=verbose)
File "D:\Python310\lib\site-packages\ultralytics\engine\model.py", line 151, in __init__
self._load(model, task=task)
File "D:\Python310\lib\site-packages\ultralytics\engine\model.py", line 240, in _load
self.model, self.ckpt = attempt_load_one_weight(weights)
File "D:\Python310\lib\site-packages\ultralytics\nn\tasks.py", line 806, in attempt_load_one_weight
ckpt, weight = torch_safe_load(weight) # load ckpt
File "D:\Python310\lib\site-packages\ultralytics\nn\tasks.py", line 760, in torch_safe_load
ckpt = {"model": ckpt.model}
File "D:\Python310\lib\site-packages\torch\nn\modules\module.py", line 1688, in __getattr__
raise AttributeError(f"'{type(self).__name__}' object has no attribute '{name}'")
AttributeError: 'GraphModule' object has no attribute 'model'. Did you mean: 'code'?
While using code:
from ultralytics import YOLO
model = YOLO("model.pt")
model.export(format="onnx", imgsz=[416,416])
The text was updated successfully, but these errors were encountered:
For yolov5n.onnx it will raise error:
NotImplementedError: Converter is not implemented (OperationDescription(domain='', operation_type='ArgMax', version=13))
For yolov8n.onnx the converted model goes wrong:
While using code:
The text was updated successfully, but these errors were encountered: