运行test报错: RuntimeError: Error(s) in loading state_dict for F3Net: Missing key(s) in state_dict:(已解)

与此博客情况相似
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 <module>
    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". 

 

 

 

 

 

 

 

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

计算机视觉-Archer

图像分割没有团队的同学可加群

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值