Error(s) in loading state_dict for ResNet 问题解决

当使用如下命令加载模型的时候,会报错,没有一些 keys:

model.load_state_dict(model_zoo.load_url(model_urls['resnet101']))
RuntimeError: Error(s) in loading state_dict for ResNet:

Missing key(s) in state_dict: "C1_down_channel.weight", "C1_down_channel.bias", "C2_down_channel.weight", "C2_down_channel.bias", 
 "C3_down_channel.weight", "C3_down_channel.bias", "C4_down_channel.weight", "C4_down_channel.bias", "C5_down_channel.weight", 
 "C5_down_channel.bias", "score_dsn1.weight", "score_dsn1.bias", "score_dsn2.weight", "score_dsn2.bias", "score_dsn3.weight", 
 "score_dsn3.bias", "score_dsn4.weight", "score_dsn4.bias", "score_dsn5.weight", "score_dsn5.bias", "score_final.weight", 
 "score_final.bias". 

则可以使用如下命令来解决,因为 load 的模型可能会缺少一些现有模型需要的东西,不使用严格的方式来 load 即可:

model.load_state_dict(model_zoo.load_url(model_urls['resnet101']), strict=False)

你可能感兴趣的:(问题记录,python,人工智能,机器学习)