Transfer learning from the subset of the ImageNet classes

Myailab: <p>Hi</p>
<p>Is it possible to get a pretrained model that is based on the selective classes of the ImageNet?</p>
<p>I have computed the similarity between each Imagenet class and my dataset using <a href="https://github.com/richardaecn/cvpr18-inaturalist-transfer/blob/master/DomainSimilarityDemo.ipynb" class="inline-onebox" rel="noopener nofollow ugc">cvpr18-inaturalist-transfer/DomainSimilarityDemo.ipynb at master · richardaecn/cvpr18-inaturalist-transfer · GitHub</a></p>
<p>and got the subset of Imagenet Classes which are most similar to my dataset. Now I want to use the pretrained features only from these most similar classes.</p>
<p>Earlier, I was using the pretrained model as follows:</p>
<pre><code class="lang-auto">def get_resnet34(num_classes=20, **_):
    model_name = 'resnet34'
    model = pretrainedmodels.__dict__[model_name](num_classes=1000, pretrained='imagenet')
    conv1 = model.conv1
</code></pre>
<p>May I know how can i get the pretrained features from the selective classes of Imagenet.<br>
I don’t have any clue to pursue this further.<br>
Looking for help.</p>
<p>Thank you</p>

gphilip: <p>Perhaps you can take the output (which is a list of probabilities) of resnet34, set the probabilities corresponding to the non-selected classes to zeroes, and normalize the remaining probabilities (scale them up by a uniform factor so that they again add up to 1)?</p>
<p>This seems to be the simplest interpretation of “drop some classes from resnet34”. Perhaps this will work for your purpose?</p>

Myailab: <p>Thanks for the suggestion.</p>
<p>Actually, output of this resnet model is 20 classes from my data set. I want to drop few classes from 1000 classes of ImageNet.<br>
Do  you think if that is possible.</p>
<p>Thanks</p>

gphilip: <aside class="quote no-group" data-username="Myailab" data-post="3" data-topic="128932">
<div class="title">
<div class="quote-controls"></div>
<img loading="lazy" alt="" width="24" height="24" src="https://discuss.pytorch.org/letter_avatar_proxy/v4/letter/m/9de053/48.png" class="avatar"> Myailab:</div>
<blockquote>
<p>Actually, output of this resnet model is 20 classes from my data set. I want to drop few classes from 1000 classes of ImageNet.</p>
</blockquote>
</aside>
<p>I am not sure I understand. If the output of this resnet models already matches your data set, why do you want to drop some classes?</p>

Myailab: <p>My data is highly imbalanced, and I am using pretrained ResNet model to get the logits.<br>
In hope of getting better accuracy, i want to use only those classes of ImageNet which are similar to the classes of my dataset.<br>
There is a paper on this approach : ‘Large Scale Fine-Grained Categorization and Domain-Specific Transfer Learning’.<br>
But unfortunately code is not complete</p>

gphilip: <p>Did you try my first suggestion? To me that looks like a reasonable first thing to try.</p>

Myailab: <aside class="quote no-group" data-username="gphilip" data-post="2" data-topic="128932">
<div class="title">
<div class="quote-controls"></div>
<img loading="lazy" alt="" width="24" height="24" src="https://discuss.pytorch.org/letter_avatar_proxy/v4/letter/g/858c86/48.png" class="avatar"> gphilip:</div>
<blockquote>
<p>output (which is a list of probabilities) of resnet34</p>
</blockquote>
</aside>
<p>Thanks for the reply.<br>
Sorry, i am not sure if i understood that correctly. Isn’t that  the ‘output (which is a list of probabilities) of resnet34’ will be 20 as the number of my dataset classes are 20, while Imagenet classes are 1000.</p>

gphilip: <aside class="quote no-group" data-username="Myailab" data-post="7" data-topic="128932">
<div class="title">
<div class="quote-controls"></div>
<img loading="lazy" alt="" width="24" height="24" src="https://discuss.pytorch.org/letter_avatar_proxy/v4/letter/m/9de053/48.png" class="avatar"> Myailab:</div>
<blockquote>
<p>Isn’t that the ‘output (which is a list of probabilities) of resnet34’ will be 20 as the number of my dataset classes are 20</p>
</blockquote>
</aside>
<p>How does resnet34 know that the number of your data classes is 20?</p>

Myailab: <aside class="quote no-group" data-username="Myailab" data-post="1" data-topic="128932">
<div class="title">
<div class="quote-controls"></div>
<img loading="lazy" alt="" width="24" height="24" src="https://discuss.pytorch.org/letter_avatar_proxy/v4/letter/m/9de053/48.png" class="avatar"> Myailab:</div>
<blockquote>
<pre><code class="lang-auto">def get_resnet34(num_classes=20, **_):
</code></pre>
</blockquote>
</aside>
<p>That is the input parameter here</p>

gphilip: <p>I see. Your problem is much more basic than I thought. I suggest that you first do a course in Python to get a basic understanding of the language, before using it to play with neural networks.</p>

Myailab: <p>I think, I have not been able to put up my problem in a very understandable way here. anyways thanks.</p>