Tobias Cornille commited on
Commit
96dc93f
1 Parent(s): 8e21781

Fix annotations

Browse files
Files changed (1) hide show
  1. app.py +5 -6
app.py CHANGED
@@ -258,19 +258,19 @@ def sam_mask_from_points(predictor, image_array, points):
258
  return upsampled_pred
259
 
260
 
261
- def inds_to_segments_format(panoptic_inds, thing_category_ids, stuff_category_ids):
262
  panoptic_inds_array = panoptic_inds.numpy().astype(np.uint32)
263
  bitmap_file = bitmap2file(panoptic_inds_array, is_segmentation_bitmap=True)
264
  segmentation_bitmap = Image.open(bitmap_file)
265
 
266
  unique_inds = np.unique(panoptic_inds_array)
267
  stuff_annotations = [
268
- {"id": i + 1, "category_id": stuff_category_id}
269
- for i, stuff_category_id in enumerate(stuff_category_ids)
270
  if i in unique_inds
271
  ]
272
  thing_annotations = [
273
- {"id": len(stuff_category_ids) + 1 + i, "category_id": thing_category_id}
274
  for i, thing_category_id in enumerate(thing_category_ids)
275
  ]
276
  annotations = stuff_annotations + thing_annotations
@@ -391,9 +391,8 @@ def generate_panoptic_mask(
391
  panoptic_inds[thing_mask.squeeze()] = ind
392
  ind += 1
393
 
394
- stuff_category_ids = [category_name_to_id[name] for name in stuff_category_names]
395
  segmentation_bitmap, annotations = inds_to_segments_format(
396
- panoptic_inds, thing_category_ids, stuff_category_ids
397
  )
398
  annotations_json = json.dumps(annotations)
399
 
 
258
  return upsampled_pred
259
 
260
 
261
+ def inds_to_segments_format(panoptic_inds, thing_category_ids, stuff_category_names):
262
  panoptic_inds_array = panoptic_inds.numpy().astype(np.uint32)
263
  bitmap_file = bitmap2file(panoptic_inds_array, is_segmentation_bitmap=True)
264
  segmentation_bitmap = Image.open(bitmap_file)
265
 
266
  unique_inds = np.unique(panoptic_inds_array)
267
  stuff_annotations = [
268
+ {"id": i, "category_id": stuff_category_names[i - 1]}
269
+ for i in range(1, len(stuff_category_names) + 1)
270
  if i in unique_inds
271
  ]
272
  thing_annotations = [
273
+ {"id": len(stuff_category_names) + 1 + i, "category_id": thing_category_id}
274
  for i, thing_category_id in enumerate(thing_category_ids)
275
  ]
276
  annotations = stuff_annotations + thing_annotations
 
391
  panoptic_inds[thing_mask.squeeze()] = ind
392
  ind += 1
393
 
 
394
  segmentation_bitmap, annotations = inds_to_segments_format(
395
+ panoptic_inds, thing_category_ids, stuff_category_names
396
  )
397
  annotations_json = json.dumps(annotations)
398