当前位置: 首页 > article >正文

pytorch加载预训练权重失败

问题

给当前模型换了个开源的主干网络,并且删除了某些层后,但是发现预训练权重一直加载不上。strict为True时加载报错,strict为False时又什么都加载不上,然后不知道哪里出问题了。

解决

当strict为False时,load_state_dict函数会返回一个字典,该字典含有以下两个键:

missing_keys:在当前模型中存在,但在预训练权重中不存在的键。
unexpected_keys:在当前模型不存在,但在预训练权重中存在的键。
        result=self.backbone.load_state_dict(model_weight,strict=False)
        print("Missing keys:", result.missing_keys)
        print("Unexpected keys:", result.unexpected_keys)

得到输出:

Missing keys: ['model.patch_embed.conv1.weight', 'model.patch_embed.conv1.bias', 'model.patch_embed.norm1.1.weight', 'model.patch_embed.norm1.1.bias', 'model.patch_embed.conv2.weight', 'model.patch_embed.conv2.bias', 'model.patch_embed.norm2.1.weight', 'model.patch_embed.norm2.1.bias', 'model.levels.0.blocks.0.norm1.0.weight', 'model.levels.0.blocks.0.norm1.0.bias', 'model.levels.0.blocks.0.dcn.offset_mask.weight', 'model.levels.0.blocks.0.dcn.offset_mask.bias', 'model.levels.0.blocks.0.dcn.value_proj.weight', 'model.levels.0.blocks.0.dcn.value_proj.bias', 'model.levels.0.blocks.0.dcn.output_proj.weight', 'model.levels.0.blocks.0.norm2.0.weight', 'model.levels.0.blocks.0.norm2.0.bias', 'model.levels.0.blocks.0.mlp.fc1.weight', 'model.levels.0.blocks.0.mlp.fc1.bias', 'model.levels.0.blocks.0.mlp.fc2.weight', 'model.levels.0.blocks.1.norm1.0.weight', 'model.levels.0.blocks.1.norm1.0.bias', 'model.levels.0.blocks.1.dcn.offset_mask.weight', 'model.levels.0.blocks.1.dcn.offset_mask.bias', 'model.levels.0.blocks.1.dcn.value_proj.weight', 'model.levels.0.blocks.1.dcn.value_proj.bias', 'model.levels.0.blocks.1.dcn.output_proj.weight', 'model.levels.0.blocks.1.norm2.0.weight', 'model.levels.0.blocks.1.norm2.0.bias', 'model.levels.0.blocks.1.mlp.fc1.weight', 'model.levels.0.blocks.1.mlp.fc1.bias', 'model.levels.0.blocks.1.mlp.fc2.weight', 'model.levels.0.blocks.2.norm1.0.weight', 'model.levels.0.blocks.2.norm1.0.bias', 'model.levels.0.blocks.2.dcn.offset_mask.weight', 'model.levels.0.blocks.2.dcn.offset_mask.bias', 'model.levels.0.blocks.2.dcn.value_proj.weight', 'model.levels.0.blocks.2.dcn.value_proj.bias', 'model.levels.0.blocks.2.dcn.output_proj.weight', 'model.levels.0.blocks.2.norm2.0.weight', 'model.levels.0.blocks.2.norm2.0.bias', 'model.levels.0.blocks.2.mlp.fc1.weight', 'model.levels.0.blocks.2.mlp.fc1.bias', 'model.levels.0.blocks.2.mlp.fc2.weight', 'model.levels.0.blocks.3.norm1.0.weight', 'model.levels.0.blocks.3.norm1.0.bias', 'model.levels.0.blocks.3.dcn.offset_mask.weight', 'model.levels.0.blocks.3.dcn.offset_mask.bias', 'model.levels.0.blocks.3.dcn.value_proj.weight', 'model.levels.0.blocks.3.dcn.value_proj.bias', 'model.levels.0.blocks.3.dcn.output_proj.weight', 'model.levels.0.blocks.3.norm2.0.weight', 'model.levels.0.blocks.3.norm2.0.bias', 'model.levels.0.blocks.3.mlp.fc1.weight', 'model.levels.0.blocks.3.mlp.fc1.bias', 'model.levels.0.blocks.3.mlp.fc2.weight', 'model.levels.0.norm.0.weight', 'model.levels.0.norm.0.bias', 'model.levels.0.downsample.conv.weight', 'model.levels.0.downsample.norm.1.weight', 'model.levels.0.downsample.norm.1.bias', 'model.levels.1.blocks.0.norm1.0.weight', 'model.levels.1.blocks.0.norm1.0.bias', 'model.levels.1.blocks.0.dcn.offset_mask.weight', 'model.levels.1.blocks.0.dcn.offset_mask.bias', 'model.levels.1.blocks.0.dcn.value_proj.weight', 'model.levels.1.blocks.0.dcn.value_proj.bias', 'model.levels.1.blocks.0.dcn.output_proj.weight', 'model.levels.1.blocks.0.norm2.0.weight', 'model.levels.1.blocks.0.norm2.0.bias', 'model.levels.1.blocks.0.mlp.fc1.weight', 'model.levels.1.blocks.0.mlp.fc1.bias', 'model.levels.1.blocks.0.mlp.fc2.weight', 'model.levels.1.blocks.1.norm1.0.weight', 'model.levels.1.blocks.1.norm1.0.bias', 'model.levels.1.blocks.1.dcn.offset_mask.weight', 'model.levels.1.blocks.1.dcn.offset_mask.bias', 'model.levels.1.blocks.1.dcn.value_proj.weight', 'model.levels.1.blocks.1.dcn.value_proj.bias', 'model.levels.1.blocks.1.dcn.output_proj.weight', 'model.levels.1.blocks.1.norm2.0.weight', 'model.levels.1.blocks.1.norm2.0.bias', 'model.levels.1.blocks.1.mlp.fc1.weight', 'model.levels.1.blocks.1.mlp.fc1.bias', 'model.levels.1.blocks.1.mlp.fc2.weight', 'model.levels.1.blocks.2.norm1.0.weight', 'model.levels.1.blocks.2.norm1.0.bias', 'model.levels.1.blocks.2.dcn.offset_mask.weight', 'model.levels.1.blocks.2.dcn.offset_mask.bias', 'model.levels.1.blocks.2.dcn.value_proj.weight', 'model.levels.1.blocks.2.dcn.value_proj.bias', 'model.levels.1.blocks.2.dcn.output_proj.weight', 'model.levels.1.blocks.2.norm2.0.weight', 'model.levels.1.blocks.2.norm2.0.bias', 'model.levels.1.blocks.2.mlp.fc1.weight', 'model.levels.1.blocks.2.mlp.fc1.bias', 'model.levels.1.blocks.2.mlp.fc2.weight', 'model.levels.1.blocks.3.norm1.0.weight', 'model.levels.1.blocks.3.norm1.0.bias', 'model.levels.1.blocks.3.dcn.offset_mask.weight', 'model.levels.1.blocks.3.dcn.offset_mask.bias', 'model.levels.1.blocks.3.dcn.value_proj.weight', 'model.levels.1.blocks.3.dcn.value_proj.bias', 'model.levels.1.blocks.3.dcn.output_proj.weight', 'model.levels.1.blocks.3.norm2.0.weight', 'model.levels.1.blocks.3.norm2.0.bias', 'model.levels.1.blocks.3.mlp.fc1.weight', 'model.levels.1.blocks.3.mlp.fc1.bias', 'model.levels.1.blocks.3.mlp.fc2.weight', 'model.levels.1.norm.0.weight', 'model.levels.1.norm.0.bias', 'model.levels.1.downsample.conv.weight', 'model.levels.1.downsample.norm.1.weight', 'model.levels.1.downsample.norm.1.bias', 'model.levels.2.blocks.0.norm1.0.weight', 'model.levels.2.blocks.0.norm1.0.bias', 'model.levels.2.blocks.0.dcn.offset_mask.weight', 'model.levels.2.blocks.0.dcn.offset_mask.bias', 'model.levels.2.blocks.0.dcn.value_proj.weight', 'model.levels.2.blocks.0.dcn.value_proj.bias', 'model.levels.2.blocks.0.dcn.output_proj.weight', 'model.levels.2.blocks.0.norm2.0.weight', 'model.levels.2.blocks.0.norm2.0.bias', 'model.levels.2.blocks.0.mlp.fc1.weight', 'model.levels.2.blocks.0.mlp.fc1.bias', 'model.levels.2.blocks.0.mlp.fc2.weight', 'model.levels.2.blocks.1.norm1.0.weight', 'model.levels.2.blocks.1.norm1.0.bias', 'model.levels.2.blocks.1.dcn.offset_mask.weight', 'model.levels.2.blocks.1.dcn.offset_mask.bias', 'model.levels.2.blocks.1.dcn.value_proj.weight', 'model.levels.2.blocks.1.dcn.value_proj.bias', 'model.levels.2.blocks.1.dcn.output_proj.weight', 'model.levels.2.blocks.1.norm2.0.weight', 'model.levels.2.blocks.1.norm2.0.bias', 'model.levels.2.blocks.1.mlp.fc1.weight', 'model.levels.2.blocks.1.mlp.fc1.bias', 'model.levels.2.blocks.1.mlp.fc2.weight', 'model.levels.2.blocks.2.norm1.0.weight', 'model.levels.2.blocks.2.norm1.0.bias', 'model.levels.2.blocks.2.dcn.offset_mask.weight', 'model.levels.2.blocks.2.dcn.offset_mask.bias', 'model.levels.2.blocks.2.dcn.value_proj.weight', 'model.levels.2.blocks.2.dcn.value_proj.bias', 'model.levels.2.blocks.2.dcn.output_proj.weight', 'model.levels.2.blocks.2.norm2.0.weight', 'model.levels.2.blocks.2.norm2.0.bias', 'model.levels.2.blocks.2.mlp.fc1.weight', 'model.levels.2.blocks.2.mlp.fc1.bias', 'model.levels.2.blocks.2.mlp.fc2.weight', 'model.levels.2.blocks.3.norm1.0.weight', 'model.levels.2.blocks.3.norm1.0.bias', 'model.levels.2.blocks.3.dcn.offset_mask.weight', 'model.levels.2.blocks.3.dcn.offset_mask.bias', 'model.levels.2.blocks.3.dcn.value_proj.weight', 'model.levels.2.blocks.3.dcn.value_proj.bias', 'model.levels.2.blocks.3.dcn.output_proj.weight', 'model.levels.2.blocks.3.norm2.0.weight', 'model.levels.2.blocks.3.norm2.0.bias', 'model.levels.2.blocks.3.mlp.fc1.weight', 'model.levels.2.blocks.3.mlp.fc1.bias', 'model.levels.2.blocks.3.mlp.fc2.weight', 'model.levels.2.blocks.4.norm1.0.weight', 'model.levels.2.blocks.4.norm1.0.bias', 'model.levels.2.blocks.4.dcn.offset_mask.weight', 'model.levels.2.blocks.4.dcn.offset_mask.bias', 'model.levels.2.blocks.4.dcn.value_proj.weight', 'model.levels.2.blocks.4.dcn.value_proj.bias', 'model.levels.2.blocks.4.dcn.output_proj.weight', 'model.levels.2.blocks.4.norm2.0.weight', 'model.levels.2.blocks.4.norm2.0.bias', 'model.levels.2.blocks.4.mlp.fc1.weight', 'model.levels.2.blocks.4.mlp.fc1.bias', 'model.levels.2.blocks.4.mlp.fc2.weight', 'model.levels.2.blocks.5.norm1.0.weight', 'model.levels.2.blocks.5.norm1.0.bias', 'model.levels.2.blocks.5.dcn.offset_mask.weight', 'model.levels.2.blocks.5.dcn.offset_mask.bias', 'model.levels.2.blocks.5.dcn.value_proj.weight', 'model.levels.2.blocks.5.dcn.value_proj.bias', 'model.levels.2.blocks.5.dcn.output_proj.weight', 'model.levels.2.blocks.5.norm2.0.weight', 'model.levels.2.blocks.5.norm2.0.bias', 'model.levels.2.blocks.5.mlp.fc1.weight', 'model.levels.2.blocks.5.mlp.fc1.bias', 'model.levels.2.blocks.5.mlp.fc2.weight', 'model.levels.2.blocks.6.norm1.0.weight', 'model.levels.2.blocks.6.norm1.0.bias', 'model.levels.2.blocks.6.dcn.offset_mask.weight', 'model.levels.2.blocks.6.dcn.offset_mask.bias', 'model.levels.2.blocks.6.dcn.value_proj.weight', 'model.levels.2.blocks.6.dcn.value_proj.bias', 'model.levels.2.blocks.6.dcn.output_proj.weight', 'model.levels.2.blocks.6.norm2.0.weight', 'model.levels.2.blocks.6.norm2.0.bias', 'model.levels.2.blocks.6.mlp.fc1.weight', 'model.levels.2.blocks.6.mlp.fc1.bias', 'model.levels.2.blocks.6.mlp.fc2.weight', 'model.levels.2.blocks.7.norm1.0.weight', 'model.levels.2.blocks.7.norm1.0.bias', 'model.levels.2.blocks.7.dcn.offset_mask.weight', 'model.levels.2.blocks.7.dcn.offset_mask.bias', 'model.levels.2.blocks.7.dcn.value_proj.weight', 'model.levels.2.blocks.7.dcn.value_proj.bias', 'model.levels.2.blocks.7.dcn.output_proj.weight', 'model.levels.2.blocks.7.norm2.0.weight', 'model.levels.2.blocks.7.norm2.0.bias', 'model.levels.2.blocks.7.mlp.fc1.weight', 'model.levels.2.blocks.7.mlp.fc1.bias', 'model.levels.2.blocks.7.mlp.fc2.weight', 'model.levels.2.blocks.8.norm1.0.weight', 'model.levels.2.blocks.8.norm1.0.bias', 'model.levels.2.blocks.8.dcn.offset_mask.weight', 'model.levels.2.blocks.8.dcn.offset_mask.bias', 'model.levels.2.blocks.8.dcn.value_proj.weight', 'model.levels.2.blocks.8.dcn.value_proj.bias', 'model.levels.2.blocks.8.dcn.output_proj.weight', 'model.levels.2.blocks.8.norm2.0.weight', 'model.levels.2.blocks.8.norm2.0.bias', 'model.levels.2.blocks.8.mlp.fc1.weight', 'model.levels.2.blocks.8.mlp.fc1.bias', 'model.levels.2.blocks.8.mlp.fc2.weight', 'model.levels.2.blocks.9.norm1.0.weight', 'model.levels.2.blocks.9.norm1.0.bias', 'model.levels.2.blocks.9.dcn.offset_mask.weight', 'model.levels.2.blocks.9.dcn.offset_mask.bias', 'model.levels.2.blocks.9.dcn.value_proj.weight', 'model.levels.2.blocks.9.dcn.value_proj.bias', 'model.levels.2.blocks.9.dcn.output_proj.weight', 'model.levels.2.blocks.9.norm2.0.weight', 'model.levels.2.blocks.9.norm2.0.bias', 'model.levels.2.blocks.9.mlp.fc1.weight', 'model.levels.2.blocks.9.mlp.fc1.bias', 'model.levels.2.blocks.9.mlp.fc2.weight', 'model.levels.2.blocks.10.norm1.0.weight', 'model.levels.2.blocks.10.norm1.0.bias', 'model.levels.2.blocks.10.dcn.offset_mask.weight', 'model.levels.2.blocks.10.dcn.offset_mask.bias', 'model.levels.2.blocks.10.dcn.value_proj.weight', 'model.levels.2.blocks.10.dcn.value_proj.bias', 'model.levels.2.blocks.10.dcn.output_proj.weight', 'model.levels.2.blocks.10.norm2.0.weight', 'model.levels.2.blocks.10.norm2.0.bias', 'model.levels.2.blocks.10.mlp.fc1.weight', 'model.levels.2.blocks.10.mlp.fc1.bias', 'model.levels.2.blocks.10.mlp.fc2.weight', 'model.levels.2.blocks.11.norm1.0.weight', 'model.levels.2.blocks.11.norm1.0.bias', 'model.levels.2.blocks.11.dcn.offset_mask.weight', 'model.levels.2.blocks.11.dcn.offset_mask.bias', 'model.levels.2.blocks.11.dcn.value_proj.weight', 'model.levels.2.blocks.11.dcn.value_proj.bias', 'model.levels.2.blocks.11.dcn.output_proj.weight', 'model.levels.2.blocks.11.norm2.0.weight', 'model.levels.2.blocks.11.norm2.0.bias', 'model.levels.2.blocks.11.mlp.fc1.weight', 'model.levels.2.blocks.11.mlp.fc1.bias', 'model.levels.2.blocks.11.mlp.fc2.weight', 'model.levels.2.blocks.12.norm1.0.weight', 'model.levels.2.blocks.12.norm1.0.bias', 'model.levels.2.blocks.12.dcn.offset_mask.weight', 'model.levels.2.blocks.12.dcn.offset_mask.bias', 'model.levels.2.blocks.12.dcn.value_proj.weight', 'model.levels.2.blocks.12.dcn.value_proj.bias', 'model.levels.2.blocks.12.dcn.output_proj.weight', 'model.levels.2.blocks.12.norm2.0.weight', 'model.levels.2.blocks.12.norm2.0.bias', 'model.levels.2.blocks.12.mlp.fc1.weight', 'model.levels.2.blocks.12.mlp.fc1.bias', 'model.levels.2.blocks.12.mlp.fc2.weight', 'model.levels.2.blocks.13.norm1.0.weight', 'model.levels.2.blocks.13.norm1.0.bias', 'model.levels.2.blocks.13.dcn.offset_mask.weight', 'model.levels.2.blocks.13.dcn.offset_mask.bias', 'model.levels.2.blocks.13.dcn.value_proj.weight', 'model.levels.2.blocks.13.dcn.value_proj.bias', 'model.levels.2.blocks.13.dcn.output_proj.weight', 'model.levels.2.blocks.13.norm2.0.weight', 'model.levels.2.blocks.13.norm2.0.bias', 'model.levels.2.blocks.13.mlp.fc1.weight', 'model.levels.2.blocks.13.mlp.fc1.bias', 'model.levels.2.blocks.13.mlp.fc2.weight', 'model.levels.2.blocks.14.norm1.0.weight', 'model.levels.2.blocks.14.norm1.0.bias', 'model.levels.2.blocks.14.dcn.offset_mask.weight', 'model.levels.2.blocks.14.dcn.offset_mask.bias', 'model.levels.2.blocks.14.dcn.value_proj.weight', 'model.levels.2.blocks.14.dcn.value_proj.bias', 'model.levels.2.blocks.14.dcn.output_proj.weight', 'model.levels.2.blocks.14.norm2.0.weight', 'model.levels.2.blocks.14.norm2.0.bias', 'model.levels.2.blocks.14.mlp.fc1.weight', 'model.levels.2.blocks.14.mlp.fc1.bias', 'model.levels.2.blocks.14.mlp.fc2.weight', 'model.levels.2.blocks.15.norm1.0.weight', 'model.levels.2.blocks.15.norm1.0.bias', 'model.levels.2.blocks.15.dcn.offset_mask.weight', 'model.levels.2.blocks.15.dcn.offset_mask.bias', 'model.levels.2.blocks.15.dcn.value_proj.weight', 'model.levels.2.blocks.15.dcn.value_proj.bias', 'model.levels.2.blocks.15.dcn.output_proj.weight', 'model.levels.2.blocks.15.norm2.0.weight', 'model.levels.2.blocks.15.norm2.0.bias', 'model.levels.2.blocks.15.mlp.fc1.weight', 'model.levels.2.blocks.15.mlp.fc1.bias', 'model.levels.2.blocks.15.mlp.fc2.weight', 'model.levels.2.blocks.16.norm1.0.weight', 'model.levels.2.blocks.16.norm1.0.bias', 'model.levels.2.blocks.16.dcn.offset_mask.weight', 'model.levels.2.blocks.16.dcn.offset_mask.bias', 'model.levels.2.blocks.16.dcn.value_proj.weight', 'model.levels.2.blocks.16.dcn.value_proj.bias', 'model.levels.2.blocks.16.dcn.output_proj.weight', 'model.levels.2.blocks.16.norm2.0.weight', 'model.levels.2.blocks.16.norm2.0.bias', 'model.levels.2.blocks.16.mlp.fc1.weight', 'model.levels.2.blocks.16.mlp.fc1.bias', 'model.levels.2.blocks.16.mlp.fc2.weight', 'model.levels.2.blocks.17.norm1.0.weight', 'model.levels.2.blocks.17.norm1.0.bias', 'model.levels.2.blocks.17.dcn.offset_mask.weight', 'model.levels.2.blocks.17.dcn.offset_mask.bias', 'model.levels.2.blocks.17.dcn.value_proj.weight', 'model.levels.2.blocks.17.dcn.value_proj.bias', 'model.levels.2.blocks.17.dcn.output_proj.weight', 'model.levels.2.blocks.17.norm2.0.weight', 'model.levels.2.blocks.17.norm2.0.bias', 'model.levels.2.blocks.17.mlp.fc1.weight', 'model.levels.2.blocks.17.mlp.fc1.bias', 'model.levels.2.blocks.17.mlp.fc2.weight', 'model.levels.2.norm.0.weight', 'model.levels.2.norm.0.bias', 'model.levels.2.downsample.conv.weight', 'model.levels.2.downsample.norm.1.weight', 'model.levels.2.downsample.norm.1.bias', 'model.levels.3.blocks.0.norm1.0.weight', 'model.levels.3.blocks.0.norm1.0.bias', 'model.levels.3.blocks.0.dcn.offset_mask.weight', 'model.levels.3.blocks.0.dcn.offset_mask.bias', 'model.levels.3.blocks.0.dcn.value_proj.weight', 'model.levels.3.blocks.0.dcn.value_proj.bias', 'model.levels.3.blocks.0.dcn.output_proj.weight', 'model.levels.3.blocks.0.norm2.0.weight', 'model.levels.3.blocks.0.norm2.0.bias', 'model.levels.3.blocks.0.mlp.fc1.weight', 'model.levels.3.blocks.0.mlp.fc1.bias', 'model.levels.3.blocks.0.mlp.fc2.weight', 'model.levels.3.blocks.1.norm1.0.weight', 'model.levels.3.blocks.1.norm1.0.bias', 'model.levels.3.blocks.1.dcn.offset_mask.weight', 'model.levels.3.blocks.1.dcn.offset_mask.bias', 'model.levels.3.blocks.1.dcn.value_proj.weight', 'model.levels.3.blocks.1.dcn.value_proj.bias', 'model.levels.3.blocks.1.dcn.output_proj.weight', 'model.levels.3.blocks.1.norm2.0.weight', 'model.levels.3.blocks.1.norm2.0.bias', 'model.levels.3.blocks.1.mlp.fc1.weight', 'model.levels.3.blocks.1.mlp.fc1.bias', 'model.levels.3.blocks.1.mlp.fc2.weight', 'model.levels.3.blocks.2.norm1.0.weight', 'model.levels.3.blocks.2.norm1.0.bias', 'model.levels.3.blocks.2.dcn.offset_mask.weight', 'model.levels.3.blocks.2.dcn.offset_mask.bias', 'model.levels.3.blocks.2.dcn.value_proj.weight', 'model.levels.3.blocks.2.dcn.value_proj.bias', 'model.levels.3.blocks.2.dcn.output_proj.weight', 'model.levels.3.blocks.2.norm2.0.weight', 'model.levels.3.blocks.2.norm2.0.bias', 'model.levels.3.blocks.2.mlp.fc1.weight', 'model.levels.3.blocks.2.mlp.fc1.bias', 'model.levels.3.blocks.2.mlp.fc2.weight', 'model.levels.3.blocks.3.norm1.0.weight', 'model.levels.3.blocks.3.norm1.0.bias', 'model.levels.3.blocks.3.dcn.offset_mask.weight', 'model.levels.3.blocks.3.dcn.offset_mask.bias', 'model.levels.3.blocks.3.dcn.value_proj.weight', 'model.levels.3.blocks.3.dcn.value_proj.bias', 'model.levels.3.blocks.3.dcn.output_proj.weight', 'model.levels.3.blocks.3.norm2.0.weight', 'model.levels.3.blocks.3.norm2.0.bias', 'model.levels.3.blocks.3.mlp.fc1.weight', 'model.levels.3.blocks.3.mlp.fc1.bias', 'model.levels.3.blocks.3.mlp.fc2.weight', 'model.levels.3.norm.0.weight', 'model.levels.3.norm.0.bias', 'model.conv_head.0.weight', 'model.conv_head.1.0.weight', 'model.conv_head.1.0.bias', 'model.conv_head.1.0.running_mean', 'model.conv_head.1.0.running_var']
Unexpected keys: ['patch_embed.conv1.weight', 'patch_embed.conv1.bias', 'patch_embed.norm1.1.weight', 'patch_embed.norm1.1.bias', 'patch_embed.conv2.weight', 'patch_embed.conv2.bias', 'patch_embed.norm2.1.weight', 'patch_embed.norm2.1.bias', 'levels.0.blocks.0.norm1.0.weight', 'levels.0.blocks.0.norm1.0.bias', 'levels.0.blocks.0.dcn.offset_mask.weight', 'levels.0.blocks.0.dcn.offset_mask.bias', 'levels.0.blocks.0.dcn.value_proj.weight', 'levels.0.blocks.0.dcn.value_proj.bias', 'levels.0.blocks.0.dcn.output_proj.weight', 'levels.0.blocks.0.norm2.0.weight', 'levels.0.blocks.0.norm2.0.bias', 'levels.0.blocks.0.mlp.fc1.weight', 'levels.0.blocks.0.mlp.fc1.bias', 'levels.0.blocks.0.mlp.fc2.weight', 'levels.0.blocks.1.norm1.0.weight', 'levels.0.blocks.1.norm1.0.bias', 'levels.0.blocks.1.dcn.offset_mask.weight', 'levels.0.blocks.1.dcn.offset_mask.bias', 'levels.0.blocks.1.dcn.value_proj.weight', 'levels.0.blocks.1.dcn.value_proj.bias', 'levels.0.blocks.1.dcn.output_proj.weight', 'levels.0.blocks.1.norm2.0.weight', 'levels.0.blocks.1.norm2.0.bias', 'levels.0.blocks.1.mlp.fc1.weight', 'levels.0.blocks.1.mlp.fc1.bias', 'levels.0.blocks.1.mlp.fc2.weight', 'levels.0.blocks.2.norm1.0.weight', 'levels.0.blocks.2.norm1.0.bias', 'levels.0.blocks.2.dcn.offset_mask.weight', 'levels.0.blocks.2.dcn.offset_mask.bias', 'levels.0.blocks.2.dcn.value_proj.weight', 'levels.0.blocks.2.dcn.value_proj.bias', 'levels.0.blocks.2.dcn.output_proj.weight', 'levels.0.blocks.2.norm2.0.weight', 'levels.0.blocks.2.norm2.0.bias', 'levels.0.blocks.2.mlp.fc1.weight', 'levels.0.blocks.2.mlp.fc1.bias', 'levels.0.blocks.2.mlp.fc2.weight', 'levels.0.blocks.3.norm1.0.weight', 'levels.0.blocks.3.norm1.0.bias', 'levels.0.blocks.3.dcn.offset_mask.weight', 'levels.0.blocks.3.dcn.offset_mask.bias', 'levels.0.blocks.3.dcn.value_proj.weight', 'levels.0.blocks.3.dcn.value_proj.bias', 'levels.0.blocks.3.dcn.output_proj.weight', 'levels.0.blocks.3.norm2.0.weight', 'levels.0.blocks.3.norm2.0.bias', 'levels.0.blocks.3.mlp.fc1.weight', 'levels.0.blocks.3.mlp.fc1.bias', 'levels.0.blocks.3.mlp.fc2.weight', 'levels.0.norm.0.weight', 'levels.0.norm.0.bias', 'levels.0.downsample.conv.weight', 'levels.0.downsample.norm.1.weight', 'levels.0.downsample.norm.1.bias', 'levels.1.blocks.0.norm1.0.weight', 'levels.1.blocks.0.norm1.0.bias', 'levels.1.blocks.0.dcn.offset_mask.weight', 'levels.1.blocks.0.dcn.offset_mask.bias', 'levels.1.blocks.0.dcn.value_proj.weight', 'levels.1.blocks.0.dcn.value_proj.bias', 'levels.1.blocks.0.dcn.output_proj.weight', 'levels.1.blocks.0.norm2.0.weight', 'levels.1.blocks.0.norm2.0.bias', 'levels.1.blocks.0.mlp.fc1.weight', 'levels.1.blocks.0.mlp.fc1.bias', 'levels.1.blocks.0.mlp.fc2.weight', 'levels.1.blocks.1.norm1.0.weight', 'levels.1.blocks.1.norm1.0.bias', 'levels.1.blocks.1.dcn.offset_mask.weight', 'levels.1.blocks.1.dcn.offset_mask.bias', 'levels.1.blocks.1.dcn.value_proj.weight', 'levels.1.blocks.1.dcn.value_proj.bias', 'levels.1.blocks.1.dcn.output_proj.weight', 'levels.1.blocks.1.norm2.0.weight', 'levels.1.blocks.1.norm2.0.bias', 'levels.1.blocks.1.mlp.fc1.weight', 'levels.1.blocks.1.mlp.fc1.bias', 'levels.1.blocks.1.mlp.fc2.weight', 'levels.1.blocks.2.norm1.0.weight', 'levels.1.blocks.2.norm1.0.bias', 'levels.1.blocks.2.dcn.offset_mask.weight', 'levels.1.blocks.2.dcn.offset_mask.bias', 'levels.1.blocks.2.dcn.value_proj.weight', 'levels.1.blocks.2.dcn.value_proj.bias', 'levels.1.blocks.2.dcn.output_proj.weight', 'levels.1.blocks.2.norm2.0.weight', 'levels.1.blocks.2.norm2.0.bias', 'levels.1.blocks.2.mlp.fc1.weight', 'levels.1.blocks.2.mlp.fc1.bias', 'levels.1.blocks.2.mlp.fc2.weight', 'levels.1.blocks.3.norm1.0.weight', 'levels.1.blocks.3.norm1.0.bias', 'levels.1.blocks.3.dcn.offset_mask.weight', 'levels.1.blocks.3.dcn.offset_mask.bias', 'levels.1.blocks.3.dcn.value_proj.weight', 'levels.1.blocks.3.dcn.value_proj.bias', 'levels.1.blocks.3.dcn.output_proj.weight', 'levels.1.blocks.3.norm2.0.weight', 'levels.1.blocks.3.norm2.0.bias', 'levels.1.blocks.3.mlp.fc1.weight', 'levels.1.blocks.3.mlp.fc1.bias', 'levels.1.blocks.3.mlp.fc2.weight', 'levels.1.norm.0.weight', 'levels.1.norm.0.bias', 'levels.1.downsample.conv.weight', 'levels.1.downsample.norm.1.weight', 'levels.1.downsample.norm.1.bias', 'levels.2.blocks.0.norm1.0.weight', 'levels.2.blocks.0.norm1.0.bias', 'levels.2.blocks.0.dcn.offset_mask.weight', 'levels.2.blocks.0.dcn.offset_mask.bias', 'levels.2.blocks.0.dcn.value_proj.weight', 'levels.2.blocks.0.dcn.value_proj.bias', 'levels.2.blocks.0.dcn.output_proj.weight', 'levels.2.blocks.0.norm2.0.weight', 'levels.2.blocks.0.norm2.0.bias', 'levels.2.blocks.0.mlp.fc1.weight', 'levels.2.blocks.0.mlp.fc1.bias', 'levels.2.blocks.0.mlp.fc2.weight', 'levels.2.blocks.1.norm1.0.weight', 'levels.2.blocks.1.norm1.0.bias', 'levels.2.blocks.1.dcn.offset_mask.weight', 'levels.2.blocks.1.dcn.offset_mask.bias', 'levels.2.blocks.1.dcn.value_proj.weight', 'levels.2.blocks.1.dcn.value_proj.bias', 'levels.2.blocks.1.dcn.output_proj.weight', 'levels.2.blocks.1.norm2.0.weight', 'levels.2.blocks.1.norm2.0.bias', 'levels.2.blocks.1.mlp.fc1.weight', 'levels.2.blocks.1.mlp.fc1.bias', 'levels.2.blocks.1.mlp.fc2.weight', 'levels.2.blocks.2.norm1.0.weight', 'levels.2.blocks.2.norm1.0.bias', 'levels.2.blocks.2.dcn.offset_mask.weight', 'levels.2.blocks.2.dcn.offset_mask.bias', 'levels.2.blocks.2.dcn.value_proj.weight', 'levels.2.blocks.2.dcn.value_proj.bias', 'levels.2.blocks.2.dcn.output_proj.weight', 'levels.2.blocks.2.norm2.0.weight', 'levels.2.blocks.2.norm2.0.bias', 'levels.2.blocks.2.mlp.fc1.weight', 'levels.2.blocks.2.mlp.fc1.bias', 'levels.2.blocks.2.mlp.fc2.weight', 'levels.2.blocks.3.norm1.0.weight', 'levels.2.blocks.3.norm1.0.bias', 'levels.2.blocks.3.dcn.offset_mask.weight', 'levels.2.blocks.3.dcn.offset_mask.bias', 'levels.2.blocks.3.dcn.value_proj.weight', 'levels.2.blocks.3.dcn.value_proj.bias', 'levels.2.blocks.3.dcn.output_proj.weight', 'levels.2.blocks.3.norm2.0.weight', 'levels.2.blocks.3.norm2.0.bias', 'levels.2.blocks.3.mlp.fc1.weight', 'levels.2.blocks.3.mlp.fc1.bias', 'levels.2.blocks.3.mlp.fc2.weight', 'levels.2.blocks.4.norm1.0.weight', 'levels.2.blocks.4.norm1.0.bias', 'levels.2.blocks.4.dcn.offset_mask.weight', 'levels.2.blocks.4.dcn.offset_mask.bias', 'levels.2.blocks.4.dcn.value_proj.weight', 'levels.2.blocks.4.dcn.value_proj.bias', 'levels.2.blocks.4.dcn.output_proj.weight', 'levels.2.blocks.4.norm2.0.weight', 'levels.2.blocks.4.norm2.0.bias', 'levels.2.blocks.4.mlp.fc1.weight', 'levels.2.blocks.4.mlp.fc1.bias', 'levels.2.blocks.4.mlp.fc2.weight', 'levels.2.blocks.5.norm1.0.weight', 'levels.2.blocks.5.norm1.0.bias', 'levels.2.blocks.5.dcn.offset_mask.weight', 'levels.2.blocks.5.dcn.offset_mask.bias', 'levels.2.blocks.5.dcn.value_proj.weight', 'levels.2.blocks.5.dcn.value_proj.bias', 'levels.2.blocks.5.dcn.output_proj.weight', 'levels.2.blocks.5.norm2.0.weight', 'levels.2.blocks.5.norm2.0.bias', 'levels.2.blocks.5.mlp.fc1.weight', 'levels.2.blocks.5.mlp.fc1.bias', 'levels.2.blocks.5.mlp.fc2.weight', 'levels.2.blocks.6.norm1.0.weight', 'levels.2.blocks.6.norm1.0.bias', 'levels.2.blocks.6.dcn.offset_mask.weight', 'levels.2.blocks.6.dcn.offset_mask.bias', 'levels.2.blocks.6.dcn.value_proj.weight', 'levels.2.blocks.6.dcn.value_proj.bias', 'levels.2.blocks.6.dcn.output_proj.weight', 'levels.2.blocks.6.norm2.0.weight', 'levels.2.blocks.6.norm2.0.bias', 'levels.2.blocks.6.mlp.fc1.weight', 'levels.2.blocks.6.mlp.fc1.bias', 'levels.2.blocks.6.mlp.fc2.weight', 'levels.2.blocks.7.norm1.0.weight', 'levels.2.blocks.7.norm1.0.bias', 'levels.2.blocks.7.dcn.offset_mask.weight', 'levels.2.blocks.7.dcn.offset_mask.bias', 'levels.2.blocks.7.dcn.value_proj.weight', 'levels.2.blocks.7.dcn.value_proj.bias', 'levels.2.blocks.7.dcn.output_proj.weight', 'levels.2.blocks.7.norm2.0.weight', 'levels.2.blocks.7.norm2.0.bias', 'levels.2.blocks.7.mlp.fc1.weight', 'levels.2.blocks.7.mlp.fc1.bias', 'levels.2.blocks.7.mlp.fc2.weight', 'levels.2.blocks.8.norm1.0.weight', 'levels.2.blocks.8.norm1.0.bias', 'levels.2.blocks.8.dcn.offset_mask.weight', 'levels.2.blocks.8.dcn.offset_mask.bias', 'levels.2.blocks.8.dcn.value_proj.weight', 'levels.2.blocks.8.dcn.value_proj.bias', 'levels.2.blocks.8.dcn.output_proj.weight', 'levels.2.blocks.8.norm2.0.weight', 'levels.2.blocks.8.norm2.0.bias', 'levels.2.blocks.8.mlp.fc1.weight', 'levels.2.blocks.8.mlp.fc1.bias', 'levels.2.blocks.8.mlp.fc2.weight', 'levels.2.blocks.9.norm1.0.weight', 'levels.2.blocks.9.norm1.0.bias', 'levels.2.blocks.9.dcn.offset_mask.weight', 'levels.2.blocks.9.dcn.offset_mask.bias', 'levels.2.blocks.9.dcn.value_proj.weight', 'levels.2.blocks.9.dcn.value_proj.bias', 'levels.2.blocks.9.dcn.output_proj.weight', 'levels.2.blocks.9.norm2.0.weight', 'levels.2.blocks.9.norm2.0.bias', 'levels.2.blocks.9.mlp.fc1.weight', 'levels.2.blocks.9.mlp.fc1.bias', 'levels.2.blocks.9.mlp.fc2.weight', 'levels.2.blocks.10.norm1.0.weight', 'levels.2.blocks.10.norm1.0.bias', 'levels.2.blocks.10.dcn.offset_mask.weight', 'levels.2.blocks.10.dcn.offset_mask.bias', 'levels.2.blocks.10.dcn.value_proj.weight', 'levels.2.blocks.10.dcn.value_proj.bias', 'levels.2.blocks.10.dcn.output_proj.weight', 'levels.2.blocks.10.norm2.0.weight', 'levels.2.blocks.10.norm2.0.bias', 'levels.2.blocks.10.mlp.fc1.weight', 'levels.2.blocks.10.mlp.fc1.bias', 'levels.2.blocks.10.mlp.fc2.weight', 'levels.2.blocks.11.norm1.0.weight', 'levels.2.blocks.11.norm1.0.bias', 'levels.2.blocks.11.dcn.offset_mask.weight', 'levels.2.blocks.11.dcn.offset_mask.bias', 'levels.2.blocks.11.dcn.value_proj.weight', 'levels.2.blocks.11.dcn.value_proj.bias', 'levels.2.blocks.11.dcn.output_proj.weight', 'levels.2.blocks.11.norm2.0.weight', 'levels.2.blocks.11.norm2.0.bias', 'levels.2.blocks.11.mlp.fc1.weight', 'levels.2.blocks.11.mlp.fc1.bias', 'levels.2.blocks.11.mlp.fc2.weight', 'levels.2.blocks.12.norm1.0.weight', 'levels.2.blocks.12.norm1.0.bias', 'levels.2.blocks.12.dcn.offset_mask.weight', 'levels.2.blocks.12.dcn.offset_mask.bias', 'levels.2.blocks.12.dcn.value_proj.weight', 'levels.2.blocks.12.dcn.value_proj.bias', 'levels.2.blocks.12.dcn.output_proj.weight', 'levels.2.blocks.12.norm2.0.weight', 'levels.2.blocks.12.norm2.0.bias', 'levels.2.blocks.12.mlp.fc1.weight', 'levels.2.blocks.12.mlp.fc1.bias', 'levels.2.blocks.12.mlp.fc2.weight', 'levels.2.blocks.13.norm1.0.weight', 'levels.2.blocks.13.norm1.0.bias', 'levels.2.blocks.13.dcn.offset_mask.weight', 'levels.2.blocks.13.dcn.offset_mask.bias', 'levels.2.blocks.13.dcn.value_proj.weight', 'levels.2.blocks.13.dcn.value_proj.bias', 'levels.2.blocks.13.dcn.output_proj.weight', 'levels.2.blocks.13.norm2.0.weight', 'levels.2.blocks.13.norm2.0.bias', 'levels.2.blocks.13.mlp.fc1.weight', 'levels.2.blocks.13.mlp.fc1.bias', 'levels.2.blocks.13.mlp.fc2.weight', 'levels.2.blocks.14.norm1.0.weight', 'levels.2.blocks.14.norm1.0.bias', 'levels.2.blocks.14.dcn.offset_mask.weight', 'levels.2.blocks.14.dcn.offset_mask.bias', 'levels.2.blocks.14.dcn.value_proj.weight', 'levels.2.blocks.14.dcn.value_proj.bias', 'levels.2.blocks.14.dcn.output_proj.weight', 'levels.2.blocks.14.norm2.0.weight', 'levels.2.blocks.14.norm2.0.bias', 'levels.2.blocks.14.mlp.fc1.weight', 'levels.2.blocks.14.mlp.fc1.bias', 'levels.2.blocks.14.mlp.fc2.weight', 'levels.2.blocks.15.norm1.0.weight', 'levels.2.blocks.15.norm1.0.bias', 'levels.2.blocks.15.dcn.offset_mask.weight', 'levels.2.blocks.15.dcn.offset_mask.bias', 'levels.2.blocks.15.dcn.value_proj.weight', 'levels.2.blocks.15.dcn.value_proj.bias', 'levels.2.blocks.15.dcn.output_proj.weight', 'levels.2.blocks.15.norm2.0.weight', 'levels.2.blocks.15.norm2.0.bias', 'levels.2.blocks.15.mlp.fc1.weight', 'levels.2.blocks.15.mlp.fc1.bias', 'levels.2.blocks.15.mlp.fc2.weight', 'levels.2.blocks.16.norm1.0.weight', 'levels.2.blocks.16.norm1.0.bias', 'levels.2.blocks.16.dcn.offset_mask.weight', 'levels.2.blocks.16.dcn.offset_mask.bias', 'levels.2.blocks.16.dcn.value_proj.weight', 'levels.2.blocks.16.dcn.value_proj.bias', 'levels.2.blocks.16.dcn.output_proj.weight', 'levels.2.blocks.16.norm2.0.weight', 'levels.2.blocks.16.norm2.0.bias', 'levels.2.blocks.16.mlp.fc1.weight', 'levels.2.blocks.16.mlp.fc1.bias', 'levels.2.blocks.16.mlp.fc2.weight', 'levels.2.blocks.17.norm1.0.weight', 'levels.2.blocks.17.norm1.0.bias', 'levels.2.blocks.17.dcn.offset_mask.weight', 'levels.2.blocks.17.dcn.offset_mask.bias', 'levels.2.blocks.17.dcn.value_proj.weight', 'levels.2.blocks.17.dcn.value_proj.bias', 'levels.2.blocks.17.dcn.output_proj.weight', 'levels.2.blocks.17.norm2.0.weight', 'levels.2.blocks.17.norm2.0.bias', 'levels.2.blocks.17.mlp.fc1.weight', 'levels.2.blocks.17.mlp.fc1.bias', 'levels.2.blocks.17.mlp.fc2.weight', 'levels.2.norm.0.weight', 'levels.2.norm.0.bias', 'levels.2.downsample.conv.weight', 'levels.2.downsample.norm.1.weight', 'levels.2.downsample.norm.1.bias', 'levels.3.blocks.0.norm1.0.weight', 'levels.3.blocks.0.norm1.0.bias', 'levels.3.blocks.0.dcn.offset_mask.weight', 'levels.3.blocks.0.dcn.offset_mask.bias', 'levels.3.blocks.0.dcn.value_proj.weight', 'levels.3.blocks.0.dcn.value_proj.bias', 'levels.3.blocks.0.dcn.output_proj.weight', 'levels.3.blocks.0.norm2.0.weight', 'levels.3.blocks.0.norm2.0.bias', 'levels.3.blocks.0.mlp.fc1.weight', 'levels.3.blocks.0.mlp.fc1.bias', 'levels.3.blocks.0.mlp.fc2.weight', 'levels.3.blocks.1.norm1.0.weight', 'levels.3.blocks.1.norm1.0.bias', 'levels.3.blocks.1.dcn.offset_mask.weight', 'levels.3.blocks.1.dcn.offset_mask.bias', 'levels.3.blocks.1.dcn.value_proj.weight', 'levels.3.blocks.1.dcn.value_proj.bias', 'levels.3.blocks.1.dcn.output_proj.weight', 'levels.3.blocks.1.norm2.0.weight', 'levels.3.blocks.1.norm2.0.bias', 'levels.3.blocks.1.mlp.fc1.weight', 'levels.3.blocks.1.mlp.fc1.bias', 'levels.3.blocks.1.mlp.fc2.weight', 'levels.3.blocks.2.norm1.0.weight', 'levels.3.blocks.2.norm1.0.bias', 'levels.3.blocks.2.dcn.offset_mask.weight', 'levels.3.blocks.2.dcn.offset_mask.bias', 'levels.3.blocks.2.dcn.value_proj.weight', 'levels.3.blocks.2.dcn.value_proj.bias', 'levels.3.blocks.2.dcn.output_proj.weight', 'levels.3.blocks.2.norm2.0.weight', 'levels.3.blocks.2.norm2.0.bias', 'levels.3.blocks.2.mlp.fc1.weight', 'levels.3.blocks.2.mlp.fc1.bias', 'levels.3.blocks.2.mlp.fc2.weight', 'levels.3.blocks.3.norm1.0.weight', 'levels.3.blocks.3.norm1.0.bias', 'levels.3.blocks.3.dcn.offset_mask.weight', 'levels.3.blocks.3.dcn.offset_mask.bias', 'levels.3.blocks.3.dcn.value_proj.weight', 'levels.3.blocks.3.dcn.value_proj.bias', 'levels.3.blocks.3.dcn.output_proj.weight', 'levels.3.blocks.3.norm2.0.weight', 'levels.3.blocks.3.norm2.0.bias', 'levels.3.blocks.3.mlp.fc1.weight', 'levels.3.blocks.3.mlp.fc1.bias', 'levels.3.blocks.3.mlp.fc2.weight', 'levels.3.norm.0.weight', 'levels.3.norm.0.bias', 'conv_head.0.weight', 'conv_head.1.0.weight', 'conv_head.1.0.bias', 'conv_head.1.0.running_mean', 'conv_head.1.0.running_var', 'conv_head.1.0.num_batches_tracked', 'head.weight', 'head.bias']

可以看到,我的模型的名字每一层都比预训练的权重多了一个’model.',这就导致了无法加载权重。
于是就把预训练的权重的键名加上‘model.’即可。

        model_weight= {'model.' + key: value for key, value in model_weight.items()}

然后重新调试,可以看到输出:

Missing keys: []
Unexpected keys: ['model.head.weight', 'model.head.bias']

可以看到Missing keys为空,所以需要的权重全部加载了。


http://www.kler.cn/a/421240.html

相关文章:

  • LeetCode 64. 最小路径和(HOT100)
  • Flutter 之 InheritedWidget
  • 「Mac畅玩鸿蒙与硬件38」UI互动应用篇15 - 猜数字增强版
  • 十、软件设计架构-微服务-服务调用Dubbo
  • redis 快 原因 详解
  • 在21世纪的我用C语言探寻世界本质——字符函数和字符串函数(2)
  • 【C++笔记】map和set的使用
  • 003-SpringBoot整合Pagehelper
  • 后端-mybatis的一对多
  • iptables 防火墙 附实验:三台虚拟机模拟内网连接外网
  • 多模态遥感技术:智慧城市更新与表达的新路径
  • 容器化实践:优化DevOps环境下的容器交付流程
  • 【Leetcode】27.移除元素
  • 【大数据学习 | 面经】Spark 3.x 中的AQE(自适应查询执行)
  • Vue教程|搭建vue项目|Vue-CLI新版脚手架
  • 【HarmonyOS】鸿蒙应用使用lottie动画
  • 【SpringBoot】29 基于HttpClient的Http工具类
  • [自然语言处理] NLP-RNN及其变体-干货
  • Python 网络爬虫入门全知道
  • 分布式推理框架 xDit
  • 【threejs】实现不同动画的播放和平滑切换
  • (长期更新)《零基础入门 ArcGIS(ArcMap) 》实验三----学校选址与路径规划(超超超详细!!!)
  • <数据集>路面坑洼识别数据集<目标检测>
  • 王道操作系统目录以及学习感受和总结
  • 《向量数据库指南》——Florence:多模态应用的新基石!
  • 2024年大热,Access平替升级方案,也适合Excel用户