Closed sparshgarg23 closed 1 year ago
I feel the above approach may not be suitable for generalization purposes.As such ,is there a way to convert the mask to polygon and then extract the polygon for specific class. I know that in detecron2 we can convert the mask to polygon as shown below https://github.com/facebookresearch/detectron2/issues/2245 Note that issue 2245 only deals with extracting polygons for instance segmentation and isn't applicable to panoptic /semantic segmentation Any help will be appreciated. thanks
Hi @sparshgarg23, to extract the binary mask corresponding to a specific category. you can directly perform an if equals
operation on the semantic segmentation result:
https://github.com/SHI-Labs/OneFormer/blob/4962ef6a96ffb76a76771bfa3e8b3587f209752b/oneformer/oneformer_model.py#L376
specific_categiry_mask = (sem_seg == category_id).float()
If you are working with panoptic results, you can loop through the segments_info
to collect the id
for all masks belonging to a category_id
and obtain the specific masks from the panoptic_map
output.
https://github.com/SHI-Labs/OneFormer/blob/4962ef6a96ffb76a76771bfa3e8b3587f209752b/oneformer/oneformer_model.py#L434
For instance segmentation, you can loop through results.pred_classes
and collect masks from corresponding indices (ones that match the target category_id
) in result.masks
.
https://github.com/SHI-Labs/OneFormer/blob/4962ef6a96ffb76a76771bfa3e8b3587f209752b/oneformer/oneformer_model.py#L486
I had come across a previous example for background removal that relied on usage of semantic segmentation.However instead of removing the background,I am currently more focused on removing the pixels corresponding to a specific class.Plus,I am interested in using the concept of panoptic to approach this problem. For example in below image
Let's say we want to white out all pixels belonging to the class grass. So how would I go about it, i am thinking i select the mask corresponding to the grass label and then subtract it from the output result's mask.
As the ADE dataset consists of a larger vocabulary,that was my first choice and I was glad to discover your work on panoptic trained on ADE. Would appreciate it if you can give me some tips on how to extract the mask corresponding to certain label . the work on background removal uses the foll code.
the above code performs segmentation,and then uses its mask to replace the foreground's background with white color.I would like to do the same thing,but instead of setting entire background to white I am interested in setting the mask belonging to specific category to white.