-
Notifications
You must be signed in to change notification settings - Fork 7.1k
Utility to draw Semantic Segmentation Masks #3272
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
@oke-aditya +1 on the proposal. I like the fact of providing a similar API as for |
I would also suggest adding an example notebook/script / tutorial where we can show how both the utils work. |
Perfect! I think using PIL should be fine given that's how the bounding box version works. Looking forward to it. |
Hey @datumbox. For Instance segmentation model we can do something like #3280. I'm looking into semantic segmentation models, I guess then the predicted label is I think colors remain the same. I think we can use ImageDraw.point to draw each point? The width makes little sense here since if we will be drawing each pixel on image? |
Agreed.
Yes they should remain the same. We currently support both tuples of RGB ints and strings. See an example we have on the tests: Line 88 in a0e5bbe
We should use
Worth investigating a couple of options and measure them. If you send a PR and tag me, I'm happy to share feedback.
Yes, I think you are right. |
Great ! I will send a PR let's investigate few options 😀 This is what I have in my mind. Taken from FCN paper |
@oke-aditya Awesome, looking forward to it. I'm actually doing work around segmentation, so I'm definitely going to use your prototypes to validate the models. :) |
I did have a go at this 😃 Here is code to reproduce a simple mask using
|
Some points, I'm unclear about
|
@oke-aditya Thanks for providing the prototype implementation. This is really helpful because it raises lots of interesting questions about the proposed API.
From the above, I understand that you create a new image after making the prediction and before start drawing. Do you intentionally propose to create a new picture that contains only the masks OR you plan to apply the mask on top of the original image (with transparency) as we do on the bounding box util? Concerning your questions, here are some thoughts:
@fmassa if you have any thoughts on the above, pitch in. |
I think Maybe people want to have a look at the predictions, and do further post-processing to the image, then redraw the predictions. I guess we should just do I am not sure mask on the original image with transparency will be nice here. Maybe that is better for Instance segmentation than semantic?
This is quite fast and good, but we lose control over colors. which can be easily supplied by a list or tuple. Taken from Colab Notebook for instance segmentation. This is share to PyTorch hub, |
A couple clarifications and additional notes on my side:
I agree we should not modify the image in place. My question was whether you planned to put transparency on top of the original image or if you wanted to create a new non-transparent image using only the classifications. If you intend to do the latter, then providing the image tensor is unnecessary because we only use the output predictions.
The example you provide follows the second approach (no transparency) and uses Palette image types. Both PIL and TorchVision support palettes and as you indicate they allow you to build segmentation masks even for massive images. Perhaps to avoid losing control over colours, we could allow the user to either define a complete list of colours for all classes. If they don't provide such a complete list, we can use a similar colour palette approach as your snippet.
As per your example snippet, using palettes avoids calling PIL's draw.point method. Instead all the processing is done in parallel using PyTorch tensors which is very fast. Thoughts? |
I had a brief thought about all points.
We can just do
So the new API proposal 😄
|
Looks very reasonable proposal to me. Thanks for looking into it. :) One last question. What do you think will happen if you take the image produced by the masks using the process you describe above and do a weighted linear combination with the original image? I think if the background of the palette is set to be transparent instead of black, this operation might project the colour of the masks into the original image. Thoughts? |
I too think so, if we set the background with transparency channel we might be able to project it into the image. |
Hi, @datumbox I opened PR #3330 since we are quite ok with the API now. Here is the output. I think I'm missing something really small, a transparent background instead of black.
I still think somehow the colors are bit spoilt maybe due to black background? Feel free to comment on PR. I think I'm missing just a small trick to make masks transparent over image 😄 |
🚀 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.
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.
The text was updated successfully, but these errors were encountered: