Closed Faris-Faiz closed 4 days ago
π Hello @Faris-Faiz, thank you for your interest in Ultralytics π! We recommend reviewing our Docs for guidance, including Python and CLI usage examples, where many common issues like this one are answered.
If this is a π Bug Report, kindly provide a minimum reproducible example that demonstrates the issue. For example, confirm which specific OS, Python environment, hardware, and training/usage configurations are being used (e.g., JupyterLab environment vs Kaggle), as this helps isolate the cause.
If this relates to a custom training or configuration β Question, please share additional details:
First, verify you've upgraded to the latest version of the ultralytics
package in a Python>=3.8 environment with PyTorch>=1.8. Run the following command to ensure you're on the latest version:
pip install -U ultralytics
It is recommended to test your setup in different environments to isolate the problem:
To ensure your issue is not related to the computational environment, you can try running YOLO in any of the following verified environments:
Join the Ultralytics community for more real-time or in-depth support:
For our latest software health status, check our Ultralytics CI tests: . If this badge is green, our tests verify correct operation across supported Modes and Tasks in macOS, Windows, and Ubuntu.
This is an automated response to ensure your issue receives prompt attention. An Ultralytics engineer will review and assist you further soon. Thank you for your patience! π
If you're using a notebook or Colab/Kaggle, you need to restart kernel after update.
If you're using a notebook or Colab/Kaggle, you need to restart kernel after update.
Yep this works. Thanks for taking your time to answering this question!
@Faris-Faiz you're welcome! Credit goes to the YOLO community and Ultralytics team for making it all possible. Happy experimenting!
Search before asking
Question
Question
I have found a similar discussion here, but it seems they fixed it by updating the ultralytics package. However, even after updating my ultralytics package (version 8.3.39), I still am not able to execute the code below:
model = YOLO('yolo11x.pt')
I was using a remote JupyterLab session on my university computer, but it's not working. Moving on to Kaggle, it works despite being on the same version.
Full Error Output
`--------------------------------------------------------------------------- AttributeError Traceback (most recent call last) Cell In[34], line 5 1 from ultralytics import YOLO 3 # Load a pre-trained YOLO model (YOLO11x preferred, YOLOv8n as fallback) 4 # If you have a pre-trained YOLO11x model, replace 'yolov8n.pt' with 'yolo11x.pt' ----> 5 model = YOLO('yolo11x.pt')
File ~/.local/lib/python3.10/site-packages/ultralytics/models/yolo/model.py:23, in YOLO.init(self, model, task, verbose) 20 self.dict = new_instance.dict 21 else: 22 # Continue with default YOLO initialization ---> 23 super().init(model=model, task=task, verbose=verbose)
File ~/.local/lib/python3.10/site-packages/ultralytics/engine/model.py:142, in Model.init(self, model, task, verbose) 140 self._new(model, task=task, verbose=verbose) 141 else: --> 142 self._load(model, task=task)
File ~/.local/lib/python3.10/site-packages/ultralytics/engine/model.py:294, in Model._load(self, weights, task) 291 weights = checks.check_model_file_from_stem(weights) # add suffix, i.e. yolov8n -> yolov8n.pt 293 if Path(weights).suffix == ".pt": --> 294 self.model, self.ckpt = attempt_load_one_weight(weights) 295 self.task = self.model.args["task"] 296 self.overrides = self.model.args = self._reset_ckpt_args(self.model.args)
File ~/.local/lib/python3.10/site-packages/ultralytics/nn/tasks.py:855, in attempt_load_one_weight(weight, device, inplace, fuse) 853 def attempt_load_one_weight(weight, device=None, inplace=True, fuse=False): 854 """Loads a single model weights.""" --> 855 ckpt, weight = torch_safe_load(weight) # load ckpt 856 args = {DEFAULT_CFG_DICT, (ckpt.get("train_args", {}))} # combine model and default args, preferring model args 857 model = (ckpt.get("ema") or ckpt["model"]).to(device).float() # FP32 model
File ~/.local/lib/python3.10/site-packages/ultralytics/nn/tasks.py:781, in torch_safe_load(weight) 769 try: 770 with temporary_modules( 771 modules={ 772 "ultralytics.yolo.utils": "ultralytics.utils", (...) 779 }, 780 ): --> 781 ckpt = torch.load(file, map_location="cpu") 783 except ModuleNotFoundError as e: # e.name is missing module name 784 if e.name == "models":
File ~/.local/lib/python3.10/site-packages/ultralytics/utils/patches.py:86, in torch_load(*args, *kwargs) 83 if TORCH_1_13 and "weights_only" not in kwargs: 84 kwargs["weights_only"] = False ---> 86 return _torch_load(args, **kwargs)
File ~/.local/lib/python3.10/site-packages/torch/serialization.py:1360, in load(f, map_location, pickle_module, weights_only, mmap, pickle_load_args) 1358 except pickle.UnpicklingError as e: 1359 raise pickle.UnpicklingError(_get_wo_message(str(e))) from None -> 1360 return _load( 1361 opened_zipfile, 1362 map_location, 1363 pickle_module, 1364 overall_storage=overall_storage, 1365 pickle_load_args, 1366 ) 1367 if mmap: 1368 f_name = "" if not isinstance(f, str) else f"{f}, "
File ~/.local/lib/python3.10/site-packages/torch/serialization.py:1848, in _load(zip_file, map_location, pickle_module, pickle_file, overall_storage, **pickle_load_args) 1846 global _serialization_tls 1847 _serialization_tls.map_location = map_location -> 1848 result = unpickler.load() 1849 _serialization_tls.map_location = None 1851 torch._utils._validate_loaded_sparse_tensors()
File ~/.local/lib/python3.10/site-packages/torch/serialization.py:1837, in _load..UnpicklerWrapper.find_class(self, mod_name, name)
1835 pass
1836 mod_name = load_module_mapping.get(mod_name, mod_name)
-> 1837 return super().find_class(mod_name, name)
AttributeError: Can't get attribute 'C3k2' on <module 'ultralytics.nn.modules.block' from '/home/user/farisfaiz/.local/lib/python3.10/site-packages/ultralytics/nn/modules/block.py'>`
Additional
No response