Transfer Learning with Pytorch Code Snippet Load a Pretrained Model

Uniqtech
Data Science Bootcamp

--

Need to load a pretrained model, such as VGG 16 in Pytorch. Use this simple code snippet. You will need the torch, torchvision and torchvision.models modules.

If you are a member, please kindly clap. Thanks a billion. For more beginner friendly articles like this, subscribe!

Transfer learning allows us to leverage knowledge obtained prior, from pre-trained model, for our current task, which may be new domain and or has less available data. Often we have customer the last one or few layers of the classifier or linear layer in the end to make the other model work with our current task.

A more technical definition is: transfer learning is using a model that is pre-trained primarily on another training dataset. It may or may not needed to be trained again fully or partially on the current training dataset.

Why is transfer learning useful again? Transfer learning use models to predict the type of the dataset that it wasn’t trained on. It can significantly improve training time and accuracy. It can also help with the situation where available training data is limited.

Read about all the available models on Pytorch documentation (link removed by pytorch). Note the top-1-error, top-5-error i.e. the performance of the models are also…

--

--