Spaces:
Sleeping
Sleeping
Update tasks/image.py
Browse files- tasks/image.py +8 -7
tasks/image.py
CHANGED
@@ -104,9 +104,10 @@ async def evaluate_image(request: ImageEvaluationRequest):
|
|
104 |
#--------------------------------------------------------------------------------------------
|
105 |
predictions = []
|
106 |
true_labels = []
|
107 |
-
pred_boxes = []
|
108 |
-
true_boxes_list = []
|
109 |
-
|
|
|
110 |
for example in test_dataset:
|
111 |
# Extract image and annotations
|
112 |
image = example["image"]
|
@@ -119,19 +120,19 @@ async def evaluate_image(request: ImageEvaluationRequest):
|
|
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 =
|
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()
|
132 |
predictions.append(1) # Predicted smoke
|
133 |
else:
|
134 |
-
pred_box = [] # No
|
135 |
predictions.append(0) # Predicted no smoke
|
136 |
|
137 |
# Append the predicted box (empty if no predictions)
|
|
|
104 |
#--------------------------------------------------------------------------------------------
|
105 |
predictions = []
|
106 |
true_labels = []
|
107 |
+
pred_boxes = [] # Flattened list of predicted boxes
|
108 |
+
true_boxes_list = [] # Flattened list of ground truth boxes
|
109 |
+
|
110 |
+
|
111 |
for example in test_dataset:
|
112 |
# Extract image and annotations
|
113 |
image = example["image"]
|
|
|
120 |
# Parse ground truth boxes if smoke is present
|
121 |
if has_smoke:
|
122 |
image_true_boxes = parse_boxes(annotation)
|
123 |
+
true_boxes_list.append(image_true_boxes if image_true_boxes else [])
|
124 |
else:
|
125 |
true_boxes_list.append([]) # No ground truth boxes
|
126 |
|
127 |
# Perform YOLO inference
|
128 |
+
results = model.predict(image)
|
129 |
|
130 |
# Extract predicted box if predictions exist
|
131 |
if len(results[0].boxes):
|
132 |
+
pred_box = results[0].boxes.xywh[0].cpu().numpy().tolist()
|
133 |
predictions.append(1) # Predicted smoke
|
134 |
else:
|
135 |
+
pred_box = [] # No predictions for this image
|
136 |
predictions.append(0) # Predicted no smoke
|
137 |
|
138 |
# Append the predicted box (empty if no predictions)
|