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

保存模型权重 #13

Open
zhoushen1 opened this issue Dec 20, 2024 · 2 comments
Open

保存模型权重 #13

zhoushen1 opened this issue Dec 20, 2024 · 2 comments

Comments

@zhoushen1
Copy link

训练的时候似乎是保存的.ckpt,测试的时候是使用的.pth,请问这是正常的吗?
这将会导致权重加载不上去。

@Ephemeral182
Copy link
Owner

Hi, we utilize PyTorch_lightning for training, where checkpoints are saved with other hyperparameters in *.ckpt file. So, you need to first take out the checkpoint of the model from the .ckpt file (just like my .pth checkpoints). Here is the code for this operation:

ckpt = torch.load('your ***.ckpt**')
new_state_dict = OrderedDict()
    for k in ckpt['state_dict']:
                    print(k)
                    if k[:6] != 'model.':
                        continue
                    name = k[6:]
                    new_state_dict[name] = ckpt['state_dict'][k]
**your model**.load_state_dict(new_state_dict,strict=False)

@zhoushen1
Copy link
Author

谢谢您!

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