PyTorch - RuntimeError: [enforce fail at inline_container.cc:209] . file not found: archive/data.pkl
PyTorch - RuntimeError: [enforce fail at inline_container.cc:209] . file not found: archive/data.pkl
问题
我正在尝试使用PyTorch加载一个文件,但错误显示archive/data.pkl
不存在。
代码
import torch cachefile = 'cacheddata.pth' torch.load(cachefile)
输出
--------------------------------------------------------------------------- RuntimeError Traceback (most recent call last)in 1 import torch 2 cachefile = 'cacheddata.pth' ----> 3 torch.load(cachefile) ~/opt/anaconda3/envs/matching/lib/python3.8/site-packages/torch/serialization.py in load(f, map_location, pickle_module, **pickle_load_args) 582 opened_file.seek(orig_position) 583 return torch.jit.load(opened_file) --> 584 return _load(opened_zipfile, map_location, pickle_module, **pickle_load_args) 585 return _legacy_load(opened_file, map_location, pickle_module, **pickle_load_args) 586 ~/opt/anaconda3/envs/matching/lib/python3.8/site-packages/torch/serialization.py in _load(zip_file, map_location, pickle_module, **pickle_load_args) 837 838 # Load the data (which may in turn use `persistent_load` to load tensors) --> 839 data_file = io.BytesIO(zip_file.get_record('data.pkl')) 840 unpickler = pickle_module.Unpickler(data_file, **pickle_load_args) 841 unpickler.persistent_load = persistent_load RuntimeError: [enforce fail at inline_container.cc:209] . 文件未找到:archive/data.pkl
假设
我猜测这与pickle有关,参考文档:
这种保存/加载过程使用最直观的语法,需要的代码最少。以这种方式保存模型将使用Python的pickle模块保存整个模块。这种方法的缺点是序列化的数据与特定的类和保存模型时使用的确切目录结构绑定在一起。这样做的原因是pickle不保存模型类本身。相反,它保存一个指向包含类的文件的路径,在加载时使用。因此,当在其他项目中使用或进行重构后,代码可能以各种方式中断。
版本
- PyTorch版本:1.6.0
- Python版本:3.8.0