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

chore: add expected output to the sample code. #19183

Merged
merged 4 commits into from
Sep 30, 2022
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 3 additions & 0 deletions src/transformers/models/vit_msn/modeling_vit_msn.py
Original file line number Diff line number Diff line change
Expand Up @@ -632,6 +632,8 @@ def forward(
>>> from PIL import Image
>>> import requests

>>> torch.manual_seed(2)
Copy link
Member Author

Choose a reason for hiding this comment

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

Since the classification head of ViT MSN is randomly initialized we need this for a consistent output (print(model.config.id2label[predicted_label])).


>>> url = "http://images.cocodataset.org/val2017/000000039769.jpg"
>>> image = Image.open(requests.get(url, stream=True).raw)

Expand All @@ -644,6 +646,7 @@ def forward(
>>> # model predicts one of the 1000 ImageNet classes
>>> predicted_label = logits.argmax(-1).item()
>>> print(model.config.id2label[predicted_label])
LABEL_183
Copy link
Collaborator

@ydshieh ydshieh Sep 26, 2022

Choose a reason for hiding this comment

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

Thank you @sayakpaul . Just wondering, if there is any plan to update the config on the Hub for this checkpoint, then update this value here?

Copy link
Member Author

Choose a reason for hiding this comment

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

How the config should be updated? Updated with the ImageNet-1k labels?

Copy link
Collaborator

Choose a reason for hiding this comment

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

Sorry @sayakpaul , I should ask this question internally, as it is a checkpoint from fackebook facebook/vit-msn-small.
But yes, I think it should be updated with ImageNet-1k labels.

Copy link
Member Author

Choose a reason for hiding this comment

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

Sure. When the classification head is updated with the pretrained params, I think we could revisit it.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Or maybe you would like to open a Hub PR for that checkpoint?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yeah that is what my plan is i.e., open a PR to the MSN checkpoints on Hub to update the config.

```"""
return_dict = return_dict if return_dict is not None else self.config.use_return_dict

Expand Down