ShomyLiu / Neu-Review-Rec

A Toolkit for Neural Review-based Recommendation models with Pytorch.
http://shomy.top/2019/12/31/neu-review-rec/
168 stars 54 forks source link

模型训练好后用测试集加载模型报错 #18

Closed yinzhiqiangluvlzx closed 3 years ago

yinzhiqiangluvlzx commented 3 years ago

大佬好,想请教下这个问题 (pytorch) D:\workspace\pycharm\Neu-Review-Rec>python main.py test --pth_path="./checkpoints/DeepCoNN_Digital_Music_data_default.pth" --model=DeepCoNN load npy from dist...


user config: vocab_size => 50002 word_dim => 300 r_max_len => 202 u_max_r => 13 i_max_r => 24 train_data_size => 51764 test_data_size => 6471 val_data_size => 6471 user_num => 5543 item_num => 3570 batch_size => 128 print_step => 100


Traceback (most recent call last): File "main.py", line 212, in fire.Fire() File "C:\Users\yinzhiqiang\anaconda3\envs\pytorch\lib\site-packages\fire\core.py", line 138, in Fire component_trace = _Fire(component, args, parsed_flag_args, context, name) File "C:\Users\yinzhiqiang\anaconda3\envs\pytorch\lib\site-packages\fire\core.py", line 468, in _Fire target=component.name) File "C:\Users\yinzhiqiang\anaconda3\envs\pytorch\lib\site-packages\fire\core.py", line 672, in _CallAndUpdateTrace component = fn(*varargs, **kwargs) File "main.py", line 156, in test model.load(opt.pth_path) File "D:\workspace\pycharm\Neu-Review-Rec\framework\models.py", line 49, in load self.load_state_dict(torch.load(path)) File "C:\Users\yinzhiqiang\anaconda3\envs\pytorch\lib\site-packages\torch\nn\modules\module.py", line 1052, in load_state_dict self.class.name, "\n\t".join(error_msgs))) RuntimeError: Error(s) in loading state_dict for Model: Unexpected key(s) in state_dict: "predict_net.model.fm_V".

yinzhiqiangluvlzx commented 3 years ago

作者好,问题已经解决啦。

ShomyLiu commented 3 years ago

好的。大应该是模型名称或者配置不匹配等原因