masakljun commited on
Commit
6f2771b
·
1 Parent(s): a6dcdbd

change segm to coco stuff

Browse files
Files changed (1) hide show
  1. app.py +8 -6
app.py CHANGED
@@ -154,7 +154,8 @@ def run_segmentation(model, image_input, original_image):
154
  mask_np = mask_tensor.cpu().numpy().astype(np.uint8)
155
  mask_np = cv2.resize(mask_np, original_image.size, interpolation=cv2.INTER_NEAREST)
156
 
157
- current_classes = COCO_STUFF_CLASSES
 
158
 
159
  h, w = mask_np.shape
160
  colored_mask = np.zeros((h, w, 3), dtype=np.uint8)
@@ -164,9 +165,9 @@ def run_segmentation(model, image_input, original_image):
164
  labels_to_draw = []
165
 
166
  for cls_id in unique_classes:
167
- # 0 is usually background/unlabeled in this list
168
- if cls_id == 0: continue
169
- # Safety check for range
170
  if cls_id < 0 or cls_id >= len(current_classes): continue
171
 
172
  class_name = current_classes[cls_id]
@@ -190,8 +191,9 @@ def run_segmentation(model, image_input, original_image):
190
  cv2.putText(blended, text, (cx, cy), cv2.FONT_HERSHEY_SIMPLEX, 0.6, (0, 0, 0), 3, cv2.LINE_AA)
191
  cv2.putText(blended, text, (cx, cy), cv2.FONT_HERSHEY_SIMPLEX, 0.6, (255, 255, 255), 1, cv2.LINE_AA)
192
 
193
- analytics_text = f"Scene Contains (Segmentation):\n" + (", ".join(sorted(list(found_classes))) if found_classes else "None")
194
-
 
195
  return Image.fromarray(blended), analytics_text, {"classes_found": list(found_classes)}
196
 
197
  # --- GRADIO UI ---
 
154
  mask_np = mask_tensor.cpu().numpy().astype(np.uint8)
155
  mask_np = cv2.resize(mask_np, original_image.size, interpolation=cv2.INTER_NEAREST)
156
 
157
+ #current_classes = COCO_STUFF_CLASSES
158
+ current_classes = ["unlabeled"] + COCO_DETECTION_CLASSES
159
 
160
  h, w = mask_np.shape
161
  colored_mask = np.zeros((h, w, 3), dtype=np.uint8)
 
165
  labels_to_draw = []
166
 
167
  for cls_id in unique_classes:
168
+ # Skip background (Index 0)
169
+ if cls_id == 0 or cls_id == 255: continue
170
+
171
  if cls_id < 0 or cls_id >= len(current_classes): continue
172
 
173
  class_name = current_classes[cls_id]
 
191
  cv2.putText(blended, text, (cx, cy), cv2.FONT_HERSHEY_SIMPLEX, 0.6, (0, 0, 0), 3, cv2.LINE_AA)
192
  cv2.putText(blended, text, (cx, cy), cv2.FONT_HERSHEY_SIMPLEX, 0.6, (255, 255, 255), 1, cv2.LINE_AA)
193
 
194
+ analytics_text = f"Scene Contains (COCO Objects):\n" + (", ".join(sorted(list(found_classes))) if found_classes else "None")
195
+
196
+
197
  return Image.fromarray(blended), analytics_text, {"classes_found": list(found_classes)}
198
 
199
  # --- GRADIO UI ---