Toybrick

tensorflow模型转rknn失败

z792929375

新手上路

积分
25
楼主
发表于 2020-5-12 12:02:53    查看: 9097|回复: 5 | [复制链接]    打印 | 只看该作者
输出信息如下:
--> Loading model

WARNING: The TensorFlow contrib module will not be included in TensorFlow 2.0.
For more information, please see:
  * https://github.com/tensorflow/co ... 7-contrib-sunset.md
  * https://github.com/tensorflow/addons
If you depend on functionality not listed there, please file an issue.

/home/LIESMARS/2019286190101/anaconda3/envs/rknn/lib/python3.6/site-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)
W:tensorflow:From /home/LIESMARS/2019286190101/anaconda3/envs/rknn/lib/python3.6/site-packages/rknn/api/rknn.py:67: extract_sub_graph (from tensorflow.python.framework.graph_util_impl) is deprecated and will be removed in a future version.
Instructions for updating:
Use tf.compat.v1.graph_util.extract_sub_graph
E Catch exception when loading tensorflow model: ../transdata/yolov3-voc.pb!
E Traceback (most recent call last):
E   File "/home/LIESMARS/2019286190101/anaconda3/envs/rknn/lib/python3.6/site-packages/tensorflow/python/client/session.py", line 1334, in _do_call
E     return fn(*args)
E   File "/home/LIESMARS/2019286190101/anaconda3/envs/rknn/lib/python3.6/site-packages/tensorflow/python/client/session.py", line 1319, in _run_fn
E     options, feed_dict, fetch_list, target_list, run_metadata)
E   File "/home/LIESMARS/2019286190101/anaconda3/envs/rknn/lib/python3.6/site-packages/tensorflow/python/client/session.py", line 1407, in _call_tf_sessionrun
E     run_metadata)
E tensorflow.python.framework.errors_impl.FailedPreconditionError: Attempting to use uninitialized value yolov3-vocconvolutional9/kernel
E        [[{{node _retval_yolov3-vocconvolutional9/kernel_0_63}}]]
E During handling of the above exception, another exception occurred:
E Traceback (most recent call last):
E   File "rknn/api/rknn_base.py", line 215, in rknn.api.rknn_base.RKNNBase.load_tensorflow
E   File "rknn/base/RKNNlib/converter/convert_tf.py", line 527, in rknn.base.RKNNlib.converter.convert_tf.convert_tf.pre_process
E   File "rknn/base/RKNNlib/converter/tensorflowloader.py", line 91, in rknn.base.RKNNlib.converter.tensorflowloader.TF_Graph_Preprocess.pre_proces
E   File "rknn/base/RKNNlib/converter/tensorflowloader.py", line 805, in rknn.base.RKNNlib.converter.tensorflowloader.TF_Graph_Preprocess.calc_2_const
E   File "rknn/base/RKNNlib/converter/tf_util.py", line 371, in rknn.base.RKNNlib.converter.tf_util.TFProto_Util.query_tensor
E   File "rknn/base/RKNNlib/converter/tf_util.py", line 374, in rknn.base.RKNNlib.converter.tf_util.TFProto_Util.query_tensor
E   File "rknn/base/RKNNlib/converter/tf_util.py", line 407, in rknn.base.RKNNlib.converter.tf_util.TFProto_Util.query_tensor
E   File "/home/LIESMARS/2019286190101/anaconda3/envs/rknn/lib/python3.6/site-packages/tensorflow/python/client/session.py", line 929, in run
E     run_metadata_ptr)
E   File "/home/LIESMARS/2019286190101/anaconda3/envs/rknn/lib/python3.6/site-packages/tensorflow/python/client/session.py", line 1152, in _run
E     feed_dict_tensor, options, run_metadata)
E   File "/home/LIESMARS/2019286190101/anaconda3/envs/rknn/lib/python3.6/site-packages/tensorflow/python/client/session.py", line 1328, in _do_run
E     run_metadata)
E   File "/home/LIESMARS/2019286190101/anaconda3/envs/rknn/lib/python3.6/site-packages/tensorflow/python/client/session.py", line 1348, in _do_call
E     raise type(e)(node_def, op, message)
E tensorflow.python.framework.errors_impl.FailedPreconditionError: Attempting to use uninitialized value yolov3-vocconvolutional9/kernel
E        [[{{node _retval_yolov3-vocconvolutional9/kernel_0_63}}]]
Loading done
--> Building model
Traceback (most recent call last):
  File "TF.py", line 15, in <module>
    rknn.build(do_quantization=True, pre_compile=True, dataset='dataset_416x416.txt')
  File "/home/LIESMARS/2019286190101/anaconda3/envs/rknn/lib/python3.6/site-packages/rknn/api/rknn.py", line 222, in build
    inputs = self.rknn_base.net.get_input_layers()
AttributeError: 'NoneType' object has no attribute 'get_input_layers'

这是什么原因?OP不支持吗?

回复

使用道具 举报

jefferyzhang

版主

积分
13580
沙发
发表于 2020-5-12 14:12:02 | 只看该作者
你这报错的地方在tensorflow里,请先检查下你的pb文件是不是可以被当前tensorflow正常读取和推理,再转rknn。
回复

使用道具 举报

z792929375

新手上路

积分
25
板凳
 楼主| 发表于 2020-5-13 16:14:47 | 只看该作者
jefferyzhang 发表于 2020-5-12 14:12
你这报错的地方在tensorflow里,请先检查下你的pb文件是不是可以被当前tensorflow正常读取和推理,再转rknn ...

我同样的模型在pytorch上测试读取推理成功,但转rknn还是失败了,请问是什么原因呢。。。
--> Loading model

WARNING: The TensorFlow contrib module will not be included in TensorFlow 2.0.
For more information, please see:
  * https://github.com/tensorflow/co ... 7-contrib-sunset.md
  * https://github.com/tensorflow/addons
If you depend on functionality not listed there, please file an issue.

/home/LIESMARS/2019286190101/anaconda3/envs/rknn/lib/python3.6/site-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)
/home/LIESMARS/2019286190101/rknntrans/transdata/model.pt ********************
E Catch exception when loading pytorch model: /home/LIESMARS/2019286190101/rknntrans/transdata/model.pt!
E Traceback (most recent call last):
E   File "rknn/api/rknn_base.py", line 611, 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 552, in rknn.base.RKNNlib.converter.convert_pytorch.convert_pytorch.__init__
E   File "/home/LIESMARS/2019286190101/anaconda3/envs/rknn/lib/python3.6/site-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: [enforce fail at inline_container.cc:137] . PytorchStreamReader failed reading zip archive: failed finding central directory
E frame #0: c10::ThrowEnforceNotMet(char const*, int, char const*, std::string const&, void const*) + 0x47 (0x7fefe530fe17 in /home/LIESMARS/2019286190101/anaconda3/envs/rknn/lib/python3.6/site-packages/torch/lib/libc10.so)
E frame #1: caffe2::serialize:yTorchStreamReader::valid(char const*) + 0x6b (0x7fefe829875b in /home/LIESMARS/2019286190101/anaconda3/envs/rknn/lib/python3.6/site-packages/torch/lib/libtorch.so)
E frame #2: caffe2::serialize:yTorchStreamReader::init() + 0x9a (0x7fefe829c20a in /home/LIESMARS/2019286190101/anaconda3/envs/rknn/lib/python3.6/site-packages/torch/lib/libtorch.so)
E frame #3: caffe2::serialize:yTorchStreamReader:yTorchStreamReader(std::string const&) + 0x60 (0x7fefe829f270 in /home/LIESMARS/2019286190101/anaconda3/envs/rknn/lib/python3.6/site-packages/torch/lib/libtorch.so)
E frame #4: 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 (0x7fefe937e088 in /home/LIESMARS/2019286190101/anaconda3/envs/rknn/lib/python3.6/site-packages/torch/lib/libtorch.so)
E frame #5: <unknown function> + 0x4d69dc (0x7ff02f67f9dc in /home/LIESMARS/2019286190101/anaconda3/envs/rknn/lib/python3.6/site-packages/torch/lib/libtorch_python.so)
E frame #6: <unknown function> + 0x1d3ef4 (0x7ff02f37cef4 in /home/LIESMARS/2019286190101/anaconda3/envs/rknn/lib/python3.6/site-packages/torch/lib/libtorch_python.so)
E frame #7: _PyCFunction_FastCallDict + 0x154 (0x55cdc5d55304 in /home/LIESMARS/2019286190101/anaconda3/envs/rknn/bin/python)
E frame #8: <unknown function> + 0x199b0c (0x55cdc5ddcb0c in /home/LIESMARS/2019286190101/anaconda3/envs/rknn/bin/python)
E frame #9: _PyEval_EvalFrameDefault + 0x30a (0x55cdc5dff81a in /home/LIESMARS/2019286190101/anaconda3/envs/rknn/bin/python)
E frame #10: PyEval_EvalCodeEx + 0x329 (0x55cdc5dd7a49 in /home/LIESMARS/2019286190101/anaconda3/envs/rknn/bin/python)
E frame #11: <unknown function> + 0x196b8 (0x7ff033ffc6b8 in /home/LIESMARS/2019286190101/anaconda3/envs/rknn/lib/python3.6/site-packages/rknn/base/RKNNlib/converter/convert_pytorch.cpython-36m-x86_64-linux-gnu.so)
E frame #12: <unknown function> + 0x19ff7 (0x7ff033ffcff7 in /home/LIESMARS/2019286190101/anaconda3/envs/rknn/lib/python3.6/site-packages/rknn/base/RKNNlib/converter/convert_pytorch.cpython-36m-x86_64-linux-gnu.so)
E frame #13: <unknown function> + 0x995d5 (0x7ff03407c5d5 in /home/LIESMARS/2019286190101/anaconda3/envs/rknn/lib/python3.6/site-packages/rknn/base/RKNNlib/converter/convert_pytorch.cpython-36m-x86_64-linux-gnu.so)
E frame #14: _PyObject_FastCallDict + 0x8b (0x55cdc5d554eb in /home/LIESMARS/2019286190101/anaconda3/envs/rknn/bin/python)
E frame #15: _PyObject_Call_Prepend + 0x63 (0x55cdc5d5a143 in /home/LIESMARS/2019286190101/anaconda3/envs/rknn/bin/python)
E frame #16: PyObject_Call + 0x3e (0x55cdc5d5510e in /home/LIESMARS/2019286190101/anaconda3/envs/rknn/bin/python)
E frame #17: <unknown function> + 0x16ab4b (0x55cdc5dadb4b in /home/LIESMARS/2019286190101/anaconda3/envs/rknn/bin/python)
E frame #18: <unknown function> + 0x199e47 (0x55cdc5ddce47 in /home/LIESMARS/2019286190101/anaconda3/envs/rknn/bin/python)
E frame #19: <unknown function> + 0x6a8c (0x7ff0358a3a8c in /home/LIESMARS/2019286190101/anaconda3/envs/rknn/lib/python3.6/site-packages/rknn/base/RKNNlib/app/importer/import_pytorch.cpython-36m-x86_64-linux-gnu.so)
E frame #20: <unknown function> + 0xcd2e (0x7ff0358a9d2e in /home/LIESMARS/2019286190101/anaconda3/envs/rknn/lib/python3.6/site-packages/rknn/base/RKNNlib/app/importer/import_pytorch.cpython-36m-x86_64-linux-gnu.so)
E frame #21: <unknown function> + 0x1314c (0x7ff0358b014c in /home/LIESMARS/2019286190101/anaconda3/envs/rknn/lib/python3.6/site-packages/rknn/base/RKNNlib/app/importer/import_pytorch.cpython-36m-x86_64-linux-gnu.so)
E frame #22: <unknown function> + 0x2041d (0x7ff09da6141d in /home/LIESMARS/2019286190101/anaconda3/envs/rknn/lib/python3.6/site-packages/rknn/api/rknn_base.cpython-36m-x86_64-linux-gnu.so)
E frame #23: <unknown function> + 0x2061e (0x7ff09da6161e in /home/LIESMARS/2019286190101/anaconda3/envs/rknn/lib/python3.6/site-packages/rknn/api/rknn_base.cpython-36m-x86_64-linux-gnu.so)
E frame #24: <unknown function> + 0x109436 (0x7ff09db4a436 in /home/LIESMARS/2019286190101/anaconda3/envs/rknn/lib/python3.6/site-packages/rknn/api/rknn_base.cpython-36m-x86_64-linux-gnu.so)
E frame #25: _PyObject_FastCallDict + 0x8b (0x55cdc5d554eb in /home/LIESMARS/2019286190101/anaconda3/envs/rknn/bin/python)
E frame #26: <unknown function> + 0x199c5e (0x55cdc5ddcc5e in /home/LIESMARS/2019286190101/anaconda3/envs/rknn/bin/python)
E frame #27: _PyEval_EvalFrameDefault + 0x30a (0x55cdc5dff81a in /home/LIESMARS/2019286190101/anaconda3/envs/rknn/bin/python)
E frame #28: <unknown function> + 0x192f26 (0x55cdc5dd5f26 in /home/LIESMARS/2019286190101/anaconda3/envs/rknn/bin/python)
E frame #29: <unknown function> + 0x193f31 (0x55cdc5dd6f31 in /home/LIESMARS/2019286190101/anaconda3/envs/rknn/bin/python)
E frame #30: <unknown function> + 0x199be5 (0x55cdc5ddcbe5 in /home/LIESMARS/2019286190101/anaconda3/envs/rknn/bin/python)
E frame #31: _PyEval_EvalFrameDefault + 0x10c9 (0x55cdc5e005d9 in /home/LIESMARS/2019286190101/anaconda3/envs/rknn/bin/python)
E frame #32: PyEval_EvalCodeEx + 0x329 (0x55cdc5dd7a49 in /home/LIESMARS/2019286190101/anaconda3/envs/rknn/bin/python)
E frame #33: PyEval_EvalCode + 0x1c (0x55cdc5dd87ec in /home/LIESMARS/2019286190101/anaconda3/envs/rknn/bin/python)
E frame #34: <unknown function> + 0x215e74 (0x55cdc5e58e74 in /home/LIESMARS/2019286190101/anaconda3/envs/rknn/bin/python)
E frame #35: PyRun_FileExFlags + 0xa1 (0x55cdc5e59271 in /home/LIESMARS/2019286190101/anaconda3/envs/rknn/bin/python)
E frame #36: PyRun_SimpleFileExFlags + 0x1c3 (0x55cdc5e59473 in /home/LIESMARS/2019286190101/anaconda3/envs/rknn/bin/python)
E frame #37: Py_Main + 0x613 (0x55cdc5e5cf63 in /home/LIESMARS/2019286190101/anaconda3/envs/rknn/bin/python)
E frame #38: main + 0xee (0x55cdc5d26f2e in /home/LIESMARS/2019286190101/anaconda3/envs/rknn/bin/python)
E frame #39: __libc_start_main + 0xf0 (0x7ff09ed04830 in /lib/x86_64-linux-gnu/libc.so.6)
E frame #40: <unknown function> + 0x1c327f (0x55cdc5e0627f in /home/LIESMARS/2019286190101/anaconda3/envs/rknn/bin/python)
Loading done
--> Building model
Traceback (most recent call last):
  File "/home/LIESMARS/2019286190101/rknntrans/src/pytorch.py", line 13, in <module>
    rknn.build(do_quantization=True, pre_compile=True, dataset='dataset_416x416.txt')
  File "/home/LIESMARS/2019286190101/anaconda3/envs/rknn/lib/python3.6/site-packages/rknn/api/rknn.py", line 222, in build
    inputs = self.rknn_base.net.get_input_layers()
AttributeError: 'NoneType' object has no attribute 'get_input_layers'
回复

使用道具 举报

jefferyzhang

版主

积分
13580
地板
发表于 2020-5-13 16:26:07 | 只看该作者
RuntimeError: [enforce fail at inline_container.cc:137] . PytorchStreamReader failed reading zip archive: failed finding central directory
自己稍微调试下啊,这里明显是你自己模型都无法被读取,都还没到转换那步。。。
pytorch op不支持显示的是 KeyError:  类似这样的。
回复

使用道具 举报

z792929375

新手上路

积分
25
5#
 楼主| 发表于 2020-5-13 21:42:53 | 只看该作者
本帖最后由 z792929375 于 2020-5-13 22:10 编辑
jefferyzhang 发表于 2020-5-13 16:26
RuntimeError: [enforce fail at inline_container.cc:137] . PytorchStreamReader failed reading zip arc ...

可这个模型就是在我机器上训练出来的啊,测试推理一切正常,不应该无法读取啊。。。
后来尝试导出onnx模型,但在build阶段报错:
E Catch exception when building RKNN model!
E Traceback (most recent call last):
E   File "rknn/base/ovxconfiggenerator.py", line 182, in rknn.base.ovxconfiggenerator.generate_vx_config_from_files
E   File "rknn/base/RKNNlib/app/exporter/ovxlib_case/casegenerator.py", line 531, in rknn.base.RKNNlib.app.exporter.ovxlib_case.casegenerator.CaseGenerator.generate
E   File "rknn/base/RKNNlib/app/exporter/ovxlib_case/casegenerator.py", line 495, in rknn.base.RKNNlib.app.exporter.ovxlib_case.casegenerator.CaseGenerator._gen_special_case
E   File "rknn/base/RKNNlib/app/exporter/ovxlib_case/casegenerator.py", line 462, in rknn.base.RKNNlib.app.exporter.ovxlib_case.casegenerator.CaseGenerator._gen_nb_file
E AttributeError: 'CaseGenerator' object has no attribute 'nbg_graph_file_path'
E During handling of the above exception, another exception occurred:
E Traceback (most recent call last):
E   File "rknn/api/rknn_base.py", line 833, in rknn.api.rknn_base.RKNNBase.build
E   File "rknn/api/rknn_base.py", line 688, in rknn.api.rknn_base.RKNNBase._build
E   File "rknn/base/ovxconfiggenerator.py", line 184, in rknn.base.ovxconfiggenerator.generate_vx_config_from_files
E   File "rknn/api/rknn_log.py", line 312, in rknn.api.rknn_log.RKNNLog.e
E ValueError: Generate nbg failed.
回复

使用道具 举报

zjmmm

中级会员

积分
304
6#
发表于 2020-6-30 10:34:02 | 只看该作者
z792929375 发表于 2020-5-13 21:42
可这个模型就是在我机器上训练出来的啊,测试推理一切正常,不应该无法读取啊。。。
后来尝试导出onnx模型 ...

您好,请问你'NoneType' object has no attribute 'get_input_layers'这个的报错解决了吗?我现在也跟你存在同样的问题。
回复

使用道具 举报

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

本版积分规则

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


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