Are you sure you want to delete this access key?
comments | description | keywords |
---|---|---|
true | Discover an interactive way to perform object detection with Ultralytics YOLO11 using Gradio. Upload images and adjust settings for real-time results. | Ultralytics, YOLO11, Gradio, object detection, interactive, real-time, image processing, AI |
This Gradio interface provides an easy and interactive way to perform object detection using the Ultralytics YOLO11 model. Users can upload images and adjust parameters like confidence threshold and intersection-over-union (IoU) threshold to get real-time detection results.
Watch: Gradio Integration with Ultralytics YOLO11
pip install gradio
This section provides the Python code used to create the Gradio interface with the Ultralytics YOLO11 model. The code supports classification tasks, detection tasks, segmentation tasks, and key point tasks.
import gradio as gr
import PIL.Image as Image
from ultralytics import ASSETS, YOLO
model = YOLO("yolo11n.pt")
def predict_image(img, conf_threshold, iou_threshold):
"""Predicts objects in an image using a YOLO11 model with adjustable confidence and IOU thresholds."""
results = model.predict(
source=img,
conf=conf_threshold,
iou=iou_threshold,
show_labels=True,
show_conf=True,
imgsz=640,
)
for r in results:
im_array = r.plot()
im = Image.fromarray(im_array[..., ::-1])
return im
iface = gr.Interface(
fn=predict_image,
inputs=[
gr.Image(type="pil", label="Upload Image"),
gr.Slider(minimum=0, maximum=1, value=0.25, label="Confidence threshold"),
gr.Slider(minimum=0, maximum=1, value=0.45, label="IoU threshold"),
],
outputs=gr.Image(type="pil", label="Result"),
title="Ultralytics Gradio",
description="Upload images for inference. The Ultralytics YOLO11n model is used by default.",
examples=[
[ASSETS / "bus.jpg", 0.25, 0.45],
[ASSETS / "zidane.jpg", 0.25, 0.45],
],
)
if __name__ == "__main__":
iface.launch()
Parameter Name | Type | Description |
---|---|---|
img |
Image |
The image on which object detection will be performed. |
conf_threshold |
float |
Confidence threshold for detecting objects. |
iou_threshold |
float |
Intersection-over-union threshold for object separation. |
Component | Description |
---|---|
Image Input | To upload the image for detection. |
Sliders | To adjust confidence and IoU thresholds. |
Image Output | To display the detection results. |
To use Gradio with Ultralytics YOLO11 for object detection, you can follow these steps:
pip install gradio
.Here's a minimal code snippet for reference:
import gradio as gr
from ultralytics import YOLO
model = YOLO("yolo11n.pt")
def predict_image(img, conf_threshold, iou_threshold):
results = model.predict(
source=img,
conf=conf_threshold,
iou=iou_threshold,
show_labels=True,
show_conf=True,
)
return results[0].plot() if results else None
iface = gr.Interface(
fn=predict_image,
inputs=[
gr.Image(type="pil", label="Upload Image"),
gr.Slider(minimum=0, maximum=1, value=0.25, label="Confidence threshold"),
gr.Slider(minimum=0, maximum=1, value=0.45, label="IoU threshold"),
],
outputs=gr.Image(type="pil", label="Result"),
title="Ultralytics Gradio YOLO11",
description="Upload images for YOLO11 object detection.",
)
iface.launch()
Using Gradio for Ultralytics YOLO11 object detection offers several benefits:
For more details, you can read this blog post on AI in radiology that showcases similar interactive visualization techniques.
Yes, Gradio and Ultralytics YOLO11 can be utilized together for educational purposes effectively. Gradio's intuitive web interface makes it easy for students and educators to interact with state-of-the-art deep learning models like Ultralytics YOLO11 without needing advanced programming skills. This setup is ideal for demonstrating key concepts in object detection and computer vision, as Gradio provides immediate visual feedback which helps in understanding the impact of different parameters on the detection performance.
In the Gradio interface for YOLO11, you can adjust the confidence and IoU thresholds using the sliders provided. These thresholds help control the prediction accuracy and object separation:
For more information on these parameters, visit the parameters explanation section.
Practical applications of combining Ultralytics YOLO11 with Gradio include:
For examples of similar use cases, check out the Ultralytics blog on animal behavior monitoring which demonstrates how interactive visualization can enhance wildlife conservation efforts.
Press p or to see the previous file or, n or to see the next file
Are you sure you want to delete this access key?
Are you sure you want to delete this access key?
Are you sure you want to delete this access key?
Are you sure you want to delete this access key?