Spaces:
Runtime error
Runtime error
Upload 2 files
Browse files
app.py
ADDED
@@ -0,0 +1,45 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
#ONLY yolov5 single input and output
|
2 |
+
import gradio as gr
|
3 |
+
from ultralyticsplus import YOLO
|
4 |
+
#import yolov5
|
5 |
+
from PIL import Image
|
6 |
+
|
7 |
+
# Load your model
|
8 |
+
# model = yolov5.load('MvitHYF/cocoaseedyolov5mvit')
|
9 |
+
model_path = "best.pt"
|
10 |
+
model = YOLO(model_path)
|
11 |
+
model.conf = 0.40
|
12 |
+
model.iou = 0.45
|
13 |
+
model.agnostic = True
|
14 |
+
model.multi_label = False
|
15 |
+
model.max_det = 100
|
16 |
+
# model.overrides['conf'] = 0.25 # NMS confidence threshold
|
17 |
+
# model.overrides['iou'] = 0.45 # NMS IoU threshold
|
18 |
+
# model.overrides['agnostic_nms'] = False # NMS class-agnostic
|
19 |
+
# model.overrides['max_det'] = 1000 # maximum number of detections per image
|
20 |
+
|
21 |
+
#css = ".output_image {height: 40rem !important; width: 100% !important;}"
|
22 |
+
|
23 |
+
def predict(input_image):
|
24 |
+
try:
|
25 |
+
# Perform inference
|
26 |
+
results = model(input_image, size=(1920), augment=True)
|
27 |
+
|
28 |
+
# Convert result image with bounding boxes to PIL format for Gradio output
|
29 |
+
result_image = Image.fromarray(results.render()[0])
|
30 |
+
|
31 |
+
return result_image
|
32 |
+
|
33 |
+
except Exception as e:
|
34 |
+
return f"Error: {str(e)}"
|
35 |
+
|
36 |
+
# Set up Gradio interface
|
37 |
+
interface = gr.Interface(
|
38 |
+
fn=predict,
|
39 |
+
inputs=gr.Image(type="pil", label="Upload an Image1"),
|
40 |
+
outputs=gr.Image(type="pil", label="Result1"),
|
41 |
+
#css = css,
|
42 |
+
title="Object Detection using YOLOv5",
|
43 |
+
description="Upload an image to detect objects using the YOLOv5 model"
|
44 |
+
)
|
45 |
+
interface.launch()
|
best.pt
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:31ebd2c1660df6974903a85db59e44f78b10685299b030f2d991d803782d992e
|
3 |
+
size 14645181
|