尽管加载了模型的权重,为什么模型摘要中的不可训练参数为零?
使用该命令
torch.save(model.state_dict(), 'model.pth')
我在训练模型后 保存参数。 但是,当我使用命令
model = EfficientNetModel()
MODEL_PATH = 'model.pth'
model.load_state_dict(torch.load(MODEL_PATH, map_location=map_location))
model.eval()
summary(model,(1,224,224) )
加载预训练权重时,不可训练参数的数量为 0,如所附屏幕截图所示。 截图
为什么会发生这种情况?我该如何纠正?
谢谢
I used the command
torch.save(model.state_dict(), 'model.pth')
to save the parameters after training the model.
But, when I use the commands
model = EfficientNetModel()
MODEL_PATH = 'model.pth'
model.load_state_dict(torch.load(MODEL_PATH, map_location=map_location))
model.eval()
summary(model,(1,224,224) )
to load the pre-trained weights, the number of non-trainable parameters is 0, as per the attached screenshot.
screenshot
Why is it happening and how can I rectify this?
Thank You
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在模型上保存和加载权重不会影响它们可训练的事实。不可训练的参数包含不需要梯度计算的张量,因此优化器在训练期间不会修改。
Saving and loading weights back on a model doesn't affect the fact they are trainable or not. Nontrainable params contain tensors that do not require gradient computation, and as such won't get modified by your optimizer during training.