Update app.py
#1
by
Q-bert
- opened
app.py
CHANGED
@@ -1,7 +1,7 @@
|
|
1 |
import gradio as gr
|
2 |
import sahi
|
3 |
import torch
|
4 |
-
from
|
5 |
|
6 |
# Download sample images
|
7 |
sahi.utils.file.download_from_url(
|
@@ -60,26 +60,16 @@ def yolov8_inference(
|
|
60 |
model.overrides["iou"] = iou_threshold
|
61 |
|
62 |
# Perform model prediction
|
63 |
-
results = model
|
64 |
|
65 |
# Initialize an empty list to store the output
|
66 |
output = []
|
67 |
|
68 |
# Iterate over the results
|
69 |
-
for
|
70 |
-
|
71 |
-
|
72 |
-
|
73 |
-
for i, (mask, box) in enumerate(zip(masks, result['boxes'])):
|
74 |
-
label = model.names[int(result['boxes']['cls'][i])]
|
75 |
-
mask_coords = mask.tolist() # Convert mask coordinates to list format
|
76 |
-
output.append({"label": label, "mask_coords": mask_coords})
|
77 |
-
else:
|
78 |
-
# If masks are not available, just extract bounding box information
|
79 |
-
for i, box in enumerate(result['boxes']):
|
80 |
-
label = model.names[int(result['boxes']['cls'][i])]
|
81 |
-
bbox = box['xyxy'].tolist() # Bounding box coordinates
|
82 |
-
output.append({"label": label, "bbox_coords": bbox})
|
83 |
|
84 |
return output
|
85 |
|
|
|
1 |
import gradio as gr
|
2 |
import sahi
|
3 |
import torch
|
4 |
+
from ultralytics import YOLO
|
5 |
|
6 |
# Download sample images
|
7 |
sahi.utils.file.download_from_url(
|
|
|
60 |
model.overrides["iou"] = iou_threshold
|
61 |
|
62 |
# Perform model prediction
|
63 |
+
results = model(image)
|
64 |
|
65 |
# Initialize an empty list to store the output
|
66 |
output = []
|
67 |
|
68 |
# Iterate over the results
|
69 |
+
for i,box in enumerate(results[0].boxes):
|
70 |
+
label = results[0].names[box.cls[0].item()]
|
71 |
+
bbox = box.xyxy[0]
|
72 |
+
output.append({"label": label, "bbox_coords": bbox})
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
73 |
|
74 |
return output
|
75 |
|