我已经训练了对象检测模型。现在,我尝试使用Tensorflow Lite graph converter提供的量化来加快推理速度。但是当我打电话给tf.lite.TFLiteConverter.from_frozen_graph
时
方法,我遇到了错误。
大约一年前,我还发现了一个similar, unanswered question的问题,我想知道TFLite的支持现在是否有所改善。
这就是我要说的:
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
以下是错误日志:
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)
答案 0 :(得分:1)
问题出在tflite转换器不支持的现有tensorflow操作中:
转换不受支持的操作:输入
转换不受支持的操作:大小
转换不受支持的操作:TensorArrayWriteV3
尝试找到一种在原始张量流图中不使用此操作的方法。
请参阅this link,其中提供了有关TFLite支持的操作的信息。