Pytorch模型文件转换失败

环境:
Ubuntu20.04 Python 3.8.10 VIM3 DDK6421 pytorch1.1

自己基于pytorch训练好了模型,想做模型转换后放到VIM3上NPU运行,手动修改actuity中的0_import_model.sh为:

#!/bin/bash
NAME=pytorch
ACUITY_PATH=../bin/
convert_pytorch=${ACUITY_PATH}convertpytorch
$convert_pytorch --pytorch-model ./model/FCN.pth --net-output cnn.json \
        --data-output cnn.data --input-size-list '1,28,28'

执行0_import_model.sh报错异常日志:

I Start importing pytorch...
./model/FCN.pth ********************
Traceback (most recent call last):
  File "convertpytorch.py", line 51, in <module>
  File "convertpytorch.py", line 41, in main
  File "acuitylib/vsi_nn.py", line 162, in load_pytorch
  File "acuitylib/app/importer/import_pytorch.py", line 92, in run
  File "acuitylib/converter/convert_pytorch.py", line 515, in __init__
  File "torch/jit/__init__.py", line 162, in load
RuntimeError: [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 (0x7f244ea16e17 in /homeb/xiaoyuan.cai/tools/actuity_linux_pytorch_COCO/bin/acuitylib/libc10.so)
frame #1: caffe2::serialize::PyTorchStreamReader::valid(char const*) + 0x6b (0x7f245199f75b in /homeb/xiaoyuan.cai/tools/actuity_linux_pytorch_COCO/bin/acuitylib/libtorch.so)
frame #2: caffe2::serialize::PyTorchStreamReader::init() + 0x9a (0x7f24519a320a in /homeb/xiaoyuan.cai/tools/actuity_linux_pytorch_COCO/bin/acuitylib/libtorch.so)
frame #3: caffe2::serialize::PyTorchStreamReader::PyTorchStreamReader(std::string const&) + 0x60 (0x7f24519a6270 in /homeb/xiaoyuan.cai/tools/actuity_linux_pytorch_COCO/bin/acuitylib/libtorch.so)
frame #4: torch::jit::import_ir_module(std::shared_ptr<torch::jit::script::CompilationUnit>, 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> > >&) + 0x38 (0x7f2452a85088 in /homeb/xiaoyuan.cai/tools/actuity_linux_pytorch_COCO/bin/acuitylib/libtorch.so)
frame #5: <unknown function> + 0x4d6abc (0x7f2498d86abc in /homeb/xiaoyuan.cai/tools/actuity_linux_pytorch_COCO/bin/acuitylib/libtorch_python.so)
frame #6: <unknown function> + 0x1d3f04 (0x7f2498a83f04 in /homeb/xiaoyuan.cai/tools/actuity_linux_pytorch_COCO/bin/acuitylib/libtorch_python.so)
<omitting python frames>
frame #29: ../bin/convertpytorch() [0x402ca1]
frame #30: ../bin/convertpytorch() [0x403087]
frame #31: __libc_start_main + 0xf3 (0x7f2596c37083 in /lib/x86_64-linux-gnu/libc.so.6)
frame #32: ../bin/convertpytorch() [0x401a9e]

[517] Failed to execute script convertpytorch

附件是训练用的VOC.py和训练后的FCN.pth模型文件
链接: 百度网盘 请输入提取码 提取码: vd3x

问题较紧急,麻烦帮忙看下?感谢!

@kiwin 请使用pt格式的pytorch文件转换。

@Frank

VOC.py中使用的torch.save(fcn8s, “VOC.pkl”)保存文件,试过保存成VOC.pth也不行。
您所指的pt格式的pytorch文件转换具体是需要怎么转换呢?
谢谢~

@kiwin 这个就需要你自行百度了,我们这边只提供转换工具的转换支持。你可以查询下Pytorch的官方文档。

@Frank 在torch1.1版本下训练出来的能兼容吗?

@kiwin 没有测试过1.1的版本,但是工具只支持pt格式的pytorch模型,另外,建议可以转成onnx再转换。