Spaces:
Build error
Build error
File size: 2,353 Bytes
696f4a2 1b575bc 8382c5c c1d776a 2dc0faa 696f4a2 2dc0faa f1be3ff 2dc0faa a00fc6b fb13f18 2dc0faa 696f4a2 2dc0faa 696f4a2 2dc0faa 696f4a2 2dc0faa ac4c5db 1b991ca 2dc0faa 696f4a2 2dc0faa 696f4a2 2dc0faa 696f4a2 |
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 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 |
import gradio as gr
import spaces
from huggingface_hub import hf_hub_download
import yolov9
model = yolov9.load('best.pt')
# classes = ('ball', 'goalkeeper', 'player', 'referee')
def inference(input_img, conf_threshold, iou_threshold):
# Set model parameters
model.conf = conf_threshold
model.iou = iou_threshold
# Perform inference
image_size = input_img.shape
results = model(input_img, size=image_size)
# Optionally, show detection bounding boxes on image
output = results.render()
return output[0]
def app():
with gr.Blocks():
with gr.Row():
with gr.Column():
input_img = gr.Image(width= 256, height=256,label="Image")
conf_threshold = gr.Slider(
label="Confidence threshold",
minimum=0.1,
maximum=1.0,
step=0.1,
value=0.4
)
iou_threshold = gr.Slider(
label="IoU Threshold",
minimum=0.1,
maximum=1.0,
step=0.1,
value=0.5,
)
yolo_inf = gr.Button(value="Inference")
with gr.Column():
output_val = gr.Image(width= 256, height=256,label="Output Image")
yolo_inf.click(
fn= inference,
inputs = [
input_img,
conf_threshold,
iou_threshold
],
outputs = [output_val],
)
gr.Examples([["img1.jpg",0.4, 0.6, 0.4],
["img2.jpg",0.1, 0.2, 1.0]],
fn= inference,
inputs = [
input_img,
conf_threshold,
iou_threshold
],
outputs = [output_val],
cache_examples=True,
)
demo = gr.Blocks()
with demo:
gr.HTML(
"""
<h1 style='text-align: center'>
YOLOv9
</h1>
""")
gr.HTML(
"""
<h3 style='text-align: center'>
Inferencing yolov9 with custom dataset - football players dataset
</h3>
""")
with gr.Row():
with gr.Column():
app()
demo.launch(debug=True)
|