在pytorch中加载模型权重时出错

vof42yt1  于 2021-08-25  发布在  Java
关注(0)|答案(0)|浏览(315)

我的模型在一个.pth文件中,为了加载模型,我编写了以下代码。

model = torch.jit.load('/content/drive/MyDrive/fod.pth')
torch.save(model.state_dict(), 'weights.pt')
u2net = U2NETP()
u2net.eval()
u2net.load_state_dict(torch.load('/content/weights.pt'), strict = False)

u2netp是网络架构,但这里的问题是,我得到了一个类似这样的错误

_IncompatibleKeys(missing_keys=['stage1.rebnconvin.bn_s1.running_mean', 'stage1.rebnconvin.bn_s1.running_var', 'stage1.rebnconv1.bn_s1.running_mean', 'stage1.rebnconv1.bn_s1.running_var', 'stage1.rebnconv2.bn_s1.running_mean', 'stage1.rebnconv2.bn_s1.running_var', 'stage1.rebnconv3.bn_s1.running_mean', 'stage1.rebnconv3.bn_s1.running_var', 'stage1.rebnconv4.bn_s1.running_mean', 'stage1.rebnconv4.bn_s1.running_var', 'stage1.rebnconv5.bn_s1.running_mean', 'stage1.rebnconv5.bn_s1.running_var', 'stage1.rebnconv6.bn_s1.running_mean', 'stage1.rebnconv6.bn_s1.running_var', 'stage1.rebnconv7.bn_s1.running_mean', 'stage1.rebnconv7.bn_s1.running_var', 'stage1.rebnconv6d.bn_s1.running_mean', 'stage1.rebnconv6d.bn_s1.running_var', 'stage1.rebnconv5d.bn_s1.running_mean', 'stage1.rebnconv5d.bn_s1.running_var', 'stage1.rebnconv4d.bn_s1.running_mean', 'stage1.rebnconv4d.bn_s1.running_var', 'stage1.rebnconv3d.bn_s1.running_mean', 'stage1.rebnconv3d.bn_s1.running_var', 'stage1.rebnconv2d.bn_s1.running_mean', 'stage1.rebnconv2d.bn_s1.running_var', 'stage1.rebnconv1d.bn_s1.running_mean', 'stage1.rebnconv1d.bn_s1.running_var', 'stage2.rebnconvin.bn_s1.running_mean', 'stage2.rebnconvin.bn_s1.running_var', 'stage2.rebnconv1.bn_s1.running_mean', 'stage2.rebnconv1.bn_s1.running_var', 'stage2.rebnconv2.bn_s1.running_mean', 'stage2.rebnconv2.bn_s1.running_var', 'stage2.rebnconv3.bn_s1.running_mean', 'stage2.rebnconv3.bn_s1.running_var', 'stage2.rebnconv4.bn_s1.running_mean', 'stage2.rebnconv4.bn_s1.running_var', 'stage2.rebnconv5.bn_s1.running_mean', 'stage2.rebnconv5.bn_s1.running_var', 'stage2.rebnconv6.bn_s1.running_mean', 'stage2.rebnconv6.bn_s1.running_var', 'stage2.rebnconv5d.bn_s1.running_mean', 'stage2.rebnconv5d.bn_s1.running_var', 'stage2.rebnconv4d.bn_s1.running_mean', 'stage2.rebnconv4d.bn_s1.running_var', 'stage2.rebnconv3d.bn_s1.running_mean', 'stage2.rebnconv3d.bn_s1.running_var', 'stage2.rebnconv2d.bn_s1.running_mean', 'stage2.rebnconv2d.bn_s1.running_var', 'stage2.rebnconv1d.bn_s1.running_mean', 'stage2.rebnconv1d.bn_s1.running_var', 'stage3.rebnconvin.bn_s1.running_mean', 'stage3.rebnconvin.bn_s1.running_var', 'stage3.rebnconv1.bn_s1.running_mean', 'stage3.rebnconv1.bn_s1.running_var', 'stage3.rebnconv2.bn_s1.running_mean', 'stage3.rebnconv2.bn_s1.running_var', 'stage3.rebnconv3.bn_s1.running_mean', 'stage3.rebnconv3.bn_s1.running_var', 'stage3.rebnconv4.bn_s1.running_mean', 'stage3.rebnconv4.bn_s1.running_var', 'stage3.rebnconv5.bn_s1.running_mean', 'stage3.rebnconv5.bn_s1.running_var', 'stage3.rebnconv4d.bn_s1.running_mean', 'stage3.rebnconv4d.bn_s1.running_var', 'stage3.rebnconv3d.bn_s1.running_mean', 'stage3.rebnconv3d.bn_s1.running_var', 'stage3.rebnconv2d.bn_s1.running_mean', 'stage3.rebnconv2d.bn_s1.running_var', 'stage3.rebnconv1d.bn_s1.running_mean', 'stage3.rebnconv1d.bn_s1.running_var', 'stage4.rebnconvin.bn_s1.running_mean', 'stage4.rebnconvin.bn_s1.running_var', 'stage4.rebnconv1.bn_s1.running_mean', 'stage4.rebnconv1.bn_s1.running_var', 'stage4.rebnconv2.bn_s1.running_mean', 'stage4.rebnconv2.bn_s1.running_var', 'stage4.rebnconv3.bn_s1.running_mean', 'stage4.rebnconv3.bn_s1.running_var', 'stage4.rebnconv4.bn_s1.running_mean', 'stage4.rebnconv4.bn_s1.running_var', 'stage4.rebnconv3d.bn_s1.running_mean', 'stage4.rebnconv3d.bn_s1.running_var', 'stage4.rebnconv2d.bn_s1.running_mean', 'stage4.rebnconv2d.bn_s1.running_var', 'stage4.rebnconv1d.bn_s1.running_mean', 'stage4.rebnconv1d.bn_s1.running_var', 'stage5.rebnconvin.bn_s1.running_mean', 'stage5.rebnconvin.bn_s1.running_var', 'stage5.rebnconv1.bn_s1.running_mean', 'stage5.rebnconv1.bn_s1.running_var', 'stage5.rebnconv2.bn_s1.running_mean', 'stage5.rebnconv2.bn_s1.running_var', 'stage5.rebnconv3.bn_s1.running_mean', 'stage5.rebnconv3.bn_s1.running_var', 'stage5.rebnconv4.bn_s1.running_mean', 'stage5.rebnconv4.bn_s1.running_var', 'stage5.rebnconv3d.bn_s1.running_mean', 'stage5.rebnconv3d.bn_s1.running_var', 'stage5.rebnconv2d.bn_s1.running_mean', 'stage5.rebnconv2d.bn_s1.running_var', 'stage5.rebnconv1d.bn_s1.running_mean', 'stage5.rebnconv1d.bn_s1.running_var', 'stage6.rebnconvin.bn_s1.running_mean', 'stage6.rebnconvin.bn_s1.running_var', 'stage6.rebnconv1.bn_s1.running_mean', 'stage6.rebnconv1.bn_s1.running_var', 'stage6.rebnconv2.bn_s1.running_mean', 'stage6.rebnconv2.bn_s1.running_var', 'stage6.rebnconv3.bn_s1.running_mean', 'stage6.rebnconv3.bn_s1.running_var', 'stage6.rebnconv4.bn_s1.running_mean', 'stage6.rebnconv4.bn_s1.running_var', 'stage6.rebnconv3d.bn_s1.running_mean', 'stage6.rebnconv3d.bn_s1.running_var', 'stage6.rebnconv2d.bn_s1.running_mean', 'stage6.rebnconv2d.bn_s1.running_var', 'stage6.rebnconv1d.bn_s1.running_mean', 'stage6.rebnconv1d.bn_s1.running_var', 'stage5d.rebnconvin.bn_s1.running_mean', 'stage5d.rebnconvin.bn_s1.running_var', 'stage5d.rebnconv1.bn_s1.running_mean', 'stage5d.rebnconv1.bn_s1.running_var', 'stage5d.rebnconv2.bn_s1.running_mean', 'stage5d.rebnconv2.bn_s1.running_var', 'stage5d.rebnconv3.bn_s1.running_mean', 'stage5d.rebnconv3.bn_s1.running_var', 'stage5d.rebnconv4.bn_s1.running_mean', 'stage5d.rebnconv4.bn_s1.running_var', 'stage5d.rebnconv3d.bn_s1.running_mean', 'stage5d.rebnconv3d.bn_s1.running_var', 'stage5d.rebnconv2d.bn_s1.running_mean', 'stage5d.rebnconv2d.bn_s1.running_var', 'stage5d.rebnconv1d.bn_s1.running_mean', 'stage5d.rebnconv1d.bn_s1.running_var', 'stage4d.rebnconvin.bn_s1.running_mean', 'stage4d.rebnconvin.bn_s1.running_var', 'stage4d.rebnconv1.bn_s1.running_mean', 'stage4d.rebnconv1.bn_s1.running_var', 'stage4d.rebnconv2.bn_s1.running_mean', 'stage4d.rebnconv2.bn_s1.running_var', 'stage4d.rebnconv3.bn_s1.running_mean', 'stage4d.rebnconv3.bn_s1.running_var', 'stage4d.rebnconv4.bn_s1.running_mean', 'stage4d.rebnconv4.bn_s1.running_var', 'stage4d.rebnconv3d.bn_s1.running_mean', 'stage4d.rebnconv3d.bn_s1.running_var', 'stage4d.rebnconv2d.bn_s1.running_mean', 'stage4d.rebnconv2d.bn_s1.running_var', 'stage4d.rebnconv1d.bn_s1.running_mean', 'stage4d.rebnconv1d.bn_s1.running_var', 'stage3d.rebnconvin.bn_s1.running_mean', 'stage3d.rebnconvin.bn_s1.running_var', 'stage3d.rebnconv1.bn_s1.running_mean', 'stage3d.rebnconv1.bn_s1.running_var', 'stage3d.rebnconv2.bn_s1.running_mean', 'stage3d.rebnconv2.bn_s1.running_var', 'stage3d.rebnconv3.bn_s1.running_mean', 'stage3d.rebnconv3.bn_s1.running_var', 'stage3d.rebnconv4.bn_s1.running_mean', 'stage3d.rebnconv4.bn_s1.running_var', 'stage3d.rebnconv5.bn_s1.running_mean', 'stage3d.rebnconv5.bn_s1.running_var', 'stage3d.rebnconv4d.bn_s1.running_mean', 'stage3d.rebnconv4d.bn_s1.running_var', 'stage3d.rebnconv3d.bn_s1.running_mean', 'stage3d.rebnconv3d.bn_s1.running_var', 'stage3d.rebnconv2d.bn_s1.running_mean', 'stage3d.rebnconv2d.bn_s1.running_var', 'stage3d.rebnconv1d.bn_s1.running_mean', 'stage3d.rebnconv1d.bn_s1.running_var', 'stage2d.rebnconvin.bn_s1.running_mean', 'stage2d.rebnconvin.bn_s1.running_var', 'stage2d.rebnconv1.bn_s1.running_mean', 'stage2d.rebnconv1.bn_s1.running_var', 'stage2d.rebnconv2.bn_s1.running_mean', 'stage2d.rebnconv2.bn_s1.running_var', 'stage2d.rebnconv3.bn_s1.running_mean', 'stage2d.rebnconv3.bn_s1.running_var', 'stage2d.rebnconv4.bn_s1.running_mean', 'stage2d.rebnconv4.bn_s1.running_var', 'stage2d.rebnconv5.bn_s1.running_mean', 'stage2d.rebnconv5.bn_s1.running_var', 'stage2d.rebnconv6.bn_s1.running_mean', 'stage2d.rebnconv6.bn_s1.running_var', 'stage2d.rebnconv5d.bn_s1.running_mean', 'stage2d.rebnconv5d.bn_s1.running_var', 'stage2d.rebnconv4d.bn_s1.running_mean', 'stage2d.rebnconv4d.bn_s1.running_var', 'stage2d.rebnconv3d.bn_s1.running_mean', 'stage2d.rebnconv3d.bn_s1.running_var', 'stage2d.rebnconv2d.bn_s1.running_mean', 'stage2d.rebnconv2d.bn_s1.running_var', 'stage2d.rebnconv1d.bn_s1.running_mean', 'stage2d.rebnconv1d.bn_s1.running_var', 'stage1d.rebnconvin.bn_s1.running_mean', 'stage1d.rebnconvin.bn_s1.running_var', 'stage1d.rebnconv1.bn_s1.running_mean', 'stage1d.rebnconv1.bn_s1.running_var', 'stage1d.rebnconv2.bn_s1.running_mean', 'stage1d.rebnconv2.bn_s1.running_var', 'stage1d.rebnconv3.bn_s1.running_mean', 'stage1d.rebnconv3.bn_s1.running_var', 'stage1d.rebnconv4.bn_s1.running_mean', 'stage1d.rebnconv4.bn_s1.running_var', 'stage1d.rebnconv5.bn_s1.running_mean', 'stage1d.rebnconv5.bn_s1.running_var', 'stage1d.rebnconv6.bn_s1.running_mean', 'stage1d.rebnconv6.bn_s1.running_var', 'stage1d.rebnconv7.bn_s1.running_mean', 'stage1d.rebnconv7.bn_s1.running_var', 'stage1d.rebnconv6d.bn_s1.running_mean', 'stage1d.rebnconv6d.bn_s1.running_var', 'stage1d.rebnconv5d.bn_s1.running_mean', 'stage1d.rebnconv5d.bn_s1.running_var', 'stage1d.rebnconv4d.bn_s1.running_mean', 'stage1d.rebnconv4d.bn_s1.running_var', 'stage1d.rebnconv3d.bn_s1.running_mean', 'stage1d.rebnconv3d.bn_s1.running_var', 'stage1d.rebnconv2d.bn_s1.running_mean', 'stage1d.rebnconv2d.bn_s1.running_var', 'stage1d.rebnconv1d.bn_s1.running_mean', 'stage1d.rebnconv1d.bn_s1.running_var'], unexpected_keys=[])

for param_tensor in sd:
    print(param_tensor, "\t", model.state_dict()[param_tensor].size())

我用这个代码来打印重量。似乎它包含权重和偏差关键点,但不运行均值/方差

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题