[enforce fail at inline_container.cc:137] . PytorchStreamReader failed reading zip archive:解决方法

pytorch 或者libtorch报错
详细如下

terminate called after throwing an instance of 'c10::Error'
  what():  [enforce fail at inline_container.cc:137] . PytorchStreamReader failed reading zip archive: failed finding central directory
frame #0: c10::ThrowEnforceNotMet(char const*, int, char const*, std::string const&, void const*) + 0x47 (0x7ffb173b7e17 in /home/libtorch-shared-with-deps-1.2.0-cu92/libtorch/lib/libc10.so)
frame #1: caffe2::serialize::PyTorchStreamReader::valid(char const*) + 0x6b (0x7ffb1a1135bb in /home/libtorch-shared-with-deps-1.2.0-cu92/libtorch/lib/libtorch.so)
frame #2: caffe2::serialize::PyTorchStreamReader::init() + 0x9a (0x7ffb1a11706a in /home/libtorch-shared-with-deps-1.2.0-cu92/libtorch/lib/libtorch.so)
frame #3: caffe2::serialize::PyTorchStreamReader::PyTorchStreamReader(std::unique_ptr<caffe2::serialize::ReadAdapterInterface, std::default_delete<caffe2::serialize::ReadAdapterInterface> >) + 0x53 (0x7ffb1a11a023 in /home/libtorch-shared-with-deps-1.2.0-cu92/libtorch/lib/libtorch.so)
frame #4: <unknown function> + 0x3c19b32 (0x7ffb1b1f7b32 in /home/libtorch-shared-with-deps-1.2.0-cu92/libtorch/lib/libtorch.so)
frame #5: torch::jit::load(std::unique_ptr<caffe2::serialize::ReadAdapterInterface, std::default_delete<caffe2::serialize::ReadAdapterInterface> >, c10::optional<c10::Device>, std::unordered_map<std::string, std::string, std::hash<std::string>, std::equal_to<std::string>, std::allocator<std::pair<std::string const, std::string> > >&) + 0x27 (0x7ffb1b1f6a87 in /home/libtorch-shared-with-deps-1.2.0-cu92/libtorch/lib/libtorch.so)
frame #6: torch::jit::load(std::string const&, c10::optional<c10::Device>, std::unordered_map<std::string, std::string, std::hash<std::string>, std::equal_to<std::string>, std::allocator<std::pair<std::string const, std::string> > >&) + 0x69 (0x7ffb1b1f6dc9 in /home/libtorch-shared-with-deps-1.2.0-cu92/libtorch/lib/libtorch.so)
frame #7: main + 0x6a (0x42abaa in ./faster-rcnn-cpp)
frame #8: __libc_start_main + 0xf5 (0x7ffaed8a53d5 in /lib64/libc.so.6)
frame #9: ./faster-rcnn-cpp() [0x429699]

由于加载的模型pth或者pt文件,文件类型不同,无法加载,一般错误在这一句

torch::jit::script::Module module = torch::jit::load("reversed.pt");

需要在训练模型文件的时候,加上一个参数 _use_new_zipfile_serialization=True
在训练的时候,保存文件时

 torch.save(model, '1.pt', _use_new_zipfile_serialization=True)

或者将文件重新保存一遍

model_path = 'logs/Epoch93-Total_Loss0.1091-Val_Loss0.1511.pt'
# model
model = resnet50()[0]

model.load_state_dict(torch.load(model_path,map_location=lambda storage, loc: storage), strict=False)
torch.save(model.state_dict(),'logs/reversed.pt',_use_new_zipfile_serialization=True)
  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 5
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 5
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

Bean_zx

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值