Transfer learning from the subset of the ImageNet classes

Hi

Is it possible to get a pretrained model that is based on the selective classes of the ImageNet?

I have computed the similarity between each Imagenet class and my dataset using cvpr18-inaturalist-transfer/DomainSimilarityDemo.ipynb at master · richardaecn/cvpr18-inaturalist-transfer · GitHub

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.

Earlier, I was using the pretrained model as follows:

def get_resnet34(num_classes=20, **_):
    model_name = 'resnet34'
    model = pretrainedmodels.__dict__[model_name](num_classes=1000, pretrained='imagenet')
    conv1 = model.conv1

May I know how can i get the pretrained features from the selective classes of Imagenet.
I don’t have any clue to pursue this further.
Looking for help.

Thank you

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)?

This seems to be the simplest interpretation of “drop some classes from resnet34”. Perhaps this will work for your purpose?

Thanks for the suggestion.

Actually, output of this resnet model is 20 classes from my data set. I want to drop few classes from 1000 classes of ImageNet.
Do you think if that is possible.

Thanks

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?

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

Did you try my first suggestion? To me that looks like a reasonable first thing to try.

Thanks for the reply.
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.

How does resnet34 know that the number of your data classes is 20?

That is the input parameter here

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.

I think, I have not been able to put up my problem in a very understandable way here. anyways thanks.