Spaces:
Sleeping
Sleeping
Commit
·
4795cf5
1
Parent(s):
c629158
Fix: parsing results
Browse files
app.py
CHANGED
@@ -19,20 +19,29 @@ COLORS = np.random.uniform(0, 255, size=(80, 3))
|
|
19 |
def parse_detections(results, yolo_version):
|
20 |
if yolo_version == "yolov5":
|
21 |
detections = results.pandas().xyxy[0].to_dict()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
22 |
else:
|
23 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
24 |
|
25 |
-
boxes, colors, names = [], [], []
|
26 |
-
for i in range(len(detections["xmin"])):
|
27 |
-
confidence = detections["confidence"][i]
|
28 |
-
if confidence < 0.2:
|
29 |
-
continue
|
30 |
-
xmin, ymin = int(detections["xmin"][i]), int(detections["ymin"][i])
|
31 |
-
xmax, ymax = int(detections["xmax"][i]), int(detections["ymax"][i])
|
32 |
-
name, category = detections["name"][i], int(detections["class"][i])
|
33 |
-
boxes.append((xmin, ymin, xmax, ymax))
|
34 |
-
colors.append(COLORS[category])
|
35 |
-
names.append(name)
|
36 |
return boxes, colors, names
|
37 |
|
38 |
# Draw bounding boxes and labels
|
|
|
19 |
def parse_detections(results, yolo_version):
|
20 |
if yolo_version == "yolov5":
|
21 |
detections = results.pandas().xyxy[0].to_dict()
|
22 |
+
boxes, colors, names = [], [], []
|
23 |
+
for i in range(len(detections["xmin"])):
|
24 |
+
confidence = detections["confidence"][i]
|
25 |
+
if confidence < 0.2:
|
26 |
+
continue
|
27 |
+
xmin, ymin = int(detections["xmin"][i]), int(detections["ymin"][i])
|
28 |
+
xmax, ymax = int(detections["xmax"][i]), int(detections["ymax"][i])
|
29 |
+
name, category = detections["name"][i], int(detections["class"][i])
|
30 |
+
boxes.append((xmin, ymin, xmax, ymax))
|
31 |
+
colors.append(COLORS[category])
|
32 |
+
names.append(name)
|
33 |
else:
|
34 |
+
boxes.append(results[0].boxes.xyxy) # Bounding boxes in xyxy format (x1, y1, x2, y2)
|
35 |
+
confidences = results[0].boxes.conf # Confidence scores
|
36 |
+
class_ids = results[0].boxes.cls # Class IDs
|
37 |
+
names.append(results[0].names) # Class names (from model)
|
38 |
+
colors = []
|
39 |
+
# Append predefined color based on category (class ID)
|
40 |
+
for class_id in class_ids:
|
41 |
+
# Map class ID to a color from the COLORS list (make sure you have enough colors)
|
42 |
+
color = COLORS[int(class_id) % len(COLORS)] # Use modulo to avoid index error
|
43 |
+
colors.append(color)
|
44 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
45 |
return boxes, colors, names
|
46 |
|
47 |
# Draw bounding boxes and labels
|