Tensorflow [Toco]将模型转换为优化格式导致ValueError

时间:2018-11-08 11:43:23

标签: python tensorflow tensorflow-lite toco

我刚开始尝试Tensorflow,我想在Android上做一些实验,但是我读到Tensorflow for Poets(移动版)支持.tflite,而我下载并发现谷歌搜索的模型是.pb。

所以我决定使用toco进行转换,但是当我执行转换命令时,总是会收到此错误

  

ValueError:发现无效的张量“输入”。

CLI命令为:

toco   --graph_def_file=tensorflow_inception_graph.pb   --output_file=optimized_graph.tflite   --input_format=TENSORFLOW_GRAPHDEF --output_format=TFLITE   --input_shape=1,300,300,3   --input_array=input   --o
utput_array=final_result   --inference_type=FLOAT   --inference_input_type=FLOAT

那是怎么了?

Stacktrace

File "/home/Mitro/venv/bin/toco", line 11, in <module>
    sys.exit(main())
  File "/home/Mitro/venv/lib/python3.5/site-packages/tensorflow/contrib/lite/python/tflite_convert.py", line 401, in main
    app.run(main=run_main, argv=sys.argv[:1])
  File "/home/Mitro/venv/lib/python3.5/site-packages/tensorflow/python/platform/app.py", line 125, in run
    _sys.exit(main(argv))
  File "/home/Mitro/venv/lib/python3.5/site-packages/tensorflow/contrib/lite/python/tflite_convert.py", line 397, in run_main
    _convert_model(tflite_flags)
  File "/home/Mitro/venv/lib/python3.5/site-packages/tensorflow/contrib/lite/python/tflite_convert.py", line 100, in _convert_model
    converter = _get_toco_converter(flags)
  File "/home/Mitro/venv/lib/python3.5/site-packages/tensorflow/contrib/lite/python/tflite_convert.py", line 87, in _get_toco_converter
    return converter_fn(**converter_kwargs)
  File "/home/Mitro/venv/lib/python3.5/site-packages/tensorflow/contrib/lite/python/lite.py", line 271, in from_frozen_graph
    sess.graph, input_arrays)
  File "/home/Mitro/venv/lib/python3.5/site-packages/tensorflow/contrib/lite/python/convert_saved_model.py", line 189, in get_tensors_from_tensor_names
    ",".join(invalid_tensors)))

My reference from Google

1 个答案:

答案 0 :(得分:0)

运行此script,将model_file参数更改为pb文件,作为输出,您将具有以下内容:

Tensor(“ import / 占位符:0”,shape =(?, 299,299,3),dtype = float32)
张量(“ import / final_result :0”,shape =(?, 5),dtype = float32)

在这种情况下,它们是您必须通过的参数
--input_array = 占位符
--output_array = 最终结果

Here是完整的信息