如何修复"TOCO失败".检查失败:dim> = 1 =(0 vs. 1)"将冻结的图转换为tensorflow_lite模型时出错 [英] How to fix "TOCO failed. Check failed: dim >= 1 (0 vs. 1)" error while converting a frozen graph into a tensorflow_lite model

查看:967
本文介绍了如何修复"TOCO失败".检查失败:dim> = 1 =(0 vs. 1)"将冻结的图转换为tensorflow_lite模型时出错的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经训练了对象检测模型.现在,我正尝试使用 Tensorflow Lite图形转换器.但是当我呼叫tf.lite.TFLiteConverter.from_frozen_graph 方法,我遇到了错误.

I have trained an object detection model. Now I'm trying to speed it up for inference using quantization provided by Tensorflow Lite graph converter. But when I call the tf.lite.TFLiteConverter.from_frozen_graph method, I am running into an error.

我还找到了

I have also found a similar, unanswered question asked almost a year ago and I was wondering if TFLite's support has improved now.

这就是我要说的:

converter = tf.lite.TFLiteConverter.from_frozen_graph(
    model_path,
    input_arrays = ['input_1'],
    output_arrays = [
        'filtered_detections/map/TensorArrayStack/TensorArrayGatherV3',
        'filtered_detections/map/TensorArrayStack_1/TensorArrayGatherV3',
        'filtered_detections/map/TensorArrayStack_2/TensorArrayGatherV3'
        ],
    input_shapes = { 
        'input_1': [None, 300, 300, 3]
        }
    )
converter.post_training_quantize = True
tflite_quantized_model = converter.convert()

我也尝试了input_1的不同参数值,例如[1, 300, 300, 3]等.我什至忽略了input_shapes参数,但随后引发了另一个错误:None is allowed only in 1st dimension. Other dimensions can not be null

I have also tried different parameter values for input_1 like [1, 300, 300, 3] etc. I have even left out the input_shapes parameter but then it throws another error: None is allowed only in 1st dimension. Other dimensions can not be null

以下是错误日志:

File "lib/python3.6/site-packages/tensorflow/lite/python/lite.py", line 500, in convert
    **converter_kwargs)
  File "lib/python3.6/site-packages/tensorflow/lite/python/convert.py", line 442, in toco_convert_impl
    input_data.SerializeToString())
  File "lib/python3.6/site-packages/tensorflow/lite/python/convert.py", line 205, in toco_convert_protos
    "TOCO failed. See console for info.\n%s\n%s\n" % (stdout, stderr))
tensorflow.lite.python.convert.ConverterError: TOCO failed. See console for info.
2019-02-06 18:38:40.906888: I tensorflow/lite/toco/import_tensorflow.cc:1332] Converting unsupported operation: Enter
2019-02-06 18:38:40.915666: I tensorflow/lite/toco/import_tensorflow.cc:1332] Converting unsupported operation: Enter
2019-02-06 18:38:40.917286: I tensorflow/lite/toco/import_tensorflow.cc:1332] Converting unsupported operation: Size
2019-02-06 18:38:40.917308: I tensorflow/lite/toco/import_tensorflow.cc:1332] Converting unsupported operation: Size
...
...
2019-02-06 18:38:40.918758: I tensorflow/lite/toco/import_tensorflow.cc:1332] Converting unsupported operation: TensorArrayWriteV3
2019-02-06 18:38:40.918783: I tensorflow/lite/toco/import_tensorflow.cc:1332] Converting unsupported operation: TensorArrayWriteV3
2019-02-06 18:38:40.918796: I tensorflow/lite/toco/import_tensorflow.cc:1332] Converting unsupported operation: TensorArrayWriteV3
2019-02-06 18:38:40.935936: I tensorflow/lite/toco/graph_transformations/graph_transformations.cc:39] Before Removing unused ops: 952 operators, 1408 arrays (0 quantized)
2019-02-06 18:38:40.955338: I tensorflow/lite/toco/graph_transformations/graph_transformations.cc:39] Before general graph transformations: 952 operators, 1408 arrays (0 quantized)
2019-02-06 18:38:41.234167: I tensorflow/lite/toco/graph_transformations/graph_transformations.cc:39] After general graph transformations pass 1: 396 operators, 708 arrays (0 quantized)
2019-02-06 18:38:41.242773: I tensorflow/lite/toco/graph_transformations/graph_transformations.cc:39] Before Group bidirectional sequence lstm/rnn: 396 operators, 708 arrays (0 quantized)
2019-02-06 18:38:41.249476: I tensorflow/lite/toco/graph_transformations/graph_transformations.cc:39] Before dequantization graph transformations: 396 operators, 708 arrays (0 quantized)
2019-02-06 18:38:41.262130: F tensorflow/lite/toco/tooling_util.cc:633] Check failed: dim >= 1 (0 vs. 1)
Fatal Python error: Aborted

Current thread 0x00007f4930238740 (most recent call first):
  File "lib/python3.6/site-packages/tensorflow/lite/toco/python/toco_from_protos.py", line 33 in execute
  File "lib/python3.6/site-packages/absl/app.py", line 251 in _run_main
  File "lib/python3.6/site-packages/absl/app.py", line 300 in run
  File "lib/python3.6/site-packages/tensorflow/python/platform/app.py", line 40 in run
  File "lib/python3.6/site-packages/tensorflow/lite/toco/python/toco_from_protos.py", line 59 in main
  File "bin/toco_from_protos", line 11 in <module>
Aborted (core dumped)

推荐答案

问题出在tflite转换器不支持的现有tensorflow操作中:

The problem is in existing unsupported tensorflow ops by tflite converter:

转换不受支持的操作:输入

Converting unsupported operation: Enter

转换不受支持的操作:大小

Converting unsupported operation: Size

转换不受支持的操作:TensorArrayWriteV3

Converting unsupported operation: TensorArrayWriteV3

尝试找到一种在原始张量流图中不使用此操作的方法.

Try to find a way to not use this operations in original tensorflow graph.

请参考此链接,其中给出了有关TFLite支持的操作的信息.

Refer this link which gives information on TFLite supported operations.

这篇关于如何修复"TOCO失败".检查失败:dim&gt; = 1 =(0 vs. 1)"将冻结的图转换为tensorflow_lite模型时出错的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆