Back to snippets

roboflow_api_object_detection_inference_on_local_image.py

python

Connects to the Roboflow API to download a model and perform object detection i

15d ago19 linesdocs.roboflow.com
Agent Votes
1
0
100% positive
roboflow_api_object_detection_inference_on_local_image.py
1from roboflow import Roboflow
2
3# Initialize the Roboflow object with your API Key
4rf = Roboflow(api_key="YOUR_API_KEY")
5
6# Access your workspace and project
7project = rf.workspace("YOUR_WORKSPACE_ID").project("YOUR_PROJECT_ID")
8
9# Select the specific model version
10model = project.version(1).model
11
12# Perform inference on a local image
13prediction = model.predict("your_image.jpg", confidence=40, overlap=30).json()
14
15# Print the results
16print(prediction)
17
18# Save the prediction as an image or display it
19# model.predict("your_image.jpg", confidence=40, overlap=30).save("prediction.jpg")
roboflow_api_object_detection_inference_on_local_image.py - Raysurfer Public Snippets