Adding a classifier on the ouputs of the intermediate layers

I have defined a simple resnet18 model with a two-node output layer. I extracted features from the last convolutional layer that might be useful to get image embeddings, now I would like to use a classifier with this vector.

How can I implement it? is it possible?

Thank you!

1 Like

I’m not exactly sure what “classifier” means in this context, but your resnet18 should already contain the feature extractor (the conv, pool, relu layers) and a classifier (linear, relu, etc.).
In the common setup the features (output of the last conv layer) would be flattened and passed to the classifier afterwards.

If I gather correctly, the person means he/she/they wants to use the frozen features from the last layer of resnet18 (dimension 512) and then fine-tune it for their own problem (e.g., feeding these 512D embeddings to an MLP layer for classification) rather than training the ResNet18 from scratch, maybe because they have limited data compared to that of ImageNet on which original ResNet18 is trained on.

I did something similar to this example: Extracting Intermediate Layer Outputs in PyTorch | Nikita Kozodoi

I have obtained output from one of the intermediate layers of the resnet18 neural network and now I would like to try to add a linear classifier as a decision tree, KNN…
I hypothesise that from the information obtained from intermediate layers I have features that I can then use in a classifier.