Mapping between labels and class names for pretrained networks

username: dangraf
cooked: <p>Hello.<br>
How do I find the mapping between class names and labels?</p>
<p>I’m using a pretrained network (mobilnet v2) and can get a prediction using pretrained weights using a random image. I then get call argmax of the output to get the label. But I would like to know the name of the label, eg is 654 a plane or a car or something else?</p>
<p>I’ve looked at this post but it does not answer my question</p><aside class="quote" data-post="1" data-topic="470">
  <div class="title">
    <div class="quote-controls"></div>
    <img loading="lazy" alt="" width="24" height="24" src="https://discuss.pytorch.org/user_avatar/discuss.pytorch.org/avijit_dasgupta/48/2541_2.png" class="avatar">
    <a href="https://discuss.pytorch.org/t/how-to-get-the-class-names-to-class-label-mapping/470">How to get the class names to class label mapping</a> 
  </div>
  <blockquote>
    I am using ResNet-18 for classification purpose. I have used dataloader to load the data. But how get the label to class name mapping? Does it load in alphabetical order?
  </blockquote>
</aside>

<p>/D</p>

username: ptrblck
cooked: <p>The mapping between class indices and class names is part of the dataset definition, not the model.<br>
Since mobilenet was pretrained on ImageNet, you could search for the class index to name mapping and will find some sources, e.g. <a href="https://gist.github.com/yrevar/942d3a0ac09ec9e5eb3a">here</a>.</p>

username: dangraf
cooked: <p>Thanks, but how did you get that information?</p>
<p>When I look at the code at github for mobilenet v2<br>
<aside class="onebox whitelistedgeneric">
  <header class="source">
      <img src="https://github.githubassets.com/favicon.ico" class="site-icon" width="16" height="16">
      <a href="https://github.com/tensorflow/models/tree/master/research/slim/nets/mobilenet" target="_blank" rel="nofollow noopener">GitHub</a>
  </header>
  <article class="onebox-body">
    <img src="https://avatars2.githubusercontent.com/u/15658638?s=400&amp;v=4" class="thumbnail onebox-avatar" width="60" height="60">

<h3><a href="https://github.com/tensorflow/models/tree/master/research/slim/nets/mobilenet" target="_blank" rel="nofollow noopener">tensorflow/models</a></h3>

<p>Models and examples built with TensorFlow. Contribute to tensorflow/models development by creating an account on GitHub.</p>


  </article>
  <div class="onebox-metadata">
    
    
  </div>
  <div style="clear: both"></div>
</aside>
<br>
I can’t find the label mapping or which dataset they are using. They are reffering to “imagenet checkpoints”.</p>
<p>One could assume they are using the same data set as in V1 where they are using the ILSVRC-2012-CLS, since they are comparing the accuracy between the nets. But there exist an imagenet2 also right?</p>
<p>Is the exact label mapping defined for all datasets? Or is it possible that one could eg mix the order between the labels and class-names when training the net?</p>
<p>Sorry for these fundamental questions, maybe it’s obvious for you guys…<br>
This seems to be many assumptions from my side and I’m searching for a crystal-clear solution.<br>
I will most certainly step into other datasets and then it’s good to know how to find this type of information.</p>
<p>thanks again for the link.</p>
<p>/Daniel</p>

username: ptrblck
cooked: <p>I’m not sure which dataset Tensorflow uses, but the <code>torchvision</code> models were trained on ImageNet-12 according to <a href="https://discuss.pytorch.org/t/using-vision-models-with-the-cifar-dataset/7278/2">this post</a>.</p>