kedimestan
commited on
Update app.py
Browse files
app.py
CHANGED
@@ -1,9 +1,9 @@
|
|
1 |
import gradio as gr
|
2 |
import sahi
|
3 |
import torch
|
4 |
-
from ultralyticsplus import YOLO
|
5 |
|
6 |
-
#
|
7 |
sahi.utils.file.download_from_url(
|
8 |
"https://raw.githubusercontent.com/kadirnar/dethub/main/data/images/highway.jpg",
|
9 |
"highway.jpg",
|
@@ -17,7 +17,6 @@ sahi.utils.file.download_from_url(
|
|
17 |
"zidane.jpg",
|
18 |
)
|
19 |
|
20 |
-
|
21 |
model_names = [
|
22 |
"yolov8n-seg.pt",
|
23 |
"yolov8s-seg.pt",
|
@@ -46,7 +45,7 @@ def yolov8_inference(
|
|
46 |
conf_threshold: Confidence threshold
|
47 |
iou_threshold: IOU threshold
|
48 |
Returns:
|
49 |
-
|
50 |
"""
|
51 |
global model
|
52 |
global current_model_name
|
@@ -56,14 +55,14 @@ def yolov8_inference(
|
|
56 |
model.overrides["conf"] = conf_threshold
|
57 |
model.overrides["iou"] = iou_threshold
|
58 |
results = model.predict(image, imgsz=image_size, return_outputs=True)
|
59 |
-
|
60 |
-
|
61 |
-
|
62 |
-
|
63 |
-
|
64 |
-
|
65 |
|
66 |
-
return
|
67 |
|
68 |
|
69 |
inputs = [
|
@@ -80,8 +79,8 @@ inputs = [
|
|
80 |
gr.Slider(minimum=0.0, maximum=1.0, value=0.45, step=0.05, label="IOU Threshold"),
|
81 |
]
|
82 |
|
83 |
-
outputs = gr.
|
84 |
-
title = "
|
85 |
|
86 |
examples = [
|
87 |
["zidane.jpg", "yolov8m-seg.pt", 640, 0.6, 0.45],
|
|
|
1 |
import gradio as gr
|
2 |
import sahi
|
3 |
import torch
|
4 |
+
from ultralyticsplus import YOLO
|
5 |
|
6 |
+
# Download images
|
7 |
sahi.utils.file.download_from_url(
|
8 |
"https://raw.githubusercontent.com/kadirnar/dethub/main/data/images/highway.jpg",
|
9 |
"highway.jpg",
|
|
|
17 |
"zidane.jpg",
|
18 |
)
|
19 |
|
|
|
20 |
model_names = [
|
21 |
"yolov8n-seg.pt",
|
22 |
"yolov8s-seg.pt",
|
|
|
45 |
conf_threshold: Confidence threshold
|
46 |
iou_threshold: IOU threshold
|
47 |
Returns:
|
48 |
+
Bounding box coordinates in xyxy format
|
49 |
"""
|
50 |
global model
|
51 |
global current_model_name
|
|
|
55 |
model.overrides["conf"] = conf_threshold
|
56 |
model.overrides["iou"] = iou_threshold
|
57 |
results = model.predict(image, imgsz=image_size, return_outputs=True)
|
58 |
+
|
59 |
+
boxes = []
|
60 |
+
for result in results:
|
61 |
+
# Extract bounding boxes (xyxy format)
|
62 |
+
for box in result.boxes.xyxy:
|
63 |
+
boxes.append(box.tolist())
|
64 |
|
65 |
+
return boxes
|
66 |
|
67 |
|
68 |
inputs = [
|
|
|
79 |
gr.Slider(minimum=0.0, maximum=1.0, value=0.45, step=0.05, label="IOU Threshold"),
|
80 |
]
|
81 |
|
82 |
+
outputs = gr.JSON(label="Bounding Boxes (xyxy format)")
|
83 |
+
title = "YOLOv8 Bounding Box Extraction Demo"
|
84 |
|
85 |
examples = [
|
86 |
["zidane.jpg", "yolov8m-seg.pt", 640, 0.6, 0.45],
|