【pytorch加载模型错误】Unexpected key(s) in state_dict: “epoch“, “arch“, “state_dict“, “optimizer“, “args“

方案1.
尝试用

state_dict = torch.load(model_name)
model.load_state_dict({k.replace('module.', ''): v for k, v in state_dict.items()})

方案2.
训练好的模型文件好像字典键值有很多个,如optimizer,epoch,args等,我们只需要模型参数文件state_dict

state_dict = torch.load(new_model)
run_logger.info('{} start evaluation!!!'.format(new_model))
model.load_state_dict(state_dict['state_dict'])

你可能感兴趣的:(pytorch,pytorch,深度学习,人工智能)