SHI-Labs / OneFormer

OneFormer: One Transformer to Rule Universal Image Segmentation, arxiv 2022 / CVPR 2023
https://praeclarumjj3.github.io/oneformer
MIT License
1.46k stars 129 forks source link

To get a segmentation label map from the model output #38

Closed rose-jinyang closed 1 year ago

rose-jinyang commented 1 year ago

Hello How are you? Thanks for contributing to this project. Could u guide me to get a segmentation label map from the model output?

praeclarumjj3 commented 1 year ago

Hi @rose-jinyang, thanks for your interest in our work.

You can run the demo script to visualize the segmentation label map from the model output. You may add an output_folder argument while initializing an evaluator object to specify the path where the segmentation label maps for the model's predictions should be saved.

https://github.com/SHI-Labs/OneFormer/blob/761189909f392a110a4ead574d85ed3a17fbc8a7/train_net.py#L358

becomes:

 evaluator = cls.build_evaluator(cfg, dataset_name, output_folder=<PATH-TO-YOUR-FOLDER>)
rose-jinyang commented 1 year ago

Thanks for your reply. I want to get the segmentation label map as numpy array on python code.

praeclarumjj3 commented 1 year ago

Could you specify the segmentation task: semantic, instance, or panoptic?

rose-jinyang commented 1 year ago

I want to get instance segmentation label maps.

rose-jinyang commented 1 year ago

Or I want to get box, score, class_id and binary mask for each instance object.

praeclarumjj3 commented 1 year ago

Thanks for the clarification. You can obtain tensors (convert into np.array) for those from the instance predictions directly.

instances = predictions["instances"]
boxes = instances.pred_boxes
scores = instances.scores
classes = instances.pred_classes
masks = instances.pred_masks

Note that to obtain boxes, you must set DETECTION_ON as True in the config. https://github.com/SHI-Labs/OneFormer/blob/761189909f392a110a4ead574d85ed3a17fbc8a7/configs/coco/oneformer_R50_bs16_50ep.yaml#L54

rose-jinyang commented 1 year ago

Thanks

rose-jinyang commented 1 year ago

Hello I have more questions. image I checked the detectorn2's output format in their help. Here what is the N? Does the "pred_masks" mean a binary mask for each instance object in the rectangle regions by the "pred_boxes"?

praeclarumjj3 commented 1 year ago

Hi @rose-jinyang, the N denotes the number of segmented regions (or object masks) in the image.

Does the "pred_masks" mean a binary mask for each instance object in the rectangle regions by the "pred_boxes"?

Yes, you are correct.

praeclarumjj3 commented 1 year ago

Closing this issue. Feel free to re-open if you have any more questions.

rose-jinyang commented 1 year ago

Hi Thanks for your kind help. I want to get one segmentation map containing all the class labels rather than binary mask for each instance. How can I get it?