Model.load_state_dict(torch.load(args.model_loc)) after using Inception V3 pretrained model

I am reading a GitHub code that uses a pretrained version of Inception V3. I am confused by this line model.load_state_dict(torch.load(args.model_loc)) in the code:

    # define the model 
    model = models.inception_v3(pretrained=True)
    num_ftrs = model.fc.in_features
    model.fc = nn.Linear(num_ftrs, 2)

    # load the model
    model.load_state_dict(torch.load(args.model_loc))
    model.eval()
    model.cuda()

As we see, in the original Inception code, it is already loading the state dict. I am wondering why the authors are also doing same after setting their model to the pretrained Inception V3?

At the same time, I see this piece of Kaggle code for using a pretrained Inception V3 model. So, which method do you comment as correct?

import torchvision.models as models
import torch.optim as optim

model_ft = models.inception_v3(pretrained=True)
for param in model_ft.parameters():
    param.requires_grad = False

# Parameters of newly constructed modules have requires_grad=True by default
# Handle the auxilary net
num_ftrs = model_ft.AuxLogits.fc.in_features
model_ft.AuxLogits.fc = nn.Linear(num_ftrs, 2)
# Handle the primary net
num_ftrs = model_ft.fc.in_features
model_ft.fc = nn.Linear(num_ftrs, 2)

I guess the author of the first code snippet is loading a pretrained state_dict for the manipulated model (note that model.fc is changed)?

1 Like