YOLOv5

Use the YOLOv5 model family through our Serverless Cloud API

We support YOLOv5 object detection and instance segmentation inferencing via our Serverless Cloud API and self-hosted Inference. Training YOLOv5 is not supported on Roboflow, but you can upload pretrained weights (model_type="yolov5") for an existing Project and serve them through any deployment target. For a Roboflow-trained detector, see RF-DETR, YOLO26, or YOLO11.

YOLOv5 input size is set when you train your model outside Roboflow (typical values: 640x640 or 1280x1280).

YOLOv5 API

1

Get your API Key

Create a Roboflow account, find your key on the Roboflow API settings page and make it available to your shell:

export ROBOFLOW_API_KEY="your-key-here"
2

Install the dependencies

Install the SDK and supervision for decoding and annotation:

pip install -U inference-sdk supervision
3

Run the model

Swap in the {workspace}/{model-slug} ID of your uploaded YOLOv5 model (see Versions, Trainings, and Models).

import os
import cv2
import supervision as sv
from inference_sdk import InferenceHTTPClient

image = sv.load_image_from_url("https://media.roboflow.com/quickstart/traffic.jpg")

client = InferenceHTTPClient(
    api_url="https://serverless.roboflow.com",
    api_key=os.environ["ROBOFLOW_API_KEY"],
)
result = client.infer(image, model_id="your-workspace/your-model-slug")

detections = sv.Detections.from_inference(result)

annotated = sv.BoxAnnotator().annotate(image.copy(), detections)
annotated = sv.LabelAnnotator().annotate(annotated, detections)

cv2.imwrite("annotated.png", annotated)

Set api_url to match your deployment target:

  • https://serverless.roboflow.com for the Serverless Cloud API.
  • http://localhost:9001 for a local Inference server.
  • Your Dedicated Deployment URL for a private endpoint.