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

Not working with yolov5 6.2 and yolov8 #214

Open
AI-M-BOT opened this issue Apr 18, 2024 · 0 comments
Open

Not working with yolov5 6.2 and yolov8 #214

AI-M-BOT opened this issue Apr 18, 2024 · 0 comments

Comments

@AI-M-BOT
Copy link

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])
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

1 participant