Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

关于加载g_ghost_regnetx_032预训练权重的问题 #282

Open
linyu17 opened this issue Nov 18, 2024 · 1 comment
Open

关于加载g_ghost_regnetx_032预训练权重的问题 #282

linyu17 opened this issue Nov 18, 2024 · 1 comment

Comments

@linyu17
Copy link

linyu17 commented Nov 18, 2024

您好,我在使用g_ghost_regnetx_032作为特征提取网络训练自己的分类任务时,我想加载预训练模型g_ghost_regnet_3.2g_77.8.pth,使用到的代码如下:

import torch
from models.g_ghost_renet import g_ghost_regnetx_032
model = g_ghost_regnetx_032()
model.load_state_dict(torch.load('./weights/g_ghost_regnet_3.2g_77.8.pth'))
print(model)

出现了如下报错:
RuntimeError: Error(s) in loading state_dict for GGhostRegNet:
Missing key(s) in state_dict: "conv1.weight", "bn1.weight", "bn1.bias", "bn1.running_mean", "bn1.running_var", "layer1.0.conv1.weight", "layer1.0.bn1.weight", "layer1.0.bn1.bias", "layer1.0.bn1.running_mean", "layer1.0.bn1.running_var", 。。。。。
Unexpected key(s) in state_dict: "module.conv1.weight", "module.bn1.weight", "module.bn1.bias", "module.bn1.running_mean", "module.bn1.

请问这是不是因为pytorch版本不匹配的问题,我需要如何才能使用到预训练模型呢,期待您的回复!

@iamhankai
Copy link
Member

改成state_dict['module']

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants