About load parameter

I used resnet in torchvision, and made following changes:

from torchvision import models as tvmodel
class ModifiedResNet18Model(torch.nn.Module):
def init(self,num_class):
super(ModifiedResNet18Model, self).init()

    model = tvmodel.resnet18(pretrained=False)
    modules = list(model.children())[:-1]
    model1 = nn.Sequential(*modules)
    self.features = model1
    self.fc = nn.Sequential(nn.Linear(512,num_class))

def forward(self, x):
    x = self.features(x)
    x = x.view(x.size(0), -1)
    x = self.fc(x) 
    return x

In that case, how can I load the parameters of the pre-trained model for this new ‘resnet’?

You would just have to set pretrained=True and self.features will contain all pretrained parameters.
Of course self.fc will be randomly initialized, since you recreate it with your custom number of classes.

I get it, thank you very much!