airctic / icevision

An Agnostic Computer Vision Framework - Pluggable to any Training Library: Fastai, Pytorch-Lightning with more to come
https://airctic.github.io/icevision/
Apache License 2.0
849 stars 150 forks source link

wrong voc data fixation request (wrong background color) #1072

Open joowon-dm-snu opened 2 years ago

joowon-dm-snu commented 2 years ago

🚀 Feature

Is your feature request related to a problem? Please describe.

voc/SegmentationObject/2010_002305's background color should be changed to black.

# icevision/icevision/core/mask.py
class VocMaskFile(MaskFile):
    def __init__(self, filepath: Union[str, Path], drop_void: bool = True):
        super().__init__(filepath=filepath)
        self.drop_void = drop_void

    def to_mask(self, h, w) -> MaskArray:
        mask_arr = np.array(Image.open(self.filepath))
        obj_ids = np.unique(mask_arr)[1:] # ->  np.unique(mask_arr) = [1, 255] then obj_ids 
        masks = mask_arr == obj_ids[:, None, None]

        if self.drop_void:
            masks = masks[:-1, ...]

        return MaskArray(masks)

white background cause error because...

Describe the solution you'd like A clear and concise description of what you want to happen.

class VocMaskFile(MaskFile):
    ...
    def to_mask(self, h, w) -> MaskArray:
        mask_arr = np.array(Image.open(self.filepath))
        unique_ids = np.unique(mask_arr)
        obj_ids = unique_ids[1:] if unique_ids[0] == 0 else unique_ids
        masks = mask_arr == obj_ids[:, None, None]
        ...

Describe alternatives you've considered A clear and concise description of any alternative solutions or features you've considered.

Additional context Add any other context or screenshots about the feature request here.

FraPochetti commented 2 years ago

Thanks for opening this issue! Do you want to open a quick PR about this one? It looks an overlook on our side and a quick fix with your solution

joowon-dm-snu commented 2 years ago

I can open PR this weekend. I'll open PR if its not late for you :) (same for #1073)

FraPochetti commented 2 years ago

totally fine! thanks a lot!