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

YOLOv5u models not compatible with the YOLOv5 Repository #374

Closed
1 task done
omumbare7 opened this issue Sep 1, 2023 · 3 comments
Closed
1 task done

YOLOv5u models not compatible with the YOLOv5 Repository #374

omumbare7 opened this issue Sep 1, 2023 · 3 comments
Assignees
Labels
question Further information is requested

Comments

@omumbare7
Copy link

omumbare7 commented Sep 1, 2023

Search before asking

Question

the .pt file i trained via ultralytics hub on yolov5lu, does not work on yolov5 i downloaded from ultralytics github. i have loaded the model via torch hub (yes forced reload is true) but other pt which i trained via roboflow jupyter notebook works on the yolov5 i downloaded from git. Am i missing something
the error is Exception: 'Detect' object has no attribute 'grid'. Cache may be out of date, try force_reload=True
something with hubconf file on yolov5 master folder,
all other pt files work which i have trained using roboflow notebook on colab

Additional

YOLOv5 2023-2-21 Python-3.10.0 torch-1.13.1+cu116 CUDA:0 (NVIDIA GeForce RTX 2060, 6144MiB)

YOLOv5l summary (fused): 303 layers, 53132179 parameters, 0 gradients
Adding AutoShape...
Traceback (most recent call last):
File "C:\Users\om\Desktop\ugv proto\codes./yolov5-master\hubconf.py", line 73, in _create
return model.to(device)
File "C:\Users\om\AppData\Local\Programs\Python\Python310\lib\site-packages\torch\nn\modules\module.py", line 989, in to
return self._apply(convert)
File "C:\Users\om\Desktop\ugv proto\codes./yolov5-master\models\common.py", line 652, in _apply
m.grid = list(map(fn, m.grid))
File "C:\Users\om\AppData\Local\Programs\Python\Python310\lib\site-packages\torch\nn\modules\module.py", line 1269, in getattr
raise AttributeError("'{}' object has no attribute '{}'".format(
AttributeError: 'Detect' object has no attribute 'grid'

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
File "c:\Users\om\Desktop\ugv proto\codes\track.py", line 15, in
model = torch.hub.load('./yolov5-master', 'custom', source ='local', path=a, force_reload=True)
File "C:\Users\om\AppData\Local\Programs\Python\Python310\lib\site-packages\torch\hub.py", line 542, in load
model = _load_local(repo_or_dir, model, *args, **kwargs)
File "C:\Users\om\AppData\Local\Programs\Python\Python310\lib\site-packages\torch\hub.py", line 572, in _load_local
model = entry(*args, **kwargs)
File "C:\Users\om\Desktop\ugv proto\codes./yolov5-master\hubconf.py", line 83, in custom
return _create(path, autoshape=autoshape, verbose=_verbose, device=device)
File "C:\Users\om\Desktop\ugv proto\codes./yolov5-master\hubconf.py", line 78, in _create
raise Exception(s) from e
Exception: 'Detect' object has no attribute 'grid'. Cache may be out of date, try force_reload=True or see ultralytics/yolov5#36 for help.

@omumbare7 omumbare7 added the question Further information is requested label Sep 1, 2023
@kalenmike
Copy link
Contributor

kalenmike commented Sep 1, 2023

@omumbare7 Thanks for asking the question. The YOLOv5lu and YOLOv5l models are not the same, there have been some tweaks that make them incompatible. All the v5u models can only be run with the ultralytics package, and they will not run with YOLOv5. And the same can be said for models trained with YOLOv5 and not ultralytics. They will work with YOLOv5 but not with ultralytics.

You will need to run inference with the ultralytics package if you have trained a v5u model in HUB.

from ultralytics import YOLO

# Load a model
model = YOLO('path/to/best.pt')  # load a custom model

# Predict with the model
results = model('https://ultralytics.com/images/bus.jpg', save=True)  # predict on an image

@kalenmike kalenmike self-assigned this Sep 1, 2023
@kalenmike kalenmike changed the title yolov5 model trained via ultralytics hub does not run YOLOv5u models not compatible with the YOLOv5 Repository Sep 1, 2023
@omumbare7
Copy link
Author

thank you @kalenmike i will try this

@UltralyticsAssistant
Copy link
Member

You're welcome @omumbare7! Please do give it a try and let us know if you encounter any other issues or have further questions. We're here to help! Remember, the key point is to use the Ultralytics package for inference if you've trained a v5u model on the HUB. Thank you for being a part of the YOLO and Ultralytics community.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

3 participants