将tf保存的模型转换为tflite时发生转换错误

时间:2018-11-09 20:05:48

标签: tensorflow tensorflow-lite

我正在尝试将保存的模型tf转换为tflite模式。转换时我在tensorflow c ++中遇到以下错误:-

tensorflow/contrib/lite/toco/tooling_util.cc:981] Check failed: name.substr(colon_pos + 1).find_first_not_of("0123456789") == string::npos (1 vs. 18446744073709551615)Array name must only have digits after colon\n'

以下是源代码:-

def convert_to_tflite_util(model_dir, output_dir):
    tag_constants = set(["train"])
    converter = tf.contrib.lite.TocoConverter.from_saved_model(model_dir, tag_set=tag_constants)
    #converter = tf.contrib.lite.TocoConverter.from_saved_model(model_dir)
    tflite_model = converter.convert()

日志:-

2018-11-09 11:44:11.410085: I tensorflow/core/platform/cpu_feature_guard.cc:141] Your CPU supports instructions that this TensorFlow binary was not compiled to use: AVX2 FMA
INFO:tensorflow:Restoring parameters from /Users/deosingh/code/mldev/sensei-on-device/converters/deeplasso_converter/model/variables/variables
INFO:tensorflow:The given SavedModel MetaGraphDef contains SignatureDefs with the following keys: {'serving_default'}
INFO:tensorflow:input tensors info: 
INFO:tensorflow:Tensor's key in saved_model's tensor_map: input
INFO:tensorflow: tensor name: data:0, shape: (-1, 320, 320, 4), type: DT_FLOAT
INFO:tensorflow:output tensors info: 
INFO:tensorflow:Tensor's key in saved_model's tensor_map: output
INFO:tensorflow: tensor name: prob:0, shape: (1, 320, 320, 2), type: DT_FLOAT
INFO:tensorflow:Restoring parameters from /Users/deosingh/code/mldev/model/variables/variables
INFO:tensorflow:Froze 387 variables.
INFO:tensorflow:Converted 387 variables to const ops.
Traceback (most recent call last):
  File "/Applications/PyCharm CE.app/Contents/helpers/pydev/pydevd.py", line 1664, in <module>
    main()
  File "/Applications/PyCharm CE.app/Contents/helpers/pydev/pydevd.py", line 1658, in main
    globals = debugger.run(setup['file'], None, None, is_module)
  File "/Applications/PyCharm CE.app/Contents/helpers/pydev/pydevd.py", line 1068, in run
    pydev_imports.execfile(file, globals, locals)  # execute the script
  File "/Applications/PyCharm CE.app/Contents/helpers/pydev/_pydev_imps/_pydev_execfile.py", line 18, in execfile
    exec(compile(contents+"\n", file, 'exec'), glob, loc)
  File "/Users/deosingh/code/mldev/src/tf_to_tflite.py", line 112, in <module>
    main()
  File "/Users/deosingh/code/mldev/src/tf_to_tflite.py", line 108, in main
    convert_to_tflite_util(args.src_dir, args.dest_dir)
  File "/Users/deosingh/code/mldev/src/tf_to_tflite.py", line 91, in convert_to_tflite_util
    tflite_model = converter.convert()
  File "/Users/deosingh/code/mldev/venv/lib/python3.6/site-packages/tensorflow/contrib/lite/python/lite.py", line 439, in convert
    **converter_kwargs)
  File "/Users/deosingh/code/mldev/venv/lib/python3.6/site-packages/tensorflow/contrib/lite/python/convert.py", line 309, in toco_convert_impl
    input_data.SerializeToString())
  File "/Users/deosingh/code/mldev/venv/lib/python3.6/site-packages/tensorflow/contrib/lite/python/convert.py", line 109, in toco_convert_protos
    (stdout, stderr))
RuntimeError: TOCO failed see console for info.
b'2018-11-09 11:44:18.328373: F tensorflow/contrib/lite/toco/tooling_util.cc:981] Check failed: name.substr(colon_pos + 1).find_first_not_of("0123456789") == string::npos (1 vs. 18446744073709551615)Array name must only have digits after colon\n'
None

Link to tensorflow source抛出此错误。

原始模型在caffe中,然后使用mmdnn转换为张量流。转换器抱怨名称格式不正确,即根据tf来源,不希望在_之后加上_。请让我知道如何解决/调试此错误。由于引发此错误的tf源在c ++中,并且我是通过python调用的,因此我无法通过macosx上的pycharm对其进行调试。

0 个答案:

没有答案