For the complete documentation index, see llms.txt. This page is also available as Markdown.

Upload, Train, and Deploy a Model

From a folder of images to a hosted, callable model - end to end.

This recipe takes a folder of labeled images and ends with a hosted Roboflow model you can call from your application. Each step is short - the whole flow is ~30 lines of Python.

What you'll need

  • A Roboflow workspace and API key - see Find Your Roboflow API Key.

  • A folder of images plus matching annotations (COCO / VOC / YOLO).

  • Python >=3.10 and pip install roboflow.

  • Time and credits to train (typically minutes for small datasets).

export ROBOFLOW_API_KEY=rf_xxxxx

1. Create the project

import roboflow

rf = roboflow.Roboflow()
ws = rf.workspace()

project = ws.create_project(
    project_name="My Detector",
    project_type="object-detection",
    project_license="MIT",            # or "Private" on paid plans
    annotation="objects",              # what you're labeling
)
print(project.id)

If the project already exists, fetch it instead:

2. Upload the dataset

The expected layout for a COCO dataset:

For VOC and YOLO, drop the corresponding annotation files alongside the images.

3. Generate a version

A version freezes a snapshot of the dataset with preprocessing and augmentation applied. The web app has a UI for this; from the SDK:

4. Train

train() schedules the job server-side and returns once the queue accepts it. Check progress in the web app or via GET /:workspace/:project/jobs/:jobId.

5. Run inference

Once training completes, call the hosted model:

That's the same hosted Serverless v2 endpoint the REST API and CLI infer hit.

6. (Optional) Move to a Dedicated Deployment

For high throughput or pinned latency, provision a Dedicated Deployment and point inference at its public_url:

Variations

  • CI-driven retraining: replace step 1's create_project with project = ws.project(...), automate steps 2–4 in a GitHub Action that runs whenever new labeled images land in your data store. The CLI flavor (roboflow upload, roboflow version create, roboflow train start) makes the YAML cleaner.

  • Active-learning loop: skip step 5 and use Workspace.active_learning() to triage new images against the trained model and feed back the uncertain ones.

  • Custom weights: skip steps 3–4 and use Version.deploy() to upload an externally trained model into the version.

Last updated

Was this helpful?