tom-b974 commited on
Commit
1e16d37
·
verified ·
1 Parent(s): 3c42d95

Update tasks/image.py

Browse files
Files changed (1) hide show
  1. tasks/image.py +27 -11
tasks/image.py CHANGED
@@ -112,32 +112,48 @@ async def evaluate_image(request: ImageEvaluationRequest):
112
  # Extract image and annotations
113
  image = example["image"]
114
  annotation = example.get("annotations", "").strip()
115
-
116
  # Determine if ground truth smoke is present
117
  has_smoke = len(annotation) > 0
118
- true_labels.append(int(has_smoke))
119
 
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)
139
- pred_boxes.append(pred_box)
140
-
 
 
 
 
 
 
 
 
 
 
 
 
141
 
142
 
143
 
 
112
  # Extract image and annotations
113
  image = example["image"]
114
  annotation = example.get("annotations", "").strip()
115
+
116
  # Determine if ground truth smoke is present
117
  has_smoke = len(annotation) > 0
118
+ true_labels.append(1 if has_smoke else 0)
119
 
120
  # Parse ground truth boxes if smoke is present
121
  if has_smoke:
122
  image_true_boxes = parse_boxes(annotation)
123
+ if image_true_boxes:
124
+ true_boxes_list.append(image_true_boxes)
125
+ else:
126
+ true_boxes_list.append([]) # Add empty list if parsing fails
127
  else:
128
+ true_boxes_list.append([]) # Add empty list for no ground truth smoke
129
 
130
  # Perform YOLO inference
131
  results = model.predict(image)
132
+
133
  # Extract predicted box if predictions exist
134
  if len(results[0].boxes):
135
+ pred_box = results[0].boxes.xywhn[0].cpu().numpy().tolist()
136
  predictions.append(1) # Predicted smoke
137
+ pred_boxes.append(pred_box)
138
  else:
139
+ predictions.append(0) # No smoke predicted
140
+ pred_boxes.append([]) # Add empty list if no prediction
141
 
142
+
143
+ # Filter out entries with empty boxes
144
+ filtered_true_boxes_list = []
145
+ filtered_pred_boxes = []
146
+
147
+
148
+ for true_boxes, pred_boxes_entry in zip(true_boxes_list, pred_boxes):
149
+ if true_boxes and pred_boxes_entry: # Keep only if neither is empty
150
+ filtered_true_boxes_list.append(true_boxes)
151
+ filtered_pred_boxes.append(pred_boxes_entry)
152
+
153
+
154
+ # Replace the original lists with the filtered ones
155
+ true_boxes_list = filtered_true_boxes_list
156
+ pred_boxes = filtered_pred_boxes
157
 
158
 
159