Pre-Trained Models

Supposed I’ve fine tuned a pre-trained model on patch images, and now i want to transform it into a whole image classifier by training it again using whole images, how do i add a new input layer at the beginning of the network for my whole image, using a pretrained AlexNet example?

Hey! I don’t think people usually replace the first layer of a network but rather the last layers. The first part of AlexNet is convolutional so it should be able to handle your whole images.

It’s the fully connected layers at the end that won’t match in dimensions, so you could replace them. They are easier to train than the first layer due to the nature of backprop anyway.

Another idea would to change your model to a fully convolutional one, then you wouldn’t have to replace the last few layers - but one solution would be to add a single layer at the end.

“Another idea would to change your model to a fully convolutional one”, How is this done?

Have a look at pytorch’s pretrained ResNets

Here is the source.

You can use any of the resnets. The larger the number, the better but slower the resnet. Start with resnet18 or 34 until things work :slight_smile:

I’m not sure how you are doing your fine tuning, but you might or might not need to replace the last fully connected layer once you want to run on whole images