在炬管的1000维输出张量中获取特定索引的ImageNet标签 [英] Get ImageNet label for a specific index in the 1000-dimensional output tensor in torch

查看:207
本文介绍了在炬管的1000维输出张量中获取特定索引的ImageNet标签的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我具有 ResNet模型的Facebook实现带有猫的图片.这是具有分类概率的1000维张量.使用 torch.topk 我可以在输出张量中获得前5个概率及其索引.现在,我想查看那些最可能出现的索引的人类可读标签.

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.

我在网上搜索了标签列表(显然也称为sysnets),却发现了这一点: http://image-net.org/challenges/LSVRC/2015/browse-synsets

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

我使用行号作为标签索引将这些标签放在文件中,并且当我使用两个不同的cat图像运行网络时,我会以"screwdriver"作为两者的最高猜测.如果我按字母顺序对标签文件进行排序,则两者都会得到电影".

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.

这似乎是将索引转换为标签的问题,对吗? 所以...问题是: 如何正确将网络输出张量中的索引映射到Imagenet标签?

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?

推荐答案

找到了此教程由Dato 在ImageNet上培训ConvNets,最后它包含正确的映射.在此处报告以作记录:

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'
}

此处有完整的映射: https://gist.github.com/maraoz/388eddec39d60c6d52d4

这篇关于在炬管的1000维输出张量中获取特定索引的ImageNet标签的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆