Skip to content
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

Added label names for top 10 confidence categories #175

Merged
merged 13 commits into from
Dec 22, 2020

Conversation

Tylersuard
Copy link
Contributor

Code will now print out label index, label name, and confidence score for input images.

@netlify
Copy link

netlify bot commented Dec 17, 2020

Deploy preview for pytorch-hub-preview ready!

Built with commit a6fc887

https://deploy-preview-175--pytorch-hub-preview.netlify.app

@datumbox
Copy link
Contributor

datumbox commented Dec 18, 2020

Thanks for the contribution.

Ideally we should not need other external libraries to do this. Could you try something like that:

  1. Keep all ImageNet categories in a list. You can download it the way you do and split on new lines.
  2. Get from the predictions the top 5 category ids and their probabilities using torch.topk()
  3. Print the category names and scores for the top 5 predictions.

@pmeier / @fmassa: Do we currently have any plans to put the ImageNet categories in TorchVision so that we can avoid the ugly/repetitive step 1?

@Tylersuard
Copy link
Contributor Author

Thank you Vasilis. I just made the requested corrections, let me know if that is what you are looking for.


```
#Download ImageNet labels
!wget https://raw.githubusercontent.com/Tylersuard/hub/master/imagenet_classes.txt
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
!wget https://raw.githubusercontent.com/Tylersuard/hub/master/imagenet_classes.txt
!wget https://raw.githubusercontent.com/pytorch/hub/master/imagenet_classes.txt

@datumbox
Copy link
Contributor

It's looking good Tyler, thanks a lot for the changes. I added one last comment to update the link of the file to point to pytorch's repo.

I'll wait for @pmeier / @fmass 's reply (might take a bit because people started leaving on holidays), to see if there are plans to add the categories directly to TorchVision and avoid downloading them.

One last non-blocking comment:
image

I assume you left the ID intentionally in case the user intends to link it back to the ImageNet category? We could optionally format a bit the output to indicate clearly which part is the Id, which is the category and which is the probability but I'll leave it to you how you want to have it.

@pmeier
Copy link
Contributor

pmeier commented Dec 20, 2020

@datumbox

Do we currently have any plans to put the ImageNet categories in TorchVision so that we can avoid the ugly/repetitive step 1?

I've already asked about this quite some time ago in pytorch/vision#1647, but as it stands @fmassa was against it for licensing reasons. If this has changed, I'm happy to pick it up and adapt the implementation of ImageNet in torchvision.

@datumbox
Copy link
Contributor

@pmeier Thanks for the reply. I don't know if providing a list with the ImageNet categories has the same issues as redistributing the meta.bin file. As far as I can see, other similar libraries from Facebook, Google, Microsoft and other open-source projects (1, 2, 3, 4) include the list of categories in their repos.

@Tylersuard Let me check if there is a blocker on adding the list in the notebook repo and I'll get back to you.

@pmeier
Copy link
Contributor

pmeier commented Dec 21, 2020

I don't know if providing a list with the ImageNet categories has the same issues as redistributing the meta.bin file

True, but goes in the same direction. Lets wait for @fmassa s judgement. I'm happy to add them if we want that.

@Tylersuard
Copy link
Contributor Author

Vasilis, thank you. It does look better without the category number. I switched back to using the CSV and the index disappears. I will update the code later today.

@datumbox
Copy link
Contributor

@pmeier I just checked internally and we are OK adding the list of categories. I think we should start by adding these here and then discuss options for landing them on TorchVision. What do you think?

@Tylersuard Thanks Tyler. Do you mind if we completely remove the numbers? Since those ids are not related to the ones that ImageNet uses, there is very little reason to keep them. So if you remove them completely from the .txt file we should be OK.

@Tylersuard
Copy link
Contributor Author

Ok, I just removed them from the text file. Please note the download link must have the .raw in the URL or it won't work.

- Remove unnecessary spaces
- Coding styles
- Simplify code
@datumbox
Copy link
Contributor

LGTM @Tylersuard. Thanks for the PR and your patience.

To avoid further back and forth and unblock the merge, I pushed directly to your branch a couple of minor changes needed to ensure that the coding style guidelines of PyTorch are met. Please check and let me know if you are OK with them, so that I can merge.

Copy link
Contributor Author

@Tylersuard Tylersuard left a comment

Choose a reason for hiding this comment

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

Looks great! Much cleaner than my code.

@datumbox datumbox merged commit e6d1997 into pytorch:master Dec 22, 2020
@Tylersuard
Copy link
Contributor Author

Tylersuard commented Dec 22, 2020 via email

@datumbox
Copy link
Contributor

@Tylersuard Yes, please that would be great!

Send a single PR where you apply the same changes that happened on file pytorch_vision_resnext.md to the remaining pre-trained models of TorchVision. To keep things simple, please do not update notebooks of other models that are not part of TorchVision, as this might require additional discussions.

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