File tree Expand file tree Collapse file tree 1 file changed +18
-4
lines changed
Expand file tree Collapse file tree 1 file changed +18
-4
lines changed Original file line number Diff line number Diff line change @@ -316,10 +316,24 @@ def _load_image_with_annotations(
316316 array = anns [0 ].combine_to_numpy (
317317 anns , self .class_mappings [task ], width = width , height = height
318318 )
319- if self .add_background and task == LabelType .SEGMENTATION :
320- unassigned_pixels = ~ np .any (array , axis = 0 )
321- background_idx = self .class_mappings [task ]["background" ]
322- array [background_idx , unassigned_pixels ] = 1
319+
320+ if task == LabelType .SEGMENTATION :
321+ mask_sum = np .sum (array , axis = 0 )
322+
323+ if self .add_background :
324+ unassigned_pixels = mask_sum == 0
325+ background_idx = self .class_mappings [task ]["background" ]
326+ array [background_idx , unassigned_pixels ] = 1
327+
328+ # Check if there are overlaps in the masks
329+ if np .any (mask_sum > 1 ):
330+ max_indices = np .argmax (array , axis = 0 )
331+ array .fill (0 )
332+ array [
333+ max_indices ,
334+ np .arange (array .shape [1 ])[:, None ],
335+ np .arange (array .shape [2 ]),
336+ ] = 1
323337
324338 labels [task ] = (array , anns [0 ]._label_type )
325339
You can’t perform that action at this time.
0 commit comments