Links

Upload Weights

Roboflow offers the ability to upload model weights for your custom-trained models to your Roboflow projects for model deployment.

Overview

Once you've completed training your custom model, upload your model weights back to your Roboflow project to take advantage of Roboflow Inference.
Model weights uploads are currently available for YOLOv5 (n, s, m, l, x) and YOLOv8 (n, s, m, l, x) Object Detection models.
How to Train YOLOv5 On a Custom Dataset
Roboflow Blog
YOLOv5 Object Detection Model Training Guide

YOLOv5 and YOLOv8

After successfully training your custom YOLOv5 or YOLOv8 model, use the .deploy() function to upload your model weights back to your Roboflow Object Detection project.
Model weights uploads are only available for dataset versions without a trained model (i.e not yet trained with Roboflow Train, and no YOLOv5 or YOLOv8 model weights uploaded).
Dataset version Export UI for Roboflow dataset versions without a trained model
Dataset version Export UI for versions without a trained model
Launch: Deploy YOLOv8 with Roboflow
Roboflow Blog
Deploy YOLOv8 Models with Roboflow

Accepted Model Weights

  1. 1.
    Model weights trained with YOLOv5n or YOLOv8n
  2. 2.
    Model weights trained with YOLOv5s or YOLOv8v8s
  3. 3.
    Model weights trained with YOLOv5m or YOLOv8vm
  4. 4.
    Model weights trained with YOLOv5l or YOLOv8vl
  5. 5.
    Model weights trained with YOLOv5x or YOLOv8vx
NOTE: Larger model sizes provide better training results. However, the larger the model size, the slower the training time, and inference (model prediction) speed. Consider whether you're looking for real-time inference on fast-moving objects or video feeds (better to use a smaller model), or you are processing data after it is collected, and more concerned with higher prediction accuracy (choose a larger model).

Code Snippet for Model Weights Upload

The dataset export code you receive after selecting the "Export" button on your dataset/project's Version page will look like this:
Roboflow Python package - YOLOv5 Dataset Export Code Snippet
Roboflow Python package - YOLOv5 Dataset Export Code Snippet
The dataset export code you receive from the "Get Snippet" button for YOLOv8 will look like this:
Roboflow Python package - YOLOv8 Dataset Export Code Snippet
Roboflow Python package - YOLOv8 Dataset Export Code Snippet
You will need to set the version variable to use the .deploy() function:
In this case, since v27 (version 27) was exported, the variable assignment will look like this:
# setting the version variable
version = project.version(27)
version.deploy(model_type, model_path)
  1. 1.
    The model architecture for the model weights you are uploading to Roboflow (i.e model_type = "yolov5" or model_type = "yolov8")
  2. 2.
    The path to your model weights (i.e model_path = runs/train/yolov5s_results/ for YOLOv5s or model_path = runs/detect/train/ for YOLOv8). NOTE: weights/best.pt is appended to the model_path provided.
As a reminder, this will only work for dataset versions that do not yet have a trained model.
In the example below, weights upload is performed for v27 (version 27) of this Construction Site Safety dataset: https://universe.roboflow.com/roboflow-universe-projects/construction-site-safety/.
Once your weights are uploaded, you will be able to utilize Roboflow features for model deployment. You won't be able to export model weights at this time.

Upload YOLOv5 Model Weights

# upload model weights for YOLOv5 Object Detection deployment
# set the version number to the version you export
# ensure version number does not yet have a trained model
version = project.version(27)
version.deploy("yolov5", "runs/train/yolov5s_results/") #auto-appends weights/best.pt to model_path
Note: If you are training YOLOv5s then the path to your weights will be "runs/train/yolov5s_results/", (e.g, version.deploy("yolov5", "runs/train/yolov5s_results/"))
  • YOLOv5n: "runs/train/yolov5n_results/"
  • YOLOv5m: "runs/train/yolov5m_results/"
  • YOLOv5l: "runs/train/yolov5l_results/"
  • YOLOv5x: "runs/train/yolov5x_results/"

Upload YOLOv8 Model Weights

# upload model weights for YOLOv8 Object Detection deployment
# set the version number to the version you export
# ensure version number does not yet have a trained model
version = project.version(27)
version.deploy("yolov8", "runs/detect/train/") #auto-appends weights/best.pt to model_path
If weights upload is attempted for dataset versions that already have a trained model (a Roboflow Train model or uploaded YOLOv5 or YOLOv8 weights) then you will receive a RuntimeError - "This version already has a trained model. Please generate and train a new version in order to upload model to Roboflow."
If upload is attempted for a model architecture that is not yet supported for weights upload, then you will receive a ValueError.

Next Steps

  1. 1.
    Test out your model in the Deploy Tab.
  2. 2.
    Deploy Your Model with Roboflow Deploy.
  3. 3.
    Improve Your Model with Active Learning | What is Active Learning?
While other architectures are not yet available for weights upload, if you have interest in training and deploying a different custom architecture on your own, check out the Roboflow Notebooks Github Repository for full written and video guides.