I’m working on fine tuning the first 10 layers of VGG19 net to extract features from images. But I’m getting the below error which I couldn’t find a get around:
Traceback (most recent call last):
  File "TODO-train_from_scratch.py", line 390, in <module>
    main()
  File "TODO-train_from_scratch.py", line 199, in main
    model.load_state_dict(weights_load)
  File "/usr/local/lib/python2.7/dist-packages/torch/nn/modules/module.py", line 339, in load_state_dict
    raise KeyError('missing keys in state_dict: "{}"'.format(missing)) 

Corresponding snippet from training code is:
# create model
vgg19 = models.vgg19(pretrained = True)

vgg19_state_dict = vgg19.state_dict()

vgg19_keys = vgg19_state_dict.keys()    

model = get_model()

weights_load = {}   

for i in range(20):
    weights_load[model.state_dict().keys()[i]] = vgg19_state_dict[vgg19_keys[i]]

model.load_state_dict(weights_load)
model = torch.nn.DataParallel(model).cuda()