ultralytics / ultralytics

NEW - YOLOv8 🚀 in PyTorch > ONNX > OpenVINO > CoreML > TFLite
https://docs.ultralytics.com
GNU Affero General Public License v3.0
25.95k stars 5.17k forks source link

AttributeError: Can't get attribute 'v10DetectLoss' on <module 'ultralytics.utils.loss'> #14072

Open mrortach opened 1 week ago

mrortach commented 1 week ago

Search before asking

YOLOv8 Component

Predict

Bug

I encountered an AttributeError when trying to load my custom-trained YOLOv10x model. However, there is no issue when loading the pre-trained yolov10s.pt model.

Error Message

plaintext result = unpickler.load() (_env) PS D:\***> & C:/Users/**/anaconda3/envs/_env/python.exe d:////.py Traceback (most recent call last): File "d:****.py", line 4, in model = YOLO("yolov10x.pt") ^^^^^^^^^^^^^^^^^^^ File "C:\Users*/anaconda3/envs/**_env\Lib\site-packages\ultralytics\models\yolo\model.py", line 23, in init super().init(model=model, task=task, verbose=verbose) File "C:\Users\/anaconda3/envs/_env\Lib\site-packages\ultralytics\engine\model.py", line 149, in init self._load(model, task=task) File "C:\Users\/anaconda3/envs/_env\Lib\site-packages\ultralytics\engine\model.py", line 230, in _load self.model, self.ckpt = attempt_load_one_weight(weights) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "C:\Users\/anaconda3/envs/_env\Lib\site-packages\ultralytics\nn\tasks.py", line 855, in attempt_load_one_weight ckpt, weight = torch_safe_load(weight) # load ckpt ^^^^^^^^^^^^^^^^^^^^^^^ File "C:\Users\/anaconda3/envs*_env\Lib\site-packages\ultralytics\nn\tasks.py", line 781, in torch_safe_load ckpt = torch.load(file, map_location="cpu") ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "C:\Users*/AppData\Roaming\Python\Python312\site-packages\torch\serialization.py", line 1026, in load return _load(opened_zipfile, ^^^^^^^^^^^^^^^^^^^^^ File "C:\Users*/AppData\Roaming\Python\Python312\site-packages\torch\serialization.py", line 1438, in _load result = unpickler.load() ^^^^^^^^^^^^^^^^ File "C:\Users*/AppData\Roaming\Python\Python312\site-packages\torch\serialization.py", line 1431, in find_class return super().find_class(mod_name, name) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ AttributeError: Can't get attribute 'v10DetectLoss' on <module 'ultralytics.utils.loss' from 'C:\Users\/anaconda3/envs\_env\Lib\site-packages\ultralytics\utils\loss.py'>

Environment Information:

Python version: 3.12 Ultralytics version: 8.2.45 Operating System: Windows


from ultralytics import YOLO

# Load a pre-trained YOLOv10 model
model = YOLO("yolov10x.pt")

# Perform object detection on an image
results = model.track(0, save=True, show=True, conf=0.15)
glenn-jocher commented 1 week ago

@mrortach hello,

Thank you for reporting this issue and providing detailed information. The AttributeError you're encountering suggests that there might be a mismatch between the model's expected components and the current version of the Ultralytics package you're using.

To help us diagnose and resolve this issue, could you please provide a minimal reproducible example? This will allow us to replicate the problem on our end. You can find guidelines on how to create a minimal reproducible example here.

Additionally, please ensure that you are using the latest version of the Ultralytics package. You can update it using the following command:

pip install --upgrade ultralytics

If the issue persists after updating, it might be related to the custom-trained model's compatibility. In such cases, re-training the model with the latest version of the package might resolve the issue.

Here's a quick example to verify if the issue is specific to the custom model or a general problem:

from ultralytics import YOLO

# Load a pre-trained YOLOv10 model
model = YOLO("yolov10s.pt")

# Perform object detection on an image
results = model.track(0, save=True, show=True, conf=0.15)

If the pre-trained model works without issues, the problem might be isolated to the custom-trained model.

Feel free to share any additional details or updates. We're here to help!