File size: 2,133 Bytes
aeeb601 afc670e b6d54f1 b0e1d53 fee70a2 aeeb601 9ce1868 939d079 b6d54f1 939d079 be96225 939d079 c134122 939d079 c134122 939d079 605ba81 b6d54f1 939d079 b6d54f1 939d079 b6d54f1 c1c1237 b6d54f1 c1c1237 b6d54f1 9ce1868 b6d54f1 e857e4e c134122 b6d54f1 e857e4e c134122 939d079 6cce185 |
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 |
import gradio as gr
import matplotlib.pyplot as plt
from PIL import Image
from ultralyticsplus import YOLO, render_result
import cv2
import numpy as np
model = YOLO('best (1).pt')
# def response(image):
# print(image)
# results = model(image)
# for i, r in enumerate(results):
# # Plot results image
# im_bgr = r.plot()
# im_rgb = im_bgr[..., ::-1] # Convert BGR to RGB
# # im_rgb = Image.fromarray(im_rgb)
# return im_rgb
def response2(image: gr.Image = None,image_size: gr.Slider = 640, conf_threshold: gr.Slider = 0.5, iou_threshold: gr.Slider = 0.6):
model = YOLO('best (1).pt')
results = model.predict(image, conf=conf_threshold, iou=iou_threshold, imgsz=image_size)
box = results[0].boxes
# render = render_result(model=model, image=image, result=results[0], rect_th = 1, text_th = 1
for i, r in enumerate(results):
# Plot results image
im_bgr = r.plot()
im_rgb = im_bgr[..., ::-1] # Convert BGR to RGB
# im_rgb = Image.fromarray(im_rgb)
return im_rgb
inputs = [
gr.Image(type="filepath", label="Input Image"),
gr.Slider(minimum=320, maximum=1280, value=640,
step=32, label="Image Size"),
gr.Slider(minimum=0.0, maximum=1.0, value=0.25,
step=0.05, label="Confidence Threshold"),
gr.Slider(minimum=0.0, maximum=1.0, value=0.45,
step=0.05, label="IOU Threshold"),
]
outputs = gr.Image( type="filepath", label="Output Image")
title = "YOLOv8 Custom Object Detection by Uyen Nguyen"
# examples = [['one.jpg', 900, 0.5, 0.8],
# ['two.jpg', 1152, 0.05, 0.05],
# ['three.jpg', 1024, 0.25, 0.25],
# ['four.jpg', 832, 0.3, 0.3]]
# yolo_app = gr.Interface(
# fn=yoloV8_func,
# inputs=inputs,
# outputs=outputs,
# title=title,
# # examples=examples,
# # cache_examples=True,
# )
# Launch the Gradio interface in debug mode with queue enabled
# yolo_app.launch()
iface = gr.Interface(fn=response2, inputs=inputs, outputs=outputs)
iface.launch()
|