I have the output Tensor of a forward pass for a Facebook implementation of the ResNet model with a cat image. That is a 1000-dimensional Tensor with the classification probabilities. Using torch.topk I can obtain the top-5 probabilities and their indexes in the output tensor. Now I want to see the human-readable labels for those most-probable indexes.
I searched online for the list of labels (which apparently are also called sysnets) and only found this:
http://image-net.org/challenges/LSVRC/2015/browse-synsets
I put those labels in a file using line numbers as the label index and when I run the network with two different cat images, I get "screwdriver" as the top guess for both. If I sort the label file alphabetically, I get "cinema" for both.
This appears to be a problem with converting index to label, right?
So...the question is:
How can I properly map index in network output tensor to Imagenet label?
Found this tutorial on training ConvNets on ImageNet by Dato and at the end it contains the correct mapping. Reporting it here for the record:
{
0: 'tench, Tinca tinca',
1: 'goldfish, Carassius auratus',
2: 'great white shark, white shark, man-eater, man-eating shark, Carcharodon carcharias',
3: 'tiger shark, Galeocerdo cuvieri',
4: 'hammerhead, hammerhead shark',
5: 'electric ray, crampfish, numbfish, torpedo',
6: 'stingray',
7: 'cock',
8: 'hen',
9: 'ostrich, Struthio camelus',
10: 'brambling, Fringilla montifringilla',
... [truncated for space]
990: 'buckeye, horse chestnut, conker',
991: 'coral fungus',
992: 'agaric',
993: 'gyromitra',
994: 'stinkhorn, carrion fungus',
995: 'earthstar',
996: 'hen-of-the-woods, hen of the woods, Polyporus frondosus, Grifola frondosa',
997: 'bolete',
998: 'ear, spike, capitulum',
999: 'toilet tissue, toilet paper, bathroom tissue'
}
Full mapping here: https://gist.github.com/maraoz/388eddec39d60c6d52d4