wgan pytorch 中调用模型的时候报错
File "/home/aistudio/external-libraries/torch/nn/modules/module.py", line 2215, in load_state_dict
raise RuntimeError('Error(s) in loading state_dict for {}:\n\t{}'.format(
RuntimeError: Error(s) in loading state_dict for Generator:
Missing key(s) in state_dict: "fc4.weight", "fc4.bias", "fc5.weight", "fc5.bias".
size mismatch for fc3.weight: copying a param with shape torch.Size([64, 256]) from checkpoint, the shape in current model is torch.Size([128, 256]).
size mismatch for fc3.bias: copying a param with shape torch.Size([64]) from checkpoint, the shape in current model is torch.Size([128]).
解决办法,bug, 保存模型参数的时候 ,生成器和判断器名字换了下
# 保存模型参数
torch.save(self.g.state_dict(), 'ckpoints/wgan/wgan_2_16_256_generator_state_dict.pth')
torch.save(self.c.state_dict(), 'ckpoints/wgan/wgan_2_16_256_critic_state_dict.pth')
保证对应上就可以了 ,生成器,加载生成器的模型即可