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

Roboflow 3.0

Use the Roboflow 3.0 model family through our Serverless Hosted API

Roboflow 3.0 Object Detection

Roboflow 3.0 is Roboflow's in-house model architecture. You train Roboflow 3.0 models on the Roboflow platform and deploy them through the Serverless Hosted API. The sample below runs Roboflow's public COCO model (coco/3) so you can try it immediately. For self-hosted deployment, see Roboflow Inference.

Code sample

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 Inference SDK and supervision:

pip install inference-sdk supervision
3

Run the model

Run detection on a sample image and annotate boxes and labels:

import os
import cv2
import numpy as np
import requests
import supervision as sv
from inference_sdk import InferenceHTTPClient

content = requests.get("https://media.roboflow.com/quickstart/traffic.jpg").content
image = cv2.imdecode(np.frombuffer(content, np.uint8), cv2.IMREAD_COLOR)

client = InferenceHTTPClient(
    api_url="https://serverless.roboflow.com",
    api_key=os.environ["ROBOFLOW_API_KEY"],
)
result = client.infer(image, model_id="coco/3")

detections = sv.Detections.from_inference(result)

annotated = sv.BoxAnnotator().annotate(image.copy(), detections)
annotated = sv.LabelAnnotator().annotate(annotated, detections)
cv2.imwrite("output.png", annotated)

Set api_url to match your deployment target:

  • https://serverless.roboflow.com for the Serverless Hosted API.

  • http://localhost:9001 for a local Inference server.

  • Your Dedicated Deployment URL for a private endpoint.

Roboflow 3.0 Instance Segmentation

Train a Roboflow 3.0 instance segmentation model, then replace your-project/1 with your own {workspace}/{model-slug} ID (see Versions, Trainings, and Models). Set your API key and install the dependencies as shown above.

Code sample

import os
import cv2
import numpy as np
import requests
import supervision as sv
from inference_sdk import InferenceHTTPClient

content = requests.get("https://media.roboflow.com/quickstart/traffic.jpg").content
image = cv2.imdecode(np.frombuffer(content, np.uint8), cv2.IMREAD_COLOR)

client = InferenceHTTPClient(
    api_url="https://serverless.roboflow.com",
    api_key=os.environ["ROBOFLOW_API_KEY"],
)
# No pretrained aliases: train your own model and replace "your-project/1" with your model ID.
result = client.infer(image, model_id="your-project/1")

detections = sv.Detections.from_inference(result)

annotated = sv.MaskAnnotator().annotate(image.copy(), detections)
annotated = sv.LabelAnnotator().annotate(annotated, detections)
cv2.imwrite("output.png", annotated)

Roboflow 3.0 Keypoint Detection

This example runs the public rf-handpose hand keypoint model, then draws the 21-point hand skeleton. Swap in your own {workspace}/{model-slug}. Set your API key and install the dependencies as shown above.

Code sample

Roboflow 3.0 Classification

Classification responses contain a list of class predictions with confidences, so visualization is not applicable. Read the top class directly from the response. Replace your-project/1 with your trained model ID, and set your API key and install the dependencies as shown above.

Code sample

Last updated

Was this helpful?