nikhilbarhate99 / PPO-PyTorch

Minimal implementation of clipped objective Proximal Policy Optimization (PPO) in PyTorch
MIT License
1.57k stars 332 forks source link

Unexpected key(s) in state_dict: "affine.weight", "affine.bias". #32

Closed fatalfeel closed 4 years ago

fatalfeel commented 4 years ago

/usr/bin/python3 /root/PycharmProjects/PPO-PyTorch/test.py Traceback (most recent call last): File "/root/PycharmProjects/PPO-PyTorch/test.py", line 36, in ppo.policy_old.load_state_dict(torch.load(pathfile)) File "/usr/lib/python3.7/site-packages/torch/nn/modules/module.py", line 847, in load_state_dict self.class.name, "\n\t".join(error_msgs))) RuntimeError: Error(s) in loading state_dict for ActorCritic: Unexpected key(s) in state_dict: "affine.weight", "affine.bias".

#ppo.policy_old.load_state_dict(torch.load(directory+filename))
loadweight = torch.load(pathfile)
ppo.policy_old.load_state_dict(loadweight)   //////-> crash here
fatalfeel commented 4 years ago

ppo.policy_old.load_state_dict(torch.load(pathfile),strict=False)

~after add strict=False then ok

outdoteth commented 3 years ago

Lifesaver thanks. @fatalfeel