Closed daixiangzi closed 4 years ago
solved method: 1 model.load_state_dict(state_dice,strick=False) 2 pip3 uninstall thop or conda uninstall thop
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.
Another approach for this issue: to delete unmatched total_ops
and total_params
in state_dict's keys
checkpoint = torch.load(cpt_path)
# delete unmatched total_ops total_params
state_dict = []
for n, p in checkpoint['model'].items():
if "total_ops" not in n and "total_params" not in n:
state_dict.append((n, p))
state_dict = dict(state_dict)
model.load_state_dict(state_dict)
solved method: 1 model.load_state_dict(state_dice,strick=False) 2 pip3 uninstall thop or conda uninstall thop
a typo:
strick=False
should be strict=False
In my case, it related to thop.
@ZhangYuef your solution woked in my case
Before submitting a bug report, please be aware that your issue must be reproducible with all of the following, otherwise it is non-actionable, and we can not help you:
git fetch && git status -uno
to check andgit pull
to update repo,
test*.jpgand
results.pngfigures, or we can not help you. You can generate these with
utils.plot_results()`.🐛 Bug
A clear and concise description of what the bug is. I find total_ops is registed model,when use thop in file utils/torch_utils.py .so i load weight files ,model exist key total_ops ,but weight not exist,so come up error.
To Reproduce (REQUIRED)
Cmd:
Traceback (most recent call last): File "test.py", line 263, in opt.augment) File "test.py", line 40, in test model.load_state_dict(torch.load(weights, map_location=device)['model']) File "/anaconda3/envs/pytorch-gpu/lib/python3.7/site-packages/torch/nn/modules/module.py", line 1045, in load_state_dict self.class.name, "\n\t".join(error_msgs))) RuntimeError: Error(s) in loading state_dict for Darknet: Missing key(s) in state_dict: "total_ops", "total_params", "module_list.total_ops", "module_list.total_params", "module_list.0.total_ops"