Spaces:
Sleeping
Sleeping
Commit
·
83c6e0c
1
Parent(s):
979f955
Debug: parsing detections
Browse files
yolov8.py
CHANGED
@@ -12,20 +12,18 @@ import gradio as gr
|
|
12 |
COLORS = np.random.uniform(0, 255, size=(80, 3))
|
13 |
|
14 |
def parse_detections(results):
|
15 |
-
detections = results.pandas().xyxy[0].to_dict()
|
16 |
boxes, colors, names = [], [], []
|
17 |
-
for
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
names.append(name)
|
27 |
-
return boxes, colors, names
|
28 |
|
|
|
29 |
|
30 |
def draw_detections(boxes, colors, names, img):
|
31 |
for box, color, name in zip(boxes, colors, names):
|
@@ -58,8 +56,7 @@ def xai_yolov8n(image):
|
|
58 |
|
59 |
target_layers = [model.model.model[-2]] # Grad-CAM target layer
|
60 |
results = model([image])
|
61 |
-
|
62 |
-
boxes, colors, names = parse_detections(results[0])
|
63 |
detections_img = draw_detections(boxes, colors, names, image.copy())
|
64 |
img_float = np.float32(image) / 255
|
65 |
transform = transforms.ToTensor()
|
|
|
12 |
COLORS = np.random.uniform(0, 255, size=(80, 3))
|
13 |
|
14 |
def parse_detections(results):
|
|
|
15 |
boxes, colors, names = [], [], []
|
16 |
+
for result in results:
|
17 |
+
# Accessing boxes directly from the result
|
18 |
+
for box in result.boxes:
|
19 |
+
xmin, ymin, xmax, ymax = box.xyxy[0].int().tolist() # Convert to list of integers
|
20 |
+
category = int(box.cls[0].item()) # Class index
|
21 |
+
name = result.names[category] # Get class name from names
|
22 |
+
boxes.append((xmin, ymin, xmax, ymax))
|
23 |
+
colors.append(COLORS[category]) # Ensure COLORS is defined elsewhere in your code
|
24 |
+
names.append(name)
|
|
|
|
|
25 |
|
26 |
+
return boxes, colors, names
|
27 |
|
28 |
def draw_detections(boxes, colors, names, img):
|
29 |
for box, color, name in zip(boxes, colors, names):
|
|
|
56 |
|
57 |
target_layers = [model.model.model[-2]] # Grad-CAM target layer
|
58 |
results = model([image])
|
59 |
+
boxes, colors, names = parse_detections(results)
|
|
|
60 |
detections_img = draw_detections(boxes, colors, names, image.copy())
|
61 |
img_float = np.float32(image) / 255
|
62 |
transform = transforms.ToTensor()
|