Skip to content

Convert "Visualization utilities" notebook into a sphinx-gallery example #3774

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

Merged
merged 18 commits into from
May 11, 2021

Conversation

NicolasHug
Copy link
Member

@NicolasHug NicolasHug commented May 5, 2021

This PR converts https://github.com/pytorch/vision/blob/master/examples/python/visualization_utils.ipynb into a sphinx-gallery example.

I modified it a bit to keep it short and to the point. I also chose not to showcase make_grid because I don't see a compelling use-case for it: users can just create matplotlib grid themselves, the mpl API has gotten a lot better in the last few years. Also it's impossible to plot images with different dimensions wit hit. (No strong opinion, feel free to disagree, I can put it back).

Eventually I think we'll want to remove the original notebook but I'm keeping it there for now.

Image used is https://www.pexels.com/photo/smiling-women-and-men-sitting-on-green-grass-1231230/

CC @oke-aditya as I think you wrote the original notebook?

@oke-aditya
Copy link
Contributor

oke-aditya commented May 5, 2021

Yes @NicolasHug I had written the notebook 😄

Linked with #3688

I think make_grid is quite old but still seems that people use it, so l think we can keep it

People often ask about this in dicusssion forums stackoveflow

And even in some codebases

So for legacy purpose. I think we can keep it.

Edit:

Here is the page
Where docs are built.

I think this is slightly intrusive. Can we set progress=False ? To avoid this

image

Copy link
Contributor

@oke-aditya oke-aditya left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Few thoughts from my side @NicolasHug 😄

Btw torchvision gallery is awesome way to add documentation.

Copy link
Member

@fmassa fmassa left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks great, thanks a ton!

I have a few comments (which can be addressed in a follow-up PR), let me know what you think

show(result)

#####################################
# We can adjust alpha to show the masks with a different transparency level:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think another thing which would be good to illustrate in the example is how to get the output of Mask R-CNN to be plotted with draw_segmentation_masks. People have asked it in the past and I think would be a good thing to showcase as well, as the output format is slightly different

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm getting poor results with maskrcnn_resnet50_fpn, is this expected?
image

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Chatted offline with Nicolas, this is current an issue / limitation of the draw_segmentation_masks which we will be looking into fixing soon

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes. There are limitations 🤕 IIRC the limitation was because Mask RCNN returns a boolean tensor of masks which isn't handled by the utility.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure, no worries, thanks for all your work and contributions @oke-aditya !

model = fasterrcnn_resnet50_fpn(pretrained=True, progress=False)
model = model.eval()

outputs = model(racoon.unsqueeze(0))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we use an image which contains categories present in COCO, like dog or people? The current predictions seems a bit arbitrary.

Also, I think it would be good to showcase how to add labels (containing for example the class name and score).


model = fcn_resnet50(pretrained=True, progress=False)
model = model.eval()
output = model(people.unsqueeze(0))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is not fully correct I believe, as we need to normalize with the imagenet mean / std, see

T.Normalize(mean=mean, std=std),
.

The only model that doesn't require this is Faster-RCNN / Mask-RCNN, but classification and segmentation models require it

Copy link
Member Author

@NicolasHug NicolasHug May 10, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks for the note @fmassa , does this also apply to the boxes on the racoon (which I'll change) above?

Oh they use Faster-RCNN so no, sorry ^^

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The boxes for the racoon uses Faster R-CNN, which only requires the image to be in 0-1, so it should be fine.

output = model(people.unsqueeze(0))
masks = output['out'].squeeze(0)

people_int = T.ConvertImageDtype(dtype=torch.uint8)(people)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In general, I would maybe recommend users using the functional API in situations like this, so something like

people_int = convert_image_dtype(people, dtype=torch.uint8)

@NicolasHug
Copy link
Member Author

Thanks for the reviews! I'll add instructions for the Mask-RCNN model in a follow up PR

facebook-github-bot pushed a commit that referenced this pull request May 19, 2021
…lery example (#3774)

Reviewed By: cpuhrsch

Differential Revision: D28538756

fbshipit-source-id: 9903ad98e78f7efb4db8dc0a0b90ce65173d0963
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants