In transfer learning, often only the last layer of the network is retrained using gradient descent. However, the last layer of a common neural network performs only a linear transformation, so why do we use gradient descent and not linear (or logistic) regression to finetune the last layer?


The common approach to fine-tuning an existing pre-trained neural network is the following:

  1. Given an existing pre-trained neural network model (e.g. imagenet), remove the last layer (which does classification in the pre-training task) and freeze all weights in the remaining layers of the model (usually with setting the trainable parameter to false).
  2. Add a new final dense layer that is to be trained on the new task.
  3. Train the model on the new task's dataset until convergence.
  4. [optional] After fine-tuning is converged, possibly unfreeze the all the layers and train further until convergence with a lower learning rate.

A reason to use gradient descent over a different ML algorithm as you suggest is to enable further training after initial fine-tuning (step #4 above). However, it's not necessary to do this. The approach you suggest (to use take the output of the pre-trained model as input to another ML model) may provide satisfactory performance and be more computationally efficient.

Tradeoffs between these approaches is also discussed in the Keras Transfer Learning guide in the section on the "Typical Transfer Learning Workflow".

  • $\begingroup$ Thanks for the answer. If don't find the discussion in the link. Can you be more specific? Also, what confuses me: When I trained the last layer using linear regression, I still can further train the network using gradient descent. I don't see a problem there. $\endgroup$ – Funkwecker Apr 3 at 7:34
  • $\begingroup$ The link to the section in the keras guide with some discussion of the tradeoffs of using another model (e.g. linear regression) vs using gradient descent was added in my newest edit: link $\endgroup$ – grov Apr 4 at 1:19
  • $\begingroup$ @funkwecker Could you say more about why you would want to use linear regression to calibrate the weights in the last layer of the network and later use gradient descent to fine tune globally? It seems possible to change algorithms for different phases of learning but what are the benefits? $\endgroup$ – grov Apr 4 at 1:21

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.