Utility to draw Semantic Segmentation Masks
See original GitHub issue🚀 Feature
We recently added utility to draw bounding boxes, which works really well with detection models. #2785 #2556 It might be nice to draw segmentation masks which we obtain from instance segmentation models.
Motivation
Same as bounding box utils. It is very useful to have these. It reduces the dependence of users over other plotting libraries.
Pitch
Our API should be compatible with segmentation models, so we should probably use Tensors. I think most params remain as same as the previous util. This keeps consistency too.
@torch.no_grad()
def draw_segmentation_masks(image: torch.Tensor,
masks: torch.Tensor,
labels: Optional[List[str]] = None,
colors: Optional[List[Union[str, Tuple[int, int, int]]]] = None,
width: int = 1,
font: Optional[str] = None,
font_size: int = 10)
We might need to see a method using which we can draw with PIL.
We used draw.rectangle()
to draw a box in utils, maybe there is some functionality in PIL that can help us draw shapes.
Alternatives
Let’s discuss further, how this API would work with our models. Also, it would be nice if this works directly for instance segmentation model Mask RCNN.
Issue Analytics
- State:
- Created 3 years ago
- Reactions:1
- Comments:16 (16 by maintainers)
I too think so, if we set the background with transparency channel we might be able to project it into the image. And additionally have a fill parameter (like we did for boxes). Let me have run with this and post the outputs 😃
I had a brief thought about all points.
We can just do
new_image = image.clone()
and continue plotting innew_image
. Also, probably we should do this for bounding boxes too and avoid in-place operation there.So the new API proposal 😄