leaderj1001 / Stand-Alone-Self-Attention

Implementing Stand-Alone Self-Attention in Vision Models using Pytorch
MIT License
456 stars 83 forks source link

Error loading pretrained model #20

Closed ylee1123 closed 4 years ago

ylee1123 commented 4 years ago

When I try to load pretrained model, I kept getting this error.

RuntimeError: Error(s) in loading state_dict for Model: Missing key(s) in state_dict: "layer1.0.conv2.0.rel_h", "layer1.0.conv2.0.rel_w", "layer1.0.conv2.0.key_conv.weight", "layer1.0.conv2.0.query_conv.weight", "layer1.0.conv2.0.value_conv.weight", "layer2.0.conv2.0.rel_h", "layer2.0.conv2.0.rel_w", "layer2.0.conv2.0.key_conv.weight", "layer2.0.conv2.0.query_conv.weight", "layer2.0.conv2.0.value_conv.weight", "layer2.1.conv2.0.rel_h", "layer2.1.conv2.0.rel_w", "layer2.1.conv2.0.key_conv.weight", "layer2.1.conv2.0.query_conv.weight", "layer2.1.conv2.0.value_conv.weight", "layer3.0.conv2.0.rel_h", "layer3.0.conv2.0.rel_w", "layer3.0.conv2.0.key_conv.weight", "layer3.0.conv2.0.query_conv.weight", "layer3.0.conv2.0.value_conv.weight", "layer3.1.conv2.0.rel_h", "layer3.1.conv2.0.rel_w", "layer3.1.conv2.0.key_conv.weight", "layer3.1.conv2.0.query_conv.weight", "layer3.1.conv2.0.value_conv.weight", "layer3.2.conv2.0.rel_h", "layer3.2.conv2.0.rel_w", "layer3.2.conv2.0.key_conv.weight", "layer3.2.conv2.0.query_conv.weight", "layer3.2.conv2.0.value_conv.weight", "layer3.3.conv2.0.rel_h", "layer3.3.conv2.0.rel_w", "layer3.3.conv2.0.key_conv.weight", "layer3.3.conv2.0.query_conv.weight", "layer3.3.conv2.0.value_conv.weight", "layer4.0.conv2.0.rel_h", "layer4.0.conv2.0.rel_w", "layer4.0.conv2.0.key_conv.weight", "layer4.0.conv2.0.query_conv.weight", "layer4.0.conv2.0.value_conv.weight". Unexpected key(s) in state_dict: "layer1.0.conv2.0.weight", "layer1.0.conv2.0.bias", "layer2.0.conv2.0.weight", "layer2.0.conv2.0.bias", "layer2.1.conv2.0.weight", "layer2.1.conv2.0.bias", "layer3.0.conv2.0.weight", "layer3.0.conv2.0.bias", "layer3.1.conv2.0.weight", "layer3.1.conv2.0.bias", "layer3.2.conv2.0.weight", "layer3.2.conv2.0.bias", "layer3.3.conv2.0.weight", "layer3.3.conv2.0.bias", "layer4.0.conv2.0.weight", "layer4.0.conv2.0.bias".

my code for loading pretrained model is below:

    file_path = 'path to file_ckpt.tar'
    checkpoint = torch.load(file_path)

    model.load_state_dict(checkpoint['state_dict'])
    model = nn.DataParallel(model, dim=0)
    model.cuda()
    start_epoch = checkpoint['epoch']
    best_acc = checkpoint['best_acc']

    model_parameters = checkpoint['parameters']
ylee1123 commented 4 years ago

Sorry, problem solved. It was my mistake.