Make Predictions

Run predictions on images, image URLs, directories, and video files from the command line with inference infer.

The inference infer command offers an easy way to make predictions from your model based on your input images or video files, sending requests to an Inference Server.

To see the details of the command, run:

inference infer --help

Command details

inference infer takes an input path or URL and a model version to produce predictions (and optionally makes a visualisation using supervision). You can also specify a host to run inference on the Roboflow hosted inference server.

If you are using a local Inference Server, make sure the command inference server start was used first.

Your Roboflow API key can be provided via the ROBOFLOW_API_KEY environment variable.

Examples

Predict on a local image

This command makes a prediction from a local image using the selected model and prints the prediction on the console.

inference infer -i ./image.jpg -m {your_project}/{version} --api-key {YOUR_API_KEY}

To display the visualised prediction, use the -D option. To save the prediction and visualisation in a local directory, use the -o {path_to_your_directory} option. These options also work in the other modes.

inference infer -i ./image.jpg -m {your_project}/{version} --api-key {YOUR_API_KEY} -D -o {path_to_your_output_directory}

Predict on an image URL

inference infer -i https://[YOUR_HOSTED_IMAGE_URL] -m {your_project}/{version} --api-key {YOUR_API_KEY}

Using the hosted API

inference infer -i ./image.jpg -m {your_project}/{version} --api-key {YOUR_API_KEY} -h https://serverless.roboflow.com

Predict from a local directory

inference infer -i {your_directory_with_images} -m {your_project}/{version} -o {path_to_your_output_directory} --api-key {YOUR_API_KEY}

Predict on a video file

inference infer -i {path_to_your_video_file} -m {your_project}/{version} -o {path_to_your_output_directory} --api-key {YOUR_API_KEY}

Configure the visualization

The -c option can be provided with a path to a *.yml file configuring supervision visualisation. There are a few pre-defined configs:

  • bounding_boxes - with BoxAnnotator and LabelAnnotator annotators
  • bounding_boxes_tracing - with ByteTracker and annotators (BoxAnnotator, LabelAnnotator)
  • masks - with MaskAnnotator and LabelAnnotator annotators
  • polygons - with PolygonAnnotator and LabelAnnotator annotators

A custom configuration can be created following this schema:

annotators:
  - type: "bounding_box"
    params:
      thickness: 2
  - type: "label"
    params:
      text_scale: 0.5
      text_thickness: 2
      text_padding: 5
  - type: "trace"
    params:
      trace_length: 60
      thickness: 2
tracking:
  track_activation_threshold: 0.25
  lost_track_buffer: 30
  minimum_matching_threshold: 0.8
  frame_rate: 30

The annotators field is a list of dictionaries with two keys: type and param. type points to the name of an annotator class:

from supervision import *
ANNOTATOR_TYPE2CLASS = {
    "bounding_box": BoxAnnotator,
    "box": BoxAnnotator,
    "mask": MaskAnnotator,
    "polygon": PolygonAnnotator,
    "color": ColorAnnotator,
    "halo": HaloAnnotator,
    "ellipse": EllipseAnnotator,
    "box_corner": BoxCornerAnnotator,
    "circle": CircleAnnotator,
    "dot": DotAnnotator,
    "label": LabelAnnotator,
    "blur": BlurAnnotator,
    "trace": TraceAnnotator,
    "heat_map": HeatMapAnnotator,
    "pixelate": PixelateAnnotator,
    "triangle": TriangleAnnotator,
}

param is a dictionary of annotator constructor parameters (check them in the supervision docs; you can only use primitive values, since classes and enums defined in constructors may not be resolvable from a YAML config).

tracking is an optional key that holds a dictionary with constructor parameters for ByteTrack.

Provide inference hyperparameters

The -mc parameter can be provided with a path to a *.yml file that specifies the model configuration (such as confidence threshold or IoU threshold). If given, the configuration is used to initialise an InferenceConfiguration object from the inference_sdk library. See the Inference SDK configuration reference to discover which options can be configured via the *.yml file. Configuration keys must match the names of fields in the InferenceConfiguration object.