问题背景:
在使用pytorch的pt文件推理时候,model.load_state_dict(state_dict)
出现了AttributeError: 'RecursiveScriptModule' object has no attribute 'copy'
报错,是因为torch保存模型种类的问题,torch保存模型有jit.trace()和jit.script()两种方法
例如: https://blog.csdn.net/weixin_43742643/article/details/116854265 所述
解决方法:
load你自己的state_dict的.state_dict()方法,示例如下:
state_dict = torch.load(args.checkpoint_path, map_location=torch.device('cpu'))
model.load_state_dict(state_dict.state_dict())