Hi, I was learning the course in Deep learning with Pytorch: Zero to GANs and I learned how to create a resnet model. I trying creating my own model and I came up with pretrained resnet50 model. How can I use a pretrained model from pytorch?
Hey, Here’s a step by step guide.
import torchvision.models as models
- Select the model you want, suppose resnet50, `model = models.resnet50(pretrained=True) (Note different parameters have different use check the documentations for parameters) → torchvision.models — Torchvision 0.10.0 documentation
3.Optimize the layers according to your need. Mostly you have to optimized the last layer to set the number of classes of output you have and model definition is done, now you have to train your model.
Check the notebook below to know more about different models. I have used many pretrained models like resnet50, resnet101, vgg16, vgg19 etc.(Do compare versions on version to check different versions ).
Thank you for the reply. The notebook has helped me relate and can now use pretrained models.
Hi Birajde, I saw you used resnet152 model in your program. How did you create your model?
I don’t think I have used resnet152 in my project, but you can do that easily by getting the resnet152 model and changing the
self.network.fc layer as I have done for other pretrained models. The structure of the code remains the same, just the model will be different.
How can one know resnet is resnet22 or resnet9 or resnet152 by the architecture?
The term ResNet mean Residual Network, that is it contains mixture of weighted layer and some residual layers. The numbers on Resnet Signify the number of layers the model have, For example, resnet9 is a 9 layered model with probably 4 residual layer, 4 weighted layer and one final(fc) layer(Not exactly sure if the numbers are correct), similarly resnet22 should have 22 layers, and so on. The more the number the more concentrated/heavy the model is.
Thanks, I now know how the architecture is created for resnet. I also got more from this page https://towardsdatascience.com/understanding-and-visualizing-resnets-442284831be8