Spaces:
Running
on
Zero
Running
on
Zero
File size: 1,982 Bytes
45439d0 79d95c0 1d11470 79d95c0 1d11470 45439d0 79d95c0 45439d0 8c94676 45439d0 28751ad 45439d0 aafcd69 c371468 45439d0 3359693 45439d0 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
import gradio as gr
import PIL.Image as Image
from ultralytics import YOLO
import spaces
@spaces.GPU
def yolo_inference(images, model_id, conf_threshold, iou_threshold, max_detection):
model = YOLO(model_id)
results = model.predict(
source=images,
conf=conf_threshold,
iou=iou_threshold,
imgsz=640,
max_det=max_detection,
show_labels=True,
show_conf=True,
)
for r in results:
image_array = r.plot()
image = Image.fromarray(image_array[..., ::-1])
return image
interface = gr.Interface(
fn=yolo_inference,
inputs=[
gr.Image(type="pil", label="Upload Image"),
gr.Dropdown(
choices=['yolo11n.pt', 'yolo11s.pt', 'yolo11m.pt', 'yolo11l.pt', 'yolo11x.pt',
'yolo11n-seg.pt', 'yolo11s-seg.pt', 'yolo11m-seg.pt', 'yolo11l-seg.pt', 'yolo11x-seg.pt',
'yolo11n-pose.pt', 'yolo11s-pose.pt', 'yolo11m-pose.pt', 'yolo11l-pose.pt', 'yolo11x-pose.pt',
'yolo11n-obb.pt', 'yolo11s-obb.pt', 'yolo11m-obb.pt', 'yolo11l-obb.pt', 'yolo11x-obb.pt',
'yolo11n-cls.pt', 'yolo11s-cls.pt', 'yolo11m-cls.pt', 'yolo11l-cls.pt', 'yolo11x-cls.pt'],
label="Model Name",
value="yolo11n.pt",
),
gr.Slider(minimum=0, maximum=1, value=0.25, label="Confidence Threshold"),
gr.Slider(minimum=0, maximum=1, value=0.45, label="IoU Threshold"),
gr.Slider(minimum=1, maximum=300, step=1, value=300, label="Max Detection"),
],
outputs=gr.Image(type="pil", label="Annotated Image"),
cache_examples=True,
title="Yolo11: Object Detection",
description="Upload image(s) for inference using the latest Ultralytics YOLO11 models.",
examples=[
["zidane.jpg", "yolo11s.pt", 0.25, 0.45, 300],
["bus.jpg", "yolo11m.pt", 0.25, 0.45, 300],
["yolo_vision.jpg", "yolo11x.pt", 0.25, 0.45, 300],
],
)
interface.launch() |