【问题标题】:ImageNet index to Wordnet 3.0 synsetsWordnet 3.0 同义词集的 ImageNet 索引
【发布时间】:2017-08-22 20:27:46
【问题描述】:

在 Caffe 中使用 ImageNet Resnet-50,预测会给出一个 1000 维的向量。有没有一种简单的方法可以将此向量的索引转换为 Wordnet 3.0 同义词集标识符?例如,415: 'bakery, bakeshop, bakehouse' 是“n02776631”?

我注意到类似的问题 Get ImageNet label for a specific index in the 1000-dimensional output tensor in torch 被问及与索引关联的人类可读标签,并且答案指向此 URL 中可用的索引到标签映射:https://gist.github.com/maraoz/388eddec39d60c6d52d4

从人类可读的标签中,我想可以通过此页面上的标签到同义词集的映射找到 Wordnet 同义词集标识符:http://image-net.org/challenges/LSVRC/2015/browse-synsets,但我想知道这是否已经完成?

【问题讨论】:

    标签: wordnet imagenet


    【解决方案1】:

    使用来自https://gist.github.com/maraoz/388eddec39d60c6d52d4http://image-net.org/challenges/LSVRC/2015/browse-synsets 的数据,映射似乎很简单:

    {0: {'id': '01440764-n',
         'label': 'tench, Tinca tinca',
         'uri': 'http://wordnet-rdf.princeton.edu/wn30/01440764-n'},
     1: {'id': '01443537-n',
         'label': 'goldfish, Carassius auratus',
         'uri': 'http://wordnet-rdf.princeton.edu/wn30/01443537-n'},
     2: {'id': '01484850-n',
         'label': 'great white shark, white shark, man-eater, man-eating shark, Carcharodon carcharias',
        'uri': 'http://wordnet-rdf.princeton.edu/wn30/01484850-n'},
     ...
    

    查看https://gist.github.com/fnielsen/4a5c94eaa6dcdf29b7a62d886f540372查看完整文件。

    我没有彻底检查这个映射是否真的正确。

    这个映射是用:

    import ast
    from lxml import html
    import requests
    from pprint import pprint
    
    url_index = ('https://gist.githubusercontent.com/maraoz/'
                 '388eddec39d60c6d52d4/raw/'
                 '791d5b370e4e31a4e9058d49005be4888ca98472/gistfile1.txt')
    url_synsets = "http://image-net.org/challenges/LSVRC/2014/browse-synsets"
    
    index_to_label = ast.literal_eval(requests.get(url_index).content)
    elements = html.fromstring(requests.get(url_synsets).content).xpath('//a')
    
    label_to_synset = {}
    for element in elements:
        href = element.attrib['href']
        if href.startswith('http://imagenet.stanford.edu/synset?wnid='):
            label_to_synset[element.text] = href[42:]
    
    index_to_synset = {
        k: {
            'id': label_to_synset[v] + '-n',
            'label': v,
            'uri': "http://wordnet-rdf.princeton.edu/wn30/{}-n".format(
                label_to_synset[v])
        }
        for k, v in index_to_label.items()}
    
    
    pprint(index_to_synset)
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2017-04-18
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多