YOLOv7

Use YOLOv7 instance segmentation through our Serverless Cloud API

We support YOLOv7 instance segmentation inferencing via our Serverless Cloud API. Training YOLOv7 is not supported on Roboflow, but you can upload your own weights and run inference against them.

For self-hosted deployment, see Roboflow Inference.

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

YOLOv7 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 Inference SDK and supervision for decoding and drawing masks:

pip install -U inference-sdk supervision opencv-python
3

Run the model

This example runs a public YOLOv7 instance segmentation model trained on concrete surface defects (concrete-pugqq/3), then uses supervision to render the predicted masks. To serve your own weights, swap in your {workspace}/{model-slug} ID (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/docs/concrete-crack.jpg")

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

detections = sv.Detections.from_inference(results)

annotated = sv.MaskAnnotator().annotate(image.copy(), 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.