Using a trained Resnet as feature extractor

Hi,
I have a Resnet-34 trained for the task of classification. However, I would like to use the features generated by this NN as input to a gradient booster along with some other user defined features. Here I am referring to features as the outputs of the flatten() layer just before they are fed to the linear part of the resnet. To be amply clear, the gradient booster would have 256/512 features pertaining to the input image concatenated with some use defined features.
Is there a way to delete the linear layers and only get access to the flattened feature vector of the Resnet??

Hi Sunil. I hope I am understanding your question correctly. ( I do not know anything about the requirements of gradient boosting.)

This is exactly how fastai converts the standard pre-trained resnet34 into a CNN Learner, by removing and appending layers. I suggest you look at create_cnn_model() to understand exactly how it is done. All the usual PyTorch operations can be used to delete layers so that the feature activations become the output from the model nn.Module.

1 Like

Thanks for the suggestion. Will go through create_cnn_model() and come back in case some things are not clear.

By the way, are you aware when is the fastai 2020 online course with fastai_v2 starting?

The live version has already passed a few months ago, exact dates for public release is unknown but expect around when their book is published.

1 Like