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

Error Loading a custom trained model or resume training from a check point. #44

Closed
abhineet-pandey opened this issue Jul 14, 2022 · 3 comments

Comments

@abhineet-pandey
Copy link

File "/mnt/disk/code/AdelaiDepth/LeReS/Train/lib/utils/net_tools.py", line 44, in load_ckpt
checkpoint_state_dict_noprefix = strip_prefix_if_present(checkpoint['model_state_dict'], "module.")
KeyError: 'model_state_dict'

With resuming training from a checkpoint or loading a self trained model.

Similar KeyError when loading a demo trained model in the Minist_test script (test_depth.py or test_shape.py)

To reproduce this error just train the demo model (..Train/scripts/train_demo.py) and try loading using the inference code in the Minist_test.

Please let me know if you need more details.
Any help would be much appreciated

@guangkaixu
Copy link
Collaborator

@abhineet-pandey Hi, if you would like to load the self-trained model and do inference, you can:

depth_model.load_state_dict(strip_prefix_if_present(checkpoint['depth_model'], "module."),
modify checkpoint['depth_model'] to checkpoint['model_state_dict'] and ensure strict=False (or remove the weights of depth_model.auxi_modules).

Resuming training from a self-trained model weight seems to contain no bugs for me. Thanks for your following and please comment casually if you still suffer from some problems.

@abhineet-pandey
Copy link
Author

Thanks a lots.

@777-en
Copy link

777-en commented Dec 28, 2022

@abhineet-pandey Hi, if you would like to load the self-trained model and do inference, you can:

depth_model.load_state_dict(strip_prefix_if_present(checkpoint['depth_model'], "module."),

modify checkpoint['depth_model'] to checkpoint['model_state_dict'] and ensure strict=False (or remove the weights of depth_model.auxi_modules).
Resuming training from a self-trained model weight seems to contain no bugs for me. Thanks for your following and please comment casually if you still suffer from some problems.

Hi! Thank you for your gorgeous work. I met the same problem. Could you explain more about "ensure strict=False (or remove the weights of depth_model.auxi_modules)", what exactly should I do? @guangkaixu @abhineet-pandey

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

3 participants