Spaces:
Sleeping
Sleeping
Update tasks/image.py
Browse files- tasks/image.py +18 -12
tasks/image.py
CHANGED
@@ -108,31 +108,37 @@ async def evaluate_image(request: ImageEvaluationRequest):
|
|
108 |
true_boxes_list = []
|
109 |
|
110 |
for example in test_dataset:
|
|
|
111 |
image = example["image"]
|
112 |
annotation = example.get("annotations", "").strip()
|
|
|
|
|
113 |
has_smoke = len(annotation) > 0
|
114 |
true_labels.append(int(has_smoke))
|
115 |
-
|
|
|
116 |
if has_smoke:
|
117 |
image_true_boxes = parse_boxes(annotation)
|
118 |
true_boxes_list.append(image_true_boxes)
|
|
|
|
|
119 |
|
120 |
-
|
121 |
-
|
122 |
|
123 |
-
|
124 |
-
|
125 |
-
|
126 |
-
|
127 |
-
pred_box = [] # No prediction for this image
|
128 |
else:
|
129 |
-
|
130 |
-
|
131 |
|
|
|
132 |
pred_boxes.append(pred_box)
|
|
|
133 |
|
134 |
-
|
135 |
-
predictions.append(1 if len(results[0].boxes) > 0 else 0)
|
136 |
|
137 |
|
138 |
#--------------------------------------------------------------------------------------------
|
|
|
108 |
true_boxes_list = []
|
109 |
|
110 |
for example in test_dataset:
|
111 |
+
# Extract image and annotations
|
112 |
image = example["image"]
|
113 |
annotation = example.get("annotations", "").strip()
|
114 |
+
|
115 |
+
# Determine if ground truth smoke is present
|
116 |
has_smoke = len(annotation) > 0
|
117 |
true_labels.append(int(has_smoke))
|
118 |
+
|
119 |
+
# Parse ground truth boxes if smoke is present
|
120 |
if has_smoke:
|
121 |
image_true_boxes = parse_boxes(annotation)
|
122 |
true_boxes_list.append(image_true_boxes)
|
123 |
+
else:
|
124 |
+
true_boxes_list.append([]) # No ground truth boxes
|
125 |
|
126 |
+
# Perform YOLO inference
|
127 |
+
results = yolo_model.predict(image)
|
128 |
|
129 |
+
# Extract predicted box if predictions exist
|
130 |
+
if len(results[0].boxes):
|
131 |
+
pred_box = results[0].boxes.xywh[0].cpu().numpy().tolist() # Take the first box
|
132 |
+
predictions.append(1) # Predicted smoke
|
|
|
133 |
else:
|
134 |
+
pred_box = [] # No prediction for this image
|
135 |
+
predictions.append(0) # Predicted no smoke
|
136 |
|
137 |
+
# Append the predicted box (empty if no predictions)
|
138 |
pred_boxes.append(pred_box)
|
139 |
+
|
140 |
|
141 |
+
|
|
|
142 |
|
143 |
|
144 |
#--------------------------------------------------------------------------------------------
|