Comment on page
Run inference on an image and retrieve predictions.
Roboflow provides an API through which you can upload an image and retrieve predictions from your model. This API is available in the Roboflow Python SDK, REST API, and CLI.
To run inference using the Python SDK, use the
rf = roboflow.Roboflow(api_key=YOUR_API_KEY_HERE)
project = rf.workspace().project("PROJECT_ID")
model = project.version("1").model
# optionally, change the confidence and overlap thresholds
# values are percentages
model.confidence = 50
model.overlap = 25
# predict on a local image
prediction = model.predict("YOUR_IMAGE.jpg")
# Predict on a hosted image via file name
prediction = model.predict("YOUR_IMAGE.jpg", hosted=True)
# Predict on a hosted image via URL
prediction = model.predict("https://...", hosted=True)
# Plot the prediction in an interactive environment
# Convert predictions to JSON
If you have a locally running Roboflow inference server running through any of our container deploys, such as the NVIDIA Jetson or Raspberry Pi container, you can use
version()to point towards that locally running server instead of the remote endpoint by specifying the IP address of the locally running inference server.
The local inference server must be running and available for communication before executing the python script! When using our docker containers with the
--net=hostflag, we recommend referencing via the
local_inference_server_address = "http://localhost:9001/"
version_number = 1
local_model = project.version(
To run inference from the CLI, use this command:
roboflow infer -m <project-name>/<version-number> <image-name>
-moption specifies which model and version should be used for inference. If you have trained your own custom model you can substitute the model/version for one of your own. This will work for object-detection, classification, instance segmentation, or semantic segmentation models.
Last modified 3mo ago