I am trying to upload my YOLOV8 weights to roboflow.
I keep getting this error.
Here is a bit more of the error
loading Roboflow workspace…
loading Roboflow project…
Traceback (most recent call last):
File “/Users/boazburnett/PycharmProjects/Roboflow Testing/main.py”, line 6, in
project.version(3).deploy(model_type=“yolov8”, model_path=“/Users/boazburnett/PycharmProjects/Roboflow Testing/runs/classify/train”)
File “/Users/boazburnett/PycharmProjects/Roboflow Testing/venv/lib/python3.9/site-packages/roboflow/core/version.py”, line 478, in deploy
model = torch.load(os.path.join(model_path, “weights/best.pt”))
File “/Users/boazburnett/PycharmProjects/Roboflow Testing/venv/lib/python3.9/site-packages/torch/serialization.py”, line 809, in load
return _load(opened_zipfile, map_location, pickle_module, **pickle_load_args)
File “/Users/boazburnett/PycharmProjects/Roboflow Testing/venv/lib/python3.9/site-packages/torch/serialization.py”, line 1172, in _load
result = unpickler.load()
File “/Users/boazburnett/PycharmProjects/Roboflow Testing/venv/lib/python3.9/site-packages/torch/serialization.py”, line 1165, in find_class
return super().find_class(mod_name, name)
ModuleNotFoundError: No module named ‘ultralytics.data’
And my code
from roboflow import Roboflow
rf = Roboflow(api_key=“secret”)
project = rf.workspace(“boaztheostrich”).project(“cartest-tyaur”)
The error you’re encountering seems to be related to the PyTorch library not being able to find the ‘ultralytics.data’ module. This issue is not directly related to Roboflow but rather to the dependencies of your YOLOv8 model.
However, to upload your YOLOv8 weights to Roboflow, you can follow these steps:
Ensure that you have the correct version of the Roboflow Python package. You need the roboflow>=1.0.1 Python package version to use the .deploy() command (source).
Make sure your weights are in the correct directory. According to the Roboflow blog, the weights should be in the “/runs/detect/train/weights/best.pt” folder of your project.
Replace “API_KEY”, “PROJECT_ID”, and “DATASET_VERSION” with your actual API key, project ID, and dataset version respectively.
If you continue to encounter issues, it might be helpful to check the Roboflow documentation or reach out to their support for further assistance.
Hi! I’m Roboflow’s AI powered bot. This is an automated response powered using AI with knowledge from our docs, blog, knowledge base, and previous forum responses. If you find this to be a helpful answer, please mark it as the solution using the checkbox icon below. If this doesn’t solve your issue, please follow up with what you’ve tried/why, and the community will continue to chime in as usual.
Hi @Boaztheostrich ! I’ve seen this error when the version of ultralytics I’m using with the roboflow python package doesn’t match the version of ultralytics I used to train my model.
Hi @Paul thanks for the response! I think that was the solution however I am now getting an error code talking about nc?
It relates to this code within version.py
if "yolov8" in model_type:
# try except for backwards compatibility with older versions of ultralytics
if "-cls" in model_type:
nc = model["model"].yaml["nc"]
args = model["train_args"]
else:
nc = model["model"].nc
args = model["model"].args
try:
model_artifacts = {
"names": class_names,
"yaml": model["model"].yaml,
"nc": nc,
"args": {
k: val
for k, val in args.items()
if ((k == "model") or (k == "imgsz") or (k == "batch"))
},
"ultralytics_version": ultralytics.__version__,
"model_type": model_type,
}
When I changed the model name to “yolov8-cls” it did successfully upload however all of my predictions were at 0% MAP etc.