Skip to content

From Roboflow

With Inference, you can run any of the 50,000+ models available on Roboflow Universe. You can also run private, fine-tuned models that you have trained or uploaded to Roboflow.

All models run on your own hardware.

Run a Model From Roboflow Universe

In the first example, we showed how to run a people detection model. This model was hosted on Universe. Let's find another model to try.

Go to the Roboflow Universe homepage and use the search bar to find a model.

Roboflow Universe search bar

Info

Add "model" to your search query to only find models.

Browse the search page to find a model.

Search page

When you have found a model, click on the model card to learn more. Click the "Model" link in the sidebar to get the information you need to use the model.

Then, install Inference and supervision, which we will use to run our model and handle model predictions, respectively:

pip install inference supervision

Next, create a new Python file and add the following code:

# import a utility function for loading Roboflow models
from inference import get_model
# import supervision to visualize our results
import supervision as sv
# import cv2 to helo load our image
import cv2

# define the image url to use for inference
image_file = "people-walking.jpg"
image = cv2.imread(image_file)

# load a pre-trained yolov8n model
model = get_model(model_id="yolov8n-640")

# run inference on our chosen image, image can be a url, a numpy array, a PIL image, etc.
results = model.infer(image)

# load the results into the supervision Detections api
detections = sv.Detections.from_inference(results[0].dict(by_alias=True, exclude_none=True))

# create supervision annotators
bounding_box_annotator = sv.BoundingBoxAnnotator()
label_annotator = sv.LabelAnnotator()

# annotate the image with our inference results
annotated_image = bounding_box_annotator.annotate(
    scene=image, detections=detections)
annotated_image = label_annotator.annotate(
    scene=annotated_image, detections=detections)

# display the image
sv.plot_image(annotated_image)

Tip

To see more models, check out the Pre-Trained Models page and Roboflow Universe.

The people-walking.jpg file is hosted here.

Replace yolov8n-640 with the model ID you found on Universe, replace image with the image of your choosing, and be sure to export your API key:

export ROBOFLOW_API_KEY=<your api key>

Then, run the Python script:

python app.py

You should see your model's predictions visualized on your screen.

People Walking Annotated

Run a Private, Fine-Tuned Model

You can run models you have trained privately on Roboflow with Inference. To do so, first go to your Roboflow dashboard. Then, choose the model you want to run.

Roboflow dashboard

Click the "Deploy" link in the sidebar to find the information you will need to use your model with Inference.

Copy the model ID on the page (in this case, taylor-swift-records/3).

Model page

Then, create a new Python file and add the following code:

# import a utility function for loading Roboflow models
from inference import get_model
# import supervision to visualize our results
import supervision as sv
# import cv2 to helo load our image
import cv2

# define the image url to use for inference
image_file = "taylor-swift-album-1989.jpeg"
image = cv2.imread(image_file)

# load a pre-trained yolov8n model
model = get_model(model_id="taylor-swift-records/3")

# run inference on our chosen image, image can be a url, a numpy array, a PIL image, etc.
results = model.infer(image)

# load the results into the supervision Detections api
detections = sv.Detections.from_inference(results[0].dict(by_alias=True, exclude_none=True))

# create supervision annotators
bounding_box_annotator = sv.BoundingBoxAnnotator()
label_annotator = sv.LabelAnnotator()

# annotate the image with our inference results
annotated_image = bounding_box_annotator.annotate(
    scene=image, detections=detections)
annotated_image = label_annotator.annotate(
    scene=annotated_image, detections=detections)

# display the image
sv.plot_image(annotated_image)

The taylor-swift-album-1989.jpeg file is hosted here.

Replace taylor-swift-records/3 with the model ID from your private model and ensure your API key is in your environment:

export ROBOFLOW_API_KEY=<your api key>

Then, run the Python script:

python app.py

You should see your model's predictions visualized on your screen.

Taylor Swift Album