与此博客情况相似
https://blog.csdn.net/qq_42052956/article/details/96423514
我的问题,更改之后果真可以解决
def initialize(self): if self.cfg.snapshot: self.load_state_dict(torch.load(self.cfg.snapshot), False) else: weight_init(self)
我的报错如下:
python test.py
Parameters...
datapath : ../data/ECSSD
snapshot : ./out/model-36
mode : test
Traceback (most recent call last):
File "test.py", line 82, in
t = Test(dataset, F3Net, path)
File "test.py", line 32, in __init__
self.net = Network(self.cfg)
File "/home/nk/zjc/PycharmProjects/F3net 7.1 _simple_x112/F3Net-master/src/net.py", line 286, in __init__
self.initialize()
File "/home/nk/zjc/PycharmProjects/F3net 7.1 _simple_x112/F3Net-master/src/net.py", line 326, in initialize
self.load_state_dict(torch.load(self.cfg.snapshot))
File "/home/nk/anaconda3/lib/python3.7/site-packages/torch/nn/modules/module.py", line 769, in load_state_dict
self.__class__.__name__, "\n\t".join(error_msgs)))
RuntimeError: Error(s) in loading state_dict for F3Net:
Missing key(s) in state_dict: "decoder2.cfm45.s_conv2h.weight", "decoder2.cfm45.s_conv2h.bias", "decoder2.cfm45.s_bn2h.weight", "decoder2.cfm45.s_bn2h.bias", "decoder2.cfm45.s_bn2h.running_mean", "decoder2.cfm45.s_bn2h.running_var", "decoder2.cfm45.e_conv2h.weight", "decoder2.cfm45.e_conv2h.bias", "decoder2.cfm45.e_bn2h.weight", "decoder2.cfm45.e_bn2h.bias", "decoder2.cfm45.e_bn2h.running_mean", "decoder2.cfm45.e_bn2h.running_var", "decoder2.cfm45.s_conv3h.weight", "decoder2.cfm45.s_conv3h.bias", "decoder2.cfm45.s_bn3h.weight", "decoder2.cfm45.s_bn3h.bias", "decoder2.cfm45.s_bn3h.running_mean", "decoder2.cfm45.s_bn3h.running_var", "decoder2.cfm45.e_conv3h.weight", "decoder2.cfm45.e_conv3h.bias", "decoder2.cfm45.e_bn3h.weight", "decoder2.cfm45.e_bn3h.bias", "decoder2.cfm45.e_bn3h.running_mean", "decoder2.cfm45.e_bn3h.running_var", "decoder2.cfm45.conv1e.weight", "decoder2.cfm45.conv1e.bias", "decoder2.cfm45.bn1e.weight", "decoder2.cfm45.bn1e.bias", "decoder2.cfm45.bn1e.running_mean", "decoder2.cfm45.bn1e.running_var", "decoder2.cfm34.s_conv2h.weight", "decoder2.cfm34.s_conv2h.bias", "decoder2.cfm34.s_bn2h.weight", "decoder2.cfm34.s_bn2h.bias", "decoder2.cfm34.s_bn2h.running_mean", "decoder2.cfm34.s_bn2h.running_var", "decoder2.cfm34.e_conv2h.weight", "decoder2.cfm34.e_conv2h.bias", "decoder2.cfm34.e_bn2h.weight", "decoder2.cfm34.e_bn2h.bias", "decoder2.cfm34.e_bn2h.running_mean", "decoder2.cfm34.e_bn2h.running_var", "decoder2.cfm34.s_conv3h.weight", "decoder2.cfm34.s_conv3h.bias", "decoder2.cfm34.s_bn3h.weight", "decoder2.cfm34.s_bn3h.bias", "decoder2.cfm34.s_bn3h.running_mean", "decoder2.cfm34.s_bn3h.running_var", "decoder2.cfm34.e_conv3h.weight", "decoder2.cfm34.e_conv3h.bias", "decoder2.cfm34.e_bn3h.weight", "decoder2.cfm34.e_bn3h.bias", "decoder2.cfm34.e_bn3h.running_mean", "decoder2.cfm34.e_bn3h.running_var", "decoder2.cfm34.conv1e.weight", "decoder2.cfm34.conv1e.bias", "decoder2.cfm34.bn1e.weight", "decoder2.cfm34.bn1e.bias", "decoder2.cfm34.bn1e.running_mean", "decoder2.cfm34.bn1e.running_var", "decoder2.cfm23.s_conv2h.weight", "decoder2.cfm23.s_conv2h.bias", "decoder2.cfm23.s_bn2h.weight", "decoder2.cfm23.s_bn2h.bias", "decoder2.cfm23.s_bn2h.running_mean", "decoder2.cfm23.s_bn2h.running_var", "decoder2.cfm23.e_conv2h.weight", "decoder2.cfm23.e_conv2h.bias", "decoder2.cfm23.e_bn2h.weight", "decoder2.cfm23.e_bn2h.bias", "decoder2.cfm23.e_bn2h.running_mean", "decoder2.cfm23.e_bn2h.running_var", "decoder2.cfm23.s_conv3h.weight", "decoder2.cfm23.s_conv3h.bias", "decoder2.cfm23.s_bn3h.weight", "decoder2.cfm23.s_bn3h.bias", "decoder2.cfm23.s_bn3h.running_mean", "decoder2.cfm23.s_bn3h.running_var", "decoder2.cfm23.e_conv3h.weight", "decoder2.cfm23.e_conv3h.bias", "decoder2.cfm23.e_bn3h.weight", "decoder2.cfm23.e_bn3h.bias", "decoder2.cfm23.e_bn3h.running_mean", "decoder2.cfm23.e_bn3h.running_var", "decoder2.cfm23.conv1e.weight", "decoder2.cfm23.conv1e.bias", "decoder2.cfm23.bn1e.weight", "decoder2.cfm23.bn1e.bias", "decoder2.cfm23.bn1e.running_mean", "decoder2.cfm23.bn1e.running_var".
Unexpected key(s) in state_dict: "decoder2.cfm45.conv2h.weight", "decoder2.cfm45.conv2h.bias", "decoder2.cfm45.bn2h.weight", "decoder2.cfm45.bn2h.bias", "decoder2.cfm45.bn2h.running_mean", "decoder2.cfm45.bn2h.running_var", "decoder2.cfm45.bn2h.num_batches_tracked", "decoder2.cfm45.conv3h.weight", "decoder2.cfm45.conv3h.bias", "decoder2.cfm45.bn3h.weight", "decoder2.cfm45.bn3h.bias", "decoder2.cfm45.bn3h.running_mean", "decoder2.cfm45.bn3h.running_var", "decoder2.cfm45.bn3h.num_batches_tracked", "decoder2.cfm34.conv2h.weight", "decoder2.cfm34.conv2h.bias", "decoder2.cfm34.bn2h.weight", "decoder2.cfm34.bn2h.bias", "decoder2.cfm34.bn2h.running_mean", "decoder2.cfm34.bn2h.running_var", "decoder2.cfm34.bn2h.num_batches_tracked", "decoder2.cfm34.conv3h.weight", "decoder2.cfm34.conv3h.bias", "decoder2.cfm34.bn3h.weight", "decoder2.cfm34.bn3h.bias", "decoder2.cfm34.bn3h.running_mean", "decoder2.cfm34.bn3h.running_var", "decoder2.cfm34.bn3h.num_batches_tracked", "decoder2.cfm23.conv2h.weight", "decoder2.cfm23.conv2h.bias", "decoder2.cfm23.bn2h.weight", "decoder2.cfm23.bn2h.bias", "decoder2.cfm23.bn2h.running_mean", "decoder2.cfm23.bn2h.running_var", "decoder2.cfm23.bn2h.num_batches_tracked", "decoder2.cfm23.conv3h.weight", "decoder2.cfm23.conv3h.bias", "decoder2.cfm23.bn3h.weight", "decoder2.cfm23.bn3h.bias", "decoder2.cfm23.bn3h.running_mean", "decoder2.cfm23.bn3h.running_var", "decoder2.cfm23.bn3h.num_batches_tracked".