So recently I have pulled the latest version of this repo, when I try to run detect.py with my custom weights like so:
python detect.py --weights weights/backup10.pt --cfg cfg/yolov3_test.cfg --data data/test.data
I get this output:
Traceback (most recent call last):
File "detect.py", line 154, in <module>
output=opt.output)
File "detect.py", line 37, in detect
model.load_state_dict(torch.load(weights, map_location=device)['model'])
File "/home/leon/anaconda3/envs/yolo/lib/python3.7/site-packages/torch/nn/modules/module.py", line 777, 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: "module_list.0.Conv2d.weight", "module_list.0.BatchNorm2d.weight", "module_list.0.BatchNorm2d.bias", "module_list.0.BatchNorm2d.running_mean", "module_list.0.BatchNorm2d.running_var", "module_list.1.Conv2d.weight", "module_list.1.BatchNorm2d.weight", "module_list.1.BatchNorm2d.bias", "module_list.1.BatchNorm2d.running_mean", "module_list.1.BatchNorm2d.running_var", "module_list.2.Conv2d.weight", "module_list.2.BatchNorm2d.weight", "module_list.2.BatchNorm2d.bias", "module_list.2.BatchNorm2d.running_mean", "module_list.2.BatchNorm2d.running_var", "module_list.3.Conv2d.weight", "module_list.3.BatchNorm2d.weight", "module_list.3.BatchNorm2d.bias", "module_list.3.BatchNorm2d.running_mean", "module_list.3.BatchNorm2d.running_var", "module_list.5.Conv2d.weight", "module_list.5.BatchNorm2d.weight", "module_list.5.BatchNorm2d.bias" ........
But if I revert the pull and use the previous version the detect.py works fine. So I'm guessing my weights are the problem? Do I need to retrain my model with the new repo or I am missing something?
@lexer21 yes, so we owe you an apology. We introduced a breaking change in https://github.com/ultralytics/yolov3/commit/2d8311a83f51e5775e6c62bbd6b4510c2c616e97 on August 3rd, 2019. This change followed a PR that removed some of the nested nn.modules, and involved simplified layer names, but as a side effect this now prevents previous models from loading as the their dictionary keys now do not match the current dictionary keys.
Your options are to clone the latest version from the day before (August 2nd):
git clone https://github.com/ultralytics/yolov3
git checkout 267b430
or to simply git pull the current version and retrain your model (recommended). Apologies for the hassle, we will try to keep a better lookout for this in the future.
@glenn-jocher thank you for responding so quickly. I have retrained the model and the detect.py is working again.
Most helpful comment
@lexer21 yes, so we owe you an apology. We introduced a breaking change in https://github.com/ultralytics/yolov3/commit/2d8311a83f51e5775e6c62bbd6b4510c2c616e97 on August 3rd, 2019. This change followed a PR that removed some of the nested nn.modules, and involved simplified layer names, but as a side effect this now prevents previous models from loading as the their dictionary keys now do not match the current dictionary keys.
Your options are to clone the latest version from the day before (August 2nd):
or to simply
git pullthe current version and retrain your model (recommended). Apologies for the hassle, we will try to keep a better lookout for this in the future.