Error deploying retrained YOLOv8 weights: ModuleNotFoundError for 'ultralytics.utils' #207
Closed
1 of 2 tasks
Labels
bug
Something isn't working
Search before asking
Notebook name
train_yolov8_object_detection_on_custom_dataset.ipynb
Bug
While trying to deploy retrained YOLOv8 weights to the Roboflow server using the version.deploy method in the notebook train_yolov8_object_detection_on_custom_dataset.ipynb, I encountered a ModuleNotFoundError for ultralytics.utils. Here is the specific cell and the traceback:
`---------------------------------------------------------------------------
ModuleNotFoundError Traceback (most recent call last)
/Users/alexandermittet/GD alexandermittet/uni_life/PIP/AoM/robo-notebooks/train_yolov8_object_detection_on_custom_dataset.ipynb Cell 51 line 2
1 version = project.version(1)
----> 2 version.deploy("yolov8", "/Users/alexandermittet/GD_alexandermittet/uni_life/PIP/AoM/runs/detect/train5")
File ~/miniconda3/envs/AoM/lib/python3.10/site-packages/roboflow/core/version.py:504, in Version.deploy(self, model_type, model_path)
499 except ImportError as e:
500 raise (
501 "The torch python package is required to deploy yolov5 models. Please install it with
pip install torch
"502 )
--> 504 model = torch.load(os.path.join(model_path, "weights/best.pt"))
506 if isinstance(model["model"].names, list):
507 class_names = model["model"].names
File ~/miniconda3/envs/AoM/lib/python3.10/site-packages/torch/serialization.py:809, in load(f, map_location, pickle_module, weights_only, **pickle_load_args)
807 except RuntimeError as e:
808 raise pickle.UnpicklingError(UNSAFE_MESSAGE + str(e)) from None
--> 809 return _load(opened_zipfile, map_location, pickle_module, **pickle_load_args)
810 if weights_only:
811 try:
File ~/miniconda3/envs/AoM/lib/python3.10/site-packages/torch/serialization.py:1172, in _load(zip_file, map_location, pickle_module, pickle_file, **pickle_load_args)
1170 unpickler = UnpicklerWrapper(data_file, **pickle_load_args)
1171 unpickler.persistent_load = persistent_load
...
1163 pass
1164 mod_name = load_module_mapping.get(mod_name, mod_name)
-> 1165 return super().find_class(mod_name, name)
ModuleNotFoundError: No module named 'ultralytics.utils'`
Environment
Python version: 3.10.12
OS: MacOS 15.5.1
ultralytics Version: 8.0.134
roboflow Version: 1.1.7
Minimal Reproducible Example
version = project.version(3) #3rd version of the dataset
version.deploy("yolov8", "path/to/train5") #5th training
Additional
This error seems to arise from the torch.load method when loading the model weights. It appears that the module ultralytics.utils is required but is not available in the environment. Is there a workaround or a fix for this issue?
I've tried updating the ultralytics library but that didn't work either.
Are you willing to submit a PR?
The text was updated successfully, but these errors were encountered: