Skip to content

Commit

Permalink
Fix instance segmentation on GPU and CPU
Browse files Browse the repository at this point in the history
  • Loading branch information
constantinpape committed Oct 30, 2023
1 parent 411d48f commit b8fcaa5
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion micro_sam/instance_segmentation.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,13 +70,16 @@ def mask_data_to_segmentation(
masks = sorted(masks, key=(lambda x: x["area"]), reverse=True)
segmentation = np.zeros(shape[:2], dtype="uint32")

def require_numpy(mask):
return mask.cpu().numpy() if torch.is_tensor(mask) else mask

seg_id = 1
for mask in masks:
if mask["area"] < min_object_size:
continue

this_seg_id = mask.get("seg_id", seg_id)
segmentation[mask["segmentation"].cpu()] = this_seg_id
segmentation[require_numpy(mask["segmentation"])] = this_seg_id

seg_id = this_seg_id + 1

Expand Down

0 comments on commit b8fcaa5

Please sign in to comment.