Spaces:
Sleeping
Sleeping
# Copyright (C) 2025 Anthony Casagrande | |
# Ultralytics YOLO π, AGPL-3.0 license | |
import gradio as gr | |
import PIL.Image as Image | |
from ultralytics import ASSETS, YOLO | |
model = None | |
def predict_image(img, conf_threshold, iou_threshold, model_name): | |
"""Predicts objects in an image using a YOLOv11 model with adjustable confidence and IOU thresholds.""" | |
model = YOLO("train29s.pt") | |
results = model.predict( | |
source=img, | |
conf=conf_threshold, | |
iou=iou_threshold, | |
show_labels=True, | |
show_conf=True, | |
imgsz=1280, | |
) | |
for r in results: | |
im_array1 = r.plot(img=img.copy(), labels=False, line_width=4) | |
im1 = Image.fromarray(im_array1[..., ::-1]) | |
for r in results: | |
im_array2 = r.plot(img=img.copy(), line_width=4, font_size=10) | |
im2 = Image.fromarray(im_array2[..., ::-1]) | |
# Calculate the dimensions for the output image | |
total_height = im1.height + im2.height | |
total_width = im1.width | |
# Create a blank image with the combined height | |
im = Image.new("BGR", (total_width, total_height)) | |
# Paste the images one above the other | |
im.paste(im1, (0, 0)) | |
im.paste(im2, (0, im1.height)) | |
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.80, label="IoU threshold"), | |
# gr.Radio(choices=["yolo11n", "yolo11s", "yolo11n-seg", "yolo11s-seg", "yolo11n-pose", "yolo11s-pose"], label="Model Name", value="yolo11n"), | |
], | |
outputs=gr.Image(type="pil", label="Result"), | |
title="RC Race Vision YOLO11 Gradio Application π", | |
description="Upload images of RC Race Cars for inference. \nCurrently supports 1/8th Buggies, and 1/10th Scale Buggies, Stadium Trucks, and Short Course Trucks.\nNot intended to work with close-up shots, works better on a wide view of the cars on a track.", | |
examples=[ | |
["rc1.jpg", 0.25, 0.8], | |
["rc2.jpg", 0.25, 0.8], | |
], | |
) | |
iface.launch(share=True) | |