Deploy custom model

I followed the steps in Launch: Deploy Custom Model Weights with Roboflow
to deploy my custom model.
I built this model with this notebook: https://colab.research.google.com/github/roboflow-ai/notebooks/blob/main/notebooks/train-yolov8-object-detection-on-custom-dataset.ipynb
I get out a best.pt file

I get this error message

loading Roboflow workspace...
loading Roboflow project...
Traceback (most recent call last):
  File "src/roboflow_deploy.py", line 15, in <module>
    project.version(1).deploy(model_type="yolov8", model_path=str(f"{REPO_DIR}/models/"))
  File ".venv/lib/python3.9/site-packages/roboflow/core/version.py", line 501, in deploy
    model = torch.load(os.path.join(model_path, "weights/best.pt"))
  File ".venv/lib/python3.9/site-packages/torch/serialization.py", line 712, in load
    return _load(opened_zipfile, map_location, pickle_module, **pickle_load_args)
  File ".venv/lib/python3.9/site-packages/torch/serialization.py", line 1049, in _load
    result = unpickler.load()
  File ".venv/lib/python3.9/site-packages/torch/serialization.py", line 1042, in find_class
    return super().find_class(mod_name, name)
ModuleNotFoundError: No module named 'ultralytics.yolo'

Describe your question/issue here! (delete this when you post)

  • Project Type: detection
  • Operating System & Browser: MacOS chrome
  • Project Universe Link or Workspace/Project ID:

The error message you’re encountering seems to be related to the PyTorch library not being able to find the ‘ultralytics.yolo’ 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:

  1. 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).

  2. 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.

  3. Use the following code to upload your weights:

from roboflow import Roboflow

rf = Roboflow(api_key="API_KEY")
project = rf.workspace().project("PROJECT_ID")
project.version(DATASET_VERSION).deploy(model_type="yolov8", model_path="./runs/detect/train/")

If you’re still encountering issues, it might be due to the version of Ultralytics you’re using. You might need to install or update the Ultralytics library in your environment. You can do this using pip:

pip install -U ultralytics

If the problem persists, it would be best to reach out to the Roboflow support team or the Ultralytics community 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, and forum. If this solves your issue, please mark it as the solution using the checkbox icon. 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.

I am using these versions:
roboflow==1.1.16
ultralytics==8.0.196

My deployment command is:
project.version(1).deploy(model_type="yolov8", model_path=str(f"{REPO_DIR}/models/"))

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.