Toybrick

pytorch算法模型转换报错

afson

新手上路

积分
26
楼主
发表于 2021-6-16 18:00:44    查看: 8790|回复: 5 | [复制链接]    打印 | 只看该作者
root@he-virtual-machine:~/Documents/rknn-toolkit/examples/pytorch/baseline# python3 test.py
--> config model
done
--> Loading model
/usr/local/lib/python3.6/dist-packages/onnx_tf/common/__init__.py:87: UserWarning: FrontendHandler.get_outputs_names is deprecated. It will be removed in future release.. Use node.outputs instead.
  warnings.warn(message)
./baseline.pt ********************
E Catch exception when loading pytorch model: ./baseline.pt!
E Traceback (most recent call last):
E   File "rknn/api/rknn_base.py", line 657, in rknn.api.rknn_base.RKNNBase.load_pytorch
E   File "rknn/base/RKNNlib/app/importer/import_pytorch.py", line 97, in rknn.base.RKNNlib.app.importer.import_pytorch.ImportPytorch.run
E   File "rknn/base/RKNNlib/converter/convert_pytorch.py", line 737, in rknn.base.RKNNlib.converter.convert_pytorch.convert_pytorch.__init__
E   File "/usr/local/lib/python3.6/dist-packages/torch/jit/__init__.py", line 162, in load
E     cpp_module = torch._C.import_ir_module(cu, f, map_location, _extra_files)
E RuntimeError: version_number <= kMaxSupportedFileFormatVersion INTERNAL ASSERT FAILED at /pytorch/caffe2/serialize/inline_container.cc:131, please report a bug to PyTorch. Attempted to read a PyTorch file with version 3, but the maximum supported version for reading is 1. Your PyTorch installation may be too old. (init at /pytorch/caffe2/serialize/inline_container.cc:131)
E frame #0: c10::Error::Error(c10::SourceLocation, std::string const&) + 0x33 (0x7fbe064ad273 in /usr/local/lib/python3.6/dist-packages/torch/lib/libc10.so)
E frame #1: caffe2::serialize:yTorchStreamReader::init() + 0x1e9a (0x7fbe0943c00a in /usr/local/lib/python3.6/dist-packages/torch/lib/libtorch.so)
E frame #2: caffe2::serialize:yTorchStreamReader:yTorchStreamReader(std::string const&) + 0x60 (0x7fbe0943d270 in /usr/local/lib/python3.6/dist-packages/torch/lib/libtorch.so)
E frame #3: torch::jit::import_ir_module(std::shared_ptr<torch::jit::script::CompilationUnit>, std::string const&, c10:ptional<c10:evice>, 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 (0x7fbe0a51c088 in /usr/local/lib/python3.6/dist-packages/torch/lib/libtorch.so)
E frame #4: <unknown function> + 0x4d69dc (0x7fbe5081d9dc in /usr/local/lib/python3.6/dist-packages/torch/lib/libtorch_python.so)
E frame #5: <unknown function> + 0x1d3ef4 (0x7fbe5051aef4 in /usr/local/lib/python3.6/dist-packages/torch/lib/libtorch_python.so)
E frame #6: python3() [0x50a5a5]
E <omitting python frames>
E frame #8: python3() [0x507cd4]
E frame #10: <unknown function> + 0x1d888 (0x7fbdc2518888 in /usr/local/lib/python3.6/dist-packages/rknn/base/RKNNlib/converter/convert_pytorch.cpython-36m-x86_64-linux-gnu.so)
E frame #11: <unknown function> + 0x1e457 (0x7fbdc2519457 in /usr/local/lib/python3.6/dist-packages/rknn/base/RKNNlib/converter/convert_pytorch.cpython-36m-x86_64-linux-gnu.so)
E frame #12: <unknown function> + 0xc5a3d (0x7fbdc25c0a3d in /usr/local/lib/python3.6/dist-packages/rknn/base/RKNNlib/converter/convert_pytorch.cpython-36m-x86_64-linux-gnu.so)
E frame #13: python3() [0x594fac]
E frame #14: python3() [0x549ce5]
E frame #15: python3() [0x551391]
E frame #16: <unknown function> + 0x659c (0x7fbdc3d2d59c in /usr/local/lib/python3.6/dist-packages/rknn/base/RKNNlib/app/importer/import_pytorch.cpython-36m-x86_64-linux-gnu.so)
E frame #17: <unknown function> + 0xc851 (0x7fbdc3d33851 in /usr/local/lib/python3.6/dist-packages/rknn/base/RKNNlib/app/importer/import_pytorch.cpython-36m-x86_64-linux-gnu.so)
E frame #18: <unknown function> + 0x14a6c (0x7fbdc3d3ba6c in /usr/local/lib/python3.6/dist-packages/rknn/base/RKNNlib/app/importer/import_pytorch.cpython-36m-x86_64-linux-gnu.so)
E frame #19: <unknown function> + 0x22e2d (0x7fbe5c77ae2d in /usr/local/lib/python3.6/dist-packages/rknn/api/rknn_base.cpython-36m-x86_64-linux-gnu.so)
E frame #20: <unknown function> + 0x2302e (0x7fbe5c77b02e in /usr/local/lib/python3.6/dist-packages/rknn/api/rknn_base.cpython-36m-x86_64-linux-gnu.so)
E frame #21: <unknown function> + 0x6673b (0x7fbe5c7be73b in /usr/local/lib/python3.6/dist-packages/rknn/api/rknn_base.cpython-36m-x86_64-linux-gnu.so)
E frame #23: python3() [0x50a533]
E frame #25: python3() [0x507cd4]
E frame #26: python3() [0x509a00]
E frame #27: python3() [0x50a3fd]
E frame #29: python3() [0x507cd4]
E frame #31: python3() [0x635262]
E frame #36: __libc_start_main + 0xe7 (0x7fbe6808ebf7 in /lib/x86_64-linux-gnu/libc.so.6)
Load pytorch model failed!
root@he-virtual-machine:~/Documents/rknn-toolkit/examples/pytorch/baseline#

这个是torch版本和原算法模型的使用的接口对应的版本不匹配导致的吗?


回复

使用道具 举报

afson

新手上路

积分
26
沙发
 楼主| 发表于 2021-6-16 18:01:45 | 只看该作者
root@he-virtual-machine:~/Documents/rknn-toolkit/examples/pytorch/baseline# pip3 list | grep torch
DEPRECATION: The default format will switch to columns in the future. You can use --format=(legacy|columns) (or define a format=(legacy|columns) in your pip.conf under the [list] section) to disable this warning.
torch (1.2.0)
torchvision (0.4.0)
root@he-virtual-machine:~/Documents/rknn-toolkit/examples/pytorch/baseline#

安装的torch (1.2.0),torchvision (0.4.0)
回复

使用道具 举报

afson

新手上路

积分
26
板凳
 楼主| 发表于 2021-6-16 20:16:35 | 只看该作者

root@he-virtual-machine:~/Documents/rknn-toolkit/examples/pytorch/resnet18# python3 test.py
Downloading: "https://download.pytorch.org/models/resnet18-5c106cde.pth" to /home/he/.cache/torch/checkpoints/resnet18-5c106cde.pth
100%|███████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████| 44.7M/44.7M [00:09<00:00, 5.03MB/s]
--> config model
done
--> Loading model
/usr/local/lib/python3.6/dist-packages/onnx_tf/common/__init__.py:87: UserWarning: FrontendHandler.get_outputs_names is deprecated. It will be removed in future release.. Use node.outputs instead.
  warnings.warn(message)
./resnet18.pt ********************
WARNING: Token 'COMMENT' defined, but not used
WARNING: There is 1 unused token
E Syntax error in input! LexToken(NAMED_IDENTIFIER,'__torch__',1,16)
E Catch exception when loading pytorch model: ./resnet18.pt!
E Traceback (most recent call last):
E   File "rknn/api/rknn_base.py", line 657, in rknn.api.rknn_base.RKNNBase.load_pytorch
E   File "rknn/base/RKNNlib/app/importer/import_pytorch.py", line 97, in rknn.base.RKNNlib.app.importer.import_pytorch.ImportPytorch.run
E   File "rknn/base/RKNNlib/converter/convert_pytorch.py", line 740, in rknn.base.RKNNlib.converter.convert_pytorch.convert_pytorch.__init__
E   File "rknn/base/RKNNlib/converter/pytorch_parser/pytorch_ir_parser.py", line 554, in rknn.base.RKNNlib.converter.pytorch_parser.pytorch_ir_parser.pytorch_ir_parser.parse
E   File "/usr/local/lib/python3.6/dist-packages/ply/yacc.py", line 333, in parse
E     return self.parseopt_notrack(input, lexer, debug, tracking, tokenfunc)
E   File "/usr/local/lib/python3.6/dist-packages/ply/yacc.py", line 1201, in parseopt_notrack
E     tok = call_errorfunc(self.errorfunc, errtoken, self)
E   File "/usr/local/lib/python3.6/dist-packages/ply/yacc.py", line 192, in call_errorfunc
E     r = errorfunc(token)
E   File "rknn/base/RKNNlib/converter/pytorch_parser/pytorch_ir_parser.py", line 545, in rknn.base.RKNNlib.converter.pytorch_parser.pytorch_ir_parser.pytorch_ir_parser.p_error
E   File "rknn/api/rknn_log.py", line 312, in rknn.api.rknn_log.RKNNLog.e
E ValueError: Syntax error in input! LexToken(NAMED_IDENTIFIER,'__torch__',1,16)
Load pytorch model failed!
root@he-virtual-machine:~/Documents/rknn-toolkit/examples/pytorch/resnet18# pip3 list | grep torch
DEPRECATION: The default format will switch to columns in the future. You can use --format=(legacy|columns) (or define a format=(legacy|columns) in your pip.conf under the [list] section) to disable this warning.
torch (1.5.1)
torchvision (0.6.1)
root@he-virtual-machine:~/Documents/rknn-toolkit/examples/pytorch/resnet18#

升级了torch (1.5.1)和 torchvision (0.6.1),rknn-toolkit自带的resnet18例子转换都有问题。
回复

使用道具 举报

afson

新手上路

积分
26
地板
 楼主| 发表于 2021-6-16 20:17:34 | 只看该作者
root@he-virtual-machine:~/Documents/rknn-toolkit/examples/pytorch/baseline# python3 test.py
--> config model
done
--> Loading model
/usr/local/lib/python3.6/dist-packages/onnx_tf/common/__init__.py:87: UserWarning: FrontendHandler.get_outputs_names is deprecated. It will be removed in future release.. Use node.outputs instead.
  warnings.warn(message)
./baseline.pt ********************
E Catch exception when loading pytorch model: ./baseline.pt!
E Traceback (most recent call last):
E   File "rknn/api/rknn_base.py", line 657, in rknn.api.rknn_base.RKNNBase.load_pytorch
E   File "rknn/base/RKNNlib/app/importer/import_pytorch.py", line 97, in rknn.base.RKNNlib.app.importer.import_pytorch.ImportPytorch.run
E   File "rknn/base/RKNNlib/converter/convert_pytorch.py", line 737, in rknn.base.RKNNlib.converter.convert_pytorch.convert_pytorch.__init__
E   File "/usr/local/lib/python3.6/dist-packages/torch/jit/__init__.py", line 228, in load
E     cpp_module = torch._C.import_ir_module(cu, f, map_location, _extra_files)
E RuntimeError: [enforce fail at inline_container.cc:208] . file not found: archive/constants.pkl
Load pytorch model failed!
root@he-virtual-machine:~/Documents/rknn-toolkit/examples/pytorch/baseline# cd ../

我自己的模型,升级了torch (1.5.1)和 torchvision (0.6.1),转换也报错。
回复

使用道具 举报

chenshq168

注册会员

积分
105
5#
发表于 2021-6-18 18:49:22 | 只看该作者
我也一样,toolkit自带的网络模型都不能运行,有点头疼!!!
回复

使用道具 举报

chenshq168

注册会员

积分
105
6#
发表于 2021-6-18 18:50:52 | 只看该作者
网络模型跟哪个版本相关,至少也出个readme嘛,搞得一个版本一版本的去试,让人崩溃。
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

产品中心 购买渠道 开源社区 Wiki教程 资料下载 关于Toybrick


快速回复 返回顶部 返回列表