尽管加载了模型的权重,为什么模型摘要中的不可训练参数为零?

发布于 2025-01-15 16:32:59 字数 455 浏览 1 评论 0原文

使用该命令

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

萤火眠眠 2025-01-22 16:32:59

在模型上保存和加载权重不会影响它们可训练的事实。不可训练的参数包含不需要梯度计算的张量,因此优化器在训练期间不会修改。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文