官方说明:the serialized data is bound to the specific classes and the exact directory structure used, so it can break in various ways when used in other projects, or after some serious refactors.
也就是说,当使用这个函数的时候,pytorch序列化的是参数以及model class的路径。所以使用这个函数之前,必须保证定义model的文件目录结构相同。一般来说,model.py只要和要运行的py文件在同个目录就不会报这个错。
总结:当使用torch.save()保存模型时候,序列化了参数和model路径,torch.load()时候需保证model的文件目录结构一致才可以。