yxgeee / FD-GAN

[NeurIPS-2018] FD-GAN: Pose-guided Feature Distilling GAN for Robust Person Re-identification.
https://yxgeee.github.io/projects/fdgan.html
281 stars 80 forks source link

KeyError: 'unexpected key "module.base_model.base.conv1.weight" in state_dict' #40

Closed haozhihui110 closed 4 years ago

haozhihui110 commented 4 years ago

Traceback (most recent call last): File "train.py", line 126, in main() File "train.py", line 60, in main model = FDGANModel(opt) File "/home/zhihui/Documents/ZHIHUI/FD-GAN/fdgan/model.py", line 28, in init self._init_models() File "/home/zhihui/Documents/ZHIHUI/FD-GAN/fdgan/model.py", line 55, in _init_models self.net_E.load_state_dict(state_dict['state_dict']) File "/home/zhihui/.local/lib/python3.5/site-packages/torch/nn/modules/module.py", line 522, in load_state_dict .format(name)) KeyError: 'unexpected key "module.base_model.base.conv1.weight" in state_dict'

   After modifying self.net_E.load_state_dict(state_dict) to self.net_E.load_state_dict(state_dict['state_dict']) according to your prompt yesterday, the above error appears. May I ask if there is an error recurring operation, please help me correct it. Thank you!
yxgeee commented 4 years ago

Try to change https://github.com/yxgeee/FD-GAN/blob/master/fdgan/model.py#L54

from

            state_dict = remove_module_key(torch.load(self.opt.netE_pretrain))
            self.net_E.load_state_dict(state_dict)

to

            state_dict = remove_module_key(torch.load(self.opt.netE_pretrain)['state_dict'])
            self.net_E.load_state_dict(state_dict)

Hint: To make sure the keys in self.net_E.state_dict() and state_dict are identical.

haozhihui110 commented 4 years ago

This modification is effective, thank you for your hint and patience for the correction