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

Class names for ImageNet-21k pre-trained models #7

Closed
issamemari opened this issue May 26, 2020 · 9 comments
Closed

Class names for ImageNet-21k pre-trained models #7

issamemari opened this issue May 26, 2020 · 9 comments

Comments

@issamemari
Copy link

Hi there! I would like to use one of the ImageNet-21k pre-trained models as is, without fine tuning. Where can I find the mapping between output indices and class names?

@lucasb-eyer
Copy link
Collaborator

Great question, we forgot to add this to the README and will add it later!

You can find the WordNet IDs of the classes here and the WordNet lemmas of the classes here. We have not actually double-checked the files yet, so if you try it out, please let us know if it looks correct!

@issamemari
Copy link
Author

issamemari commented Jul 1, 2020

Thank you for your response @lucasb-eyer. I tried the file you linked and the output seems indeed correct. Here's some code for those interested:

import numpy as np
import torch

from bit.models import ResNetV2
from torchvision import transforms
from PIL import Image
from nltk.corpus import wordnet as wn


wordnet_ids = open("/home/issa/Desktop/wordnet_ids.txt", "r").readlines()
wordnet_ids = [x.strip() for x in wordnet_ids]
wordnet_ids = [int(x[1:]) for x in wordnet_ids]

model = ResNetV2(ResNetV2.BLOCK_UNITS["r101"], width_factor=1, zero_head=False)
model.load_from(np.load("/home/issa/Desktop/BiT-M-R101x1.npz"))
model.eval()

transform_test = transforms.Compose(
    [
        transforms.Resize(224),
        transforms.ToTensor(),
        transforms.Normalize(mean=[0.5, 0.5, 0.5], std=[0.5, 0.5, 0.5]),
    ]
)

image = Image.open("/home/issa/Downloads/DSC_0611.jpg")
output = model(transform_test(image).unsqueeze(0))[0]

for index in torch.argsort(output, descending=True)[:10]:
    print(wn.synset_from_pos_and_offset('n', wordnet_ids[int(index)]))

@lucasb-eyer
Copy link
Collaborator

Great, thank you for the update and the code example!

@ZhiyuanChen
Copy link

Great question, we forgot to add this to the README and will add it later!

You can find the WordNet IDs of the classes here and the WordNet lemmas of the classes here. We have not actually double-checked the files yet, so if you try it out, please let us know if it looks correct!

Hi,

I checked the file provided, but it seems it does not contain all label in imagenet.
For example, "n11738203", "European pasqueflower, Pulsatilla vulgaris, Anemone plusatilla" is not in the list

@peiyingxin
Copy link

Great question, we forgot to add this to the README and will add it later!
You can find the WordNet IDs of the classes here and the WordNet lemmas of the classes here. We have not actually double-checked the files yet, so if you try it out, please let us know if it looks correct!

Hi,

I checked the file provided, but it seems it does not contain all label in imagenet. For example, "n11738203", "European pasqueflower, Pulsatilla vulgaris, Anemone plusatilla" is not in the list

Hi,
have you solve this problem?

@mosjel
Copy link

mosjel commented Apr 17, 2023

Hi!
Can you please just put the text file with 21841 classes and lines. Current file has 21843 lines instead!

@mosjel
Copy link

mosjel commented Apr 20, 2023

Please remove the line 9206 and 15028 in both lemma and id files. line 9206 and line 15028 must be omitted in both files. Then you can use them comfortably. If you do not do that after class 9204 you will receive the wrong answer.

@Taby383
Copy link

Taby383 commented Dec 14, 2024

Is there also an updated version of the classes from the dataset available?

@mosjel
Copy link

mosjel commented Dec 14, 2024

You can download the correct ImageNet-21k classes file in my github:https://github.com/mosjel/ImageNet_21k_Original_OK
Goodluck.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants