使用内置的Tensorflow(1.13.1)tflite_convert工具从保存的.pb Tensorflow模型转换为.tflite Tensorflow Lite模型时,我遇到问题,我想知道如何解决这个问题问题。执行时:
tflite_convert --output_file done --graph_def_file reshaped_t.pb --input_arrays the_input --output_arrays ctc/ExpandDims --allow_custom_ops
我遇到了错误:
F tensorflow/lite/toco/graph_transformations/propagate_fixed_sizes.cc:1499] Check failed: dim_size > 0 (0 vs. 0)Output size for an axis must be greater than 0. Axis 0 computes to size 0 for StridedSlice op with output "ctc/boolean_mask/strided_slice_1".
作为背景,.pb文件表示的模型最初是Keras模型,其结构如下。我使用位于https://github.com/amir-abdi/keras_to_tensorflow
__________________________________________________________________________________________________
Layer (type) Output Shape Param # Connected to
==================================================================================================
the_input (InputLayer) (1, 584, 13) 0
__________________________________________________________________________________________________
layer_1_conv (Conv1D) (1, 287, 200) 28800 the_input[0][0]
__________________________________________________________________________________________________
conv_batch_norm (BatchNormaliza (1, 287, 200) 800 layer_1_conv[0][0]
__________________________________________________________________________________________________
rnn_1 (GRU) (1, 287, 250) 338250 conv_batch_norm[0][0]
__________________________________________________________________________________________________
bt_rnn_1 (BatchNormalization) (1, 287, 250) 1000 rnn_1[0][0]
__________________________________________________________________________________________________
final_layer_of_rnn (GRU) (1, 287, 250) 375750 bt_rnn_1[0][0]
__________________________________________________________________________________________________
bt_rnn_final (BatchNormalizatio (1, 287, 250) 1000 final_layer_of_rnn[0][0]
__________________________________________________________________________________________________
time_distributed_13 (TimeDistri (1, 287, 29) 7279 bt_rnn_final[0][0]
__________________________________________________________________________________________________
input_length (InputLayer) (1, 1) 0
__________________________________________________________________________________________________
softmax (Activation) (1, 287, 29) 0 time_distributed_13[0][0]
__________________________________________________________________________________________________
the_labels (InputLayer) (1, 29) 0
__________________________________________________________________________________________________
lambda_24 (Lambda) (1, 1) 0 input_length[0][0]
__________________________________________________________________________________________________
label_length (InputLayer) (1, 1) 0
__________________________________________________________________________________________________
ctc (Lambda) (1, 1) 0 softmax[0][0]
the_labels[0][0]
lambda_24[0][0]
label_length[0][0]
==================================================================================================
Total params: 752,879
Trainable params: 751,479
Non-trainable params: 1,400
__________________________________________________________________________________________________
>>>
此外,这是tflite_convert的完整日志输出:
2019-06-19 14:49:24.878900: I tensorflow/core/platform/cpu_feature_guard.cc:141] Your CPU supports instructions that this TensorFlow binary was not compiled to use: AVX2 FMA
Traceback (most recent call last):
File "/anaconda3/bin/tflite_convert", line 10, in <module>
sys.exit(main())
File "/anaconda3/lib/python3.7/site-packages/tensorflow/lite/python/tflite_convert.py", line 442, in main
app.run(main=run_main, argv=sys.argv[:1])
File "/anaconda3/lib/python3.7/site-packages/tensorflow/python/platform/app.py", line 125, in run
_sys.exit(main(argv))
File "/anaconda3/lib/python3.7/site-packages/tensorflow/lite/python/tflite_convert.py", line 438, in run_main
_convert_model(tflite_flags)
File "/anaconda3/lib/python3.7/site-packages/tensorflow/lite/python/tflite_convert.py", line 191, in _convert_model
output_data = converter.convert()
File "/anaconda3/lib/python3.7/site-packages/tensorflow/lite/python/lite.py", line 455, in convert
**converter_kwargs)
File "/anaconda3/lib/python3.7/site-packages/tensorflow/lite/python/convert.py", line 442, in toco_convert_impl
input_data.SerializeToString())
File "/anaconda3/lib/python3.7/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-06-19 14:49:25.969310: I tensorflow/lite/toco/import_tensorflow.cc:1324] Converting unsupported operation: TensorArrayV3
2019-06-19 14:49:25.977488: I tensorflow/lite/toco/import_tensorflow.cc:193] Unsupported data type in placeholder op: 20
2019-06-19 14:49:25.977507: I tensorflow/lite/toco/import_tensorflow.cc:1324] Converting unsupported operation: TensorArrayV3
2019-06-19 14:49:25.977516: I tensorflow/lite/toco/import_tensorflow.cc:193] Unsupported data type in placeholder op: 20
2019-06-19 14:49:25.977560: I tensorflow/lite/toco/import_tensorflow.cc:1324] Converting unsupported operation: TensorArrayScatterV3
2019-06-19 14:49:25.977579: I tensorflow/lite/toco/import_tensorflow.cc:1324] Converting unsupported operation: Enter
2019-06-19 14:49:25.977589: I tensorflow/lite/toco/import_tensorflow.cc:1324] Converting unsupported operation: Enter
2019-06-19 14:49:25.977598: I tensorflow/lite/toco/import_tensorflow.cc:1324] Converting unsupported operation: Enter
2019-06-19 14:49:25.977606: I tensorflow/lite/toco/import_tensorflow.cc:1324] Converting unsupported operation: Enter
2019-06-19 14:49:25.977626: I tensorflow/lite/toco/import_tensorflow.cc:1324] Converting unsupported operation: Enter
2019-06-19 14:49:25.977638: I tensorflow/lite/toco/import_tensorflow.cc:1324] Converting unsupported operation: Enter
2019-06-19 14:49:25.977649: I tensorflow/lite/toco/import_tensorflow.cc:1324] Converting unsupported operation: LoopCond
2019-06-19 14:49:25.977680: I tensorflow/lite/toco/import_tensorflow.cc:1324] Converting unsupported operation: Enter
2019-06-19 14:49:25.977686: I tensorflow/lite/toco/import_tensorflow.cc:193] Unsupported data type in placeholder op: 20
2019-06-19 14:49:25.977692: I tensorflow/lite/toco/import_tensorflow.cc:1324] Converting unsupported operation: Enter
2019-06-19 14:49:25.977700: I tensorflow/lite/toco/import_tensorflow.cc:1324] Converting unsupported operation: TensorArrayReadV3
2019-06-19 14:49:25.977707: I tensorflow/lite/toco/import_tensorflow.cc:1324] Converting unsupported operation: Enter
2019-06-19 14:49:25.977721: I tensorflow/lite/toco/import_tensorflow.cc:1324] Converting unsupported operation: Enter
2019-06-19 14:49:25.977792: I tensorflow/lite/toco/import_tensorflow.cc:1324] Converting unsupported operation: Enter
2019-06-19 14:49:25.977928: I tensorflow/lite/toco/import_tensorflow.cc:1324] Converting unsupported operation: Enter
2019-06-19 14:49:25.977937: I tensorflow/lite/toco/import_tensorflow.cc:193] Unsupported data type in placeholder op: 20
2019-06-19 14:49:25.977944: I tensorflow/lite/toco/import_tensorflow.cc:1324] Converting unsupported operation: TensorArrayWriteV3
2019-06-19 14:49:25.977962: I tensorflow/lite/toco/import_tensorflow.cc:1324] Converting unsupported operation: Exit
2019-06-19 14:49:25.977968: I tensorflow/lite/toco/import_tensorflow.cc:1324] Converting unsupported operation: TensorArraySizeV3
2019-06-19 14:49:25.977989: I tensorflow/lite/toco/import_tensorflow.cc:1324] Converting unsupported operation: TensorArrayGatherV3
2019-06-19 14:49:25.978827: I tensorflow/lite/toco/import_tensorflow.cc:1324] Converting unsupported operation: TensorArrayV3
2019-06-19 14:49:25.978838: I tensorflow/lite/toco/import_tensorflow.cc:193] Unsupported data type in placeholder op: 20
2019-06-19 14:49:25.978847: I tensorflow/lite/toco/import_tensorflow.cc:1324] Converting unsupported operation: TensorArrayV3
2019-06-19 14:49:25.978853: I tensorflow/lite/toco/import_tensorflow.cc:193] Unsupported data type in placeholder op: 20
2019-06-19 14:49:25.978887: I tensorflow/lite/toco/import_tensorflow.cc:1324] Converting unsupported operation: TensorArrayScatterV3
2019-06-19 14:49:25.978904: I tensorflow/lite/toco/import_tensorflow.cc:1324] Converting unsupported operation: Enter
2019-06-19 14:49:25.978912: I tensorflow/lite/toco/import_tensorflow.cc:1324] Converting unsupported operation: Enter
2019-06-19 14:49:25.978920: I tensorflow/lite/toco/import_tensorflow.cc:1324] Converting unsupported operation: Enter
2019-06-19 14:49:25.978929: I tensorflow/lite/toco/import_tensorflow.cc:1324] Converting unsupported operation: Enter
2019-06-19 14:49:25.978947: I tensorflow/lite/toco/import_tensorflow.cc:1324] Converting unsupported operation: Enter
2019-06-19 14:49:25.978957: I tensorflow/lite/toco/import_tensorflow.cc:1324] Converting unsupported operation: Enter
2019-06-19 14:49:25.978968: I tensorflow/lite/toco/import_tensorflow.cc:1324] Converting unsupported operation: LoopCond
2019-06-19 14:49:25.979003: I tensorflow/lite/toco/import_tensorflow.cc:1324] Converting unsupported operation: Enter
2019-06-19 14:49:25.979009: I tensorflow/lite/toco/import_tensorflow.cc:193] Unsupported data type in placeholder op: 20
2019-06-19 14:49:25.979016: I tensorflow/lite/toco/import_tensorflow.cc:1324] Converting unsupported operation: Enter
2019-06-19 14:49:25.979024: I tensorflow/lite/toco/import_tensorflow.cc:1324] Converting unsupported operation: TensorArrayReadV3
2019-06-19 14:49:25.979031: I tensorflow/lite/toco/import_tensorflow.cc:1324] Converting unsupported operation: Enter
2019-06-19 14:49:25.979042: I tensorflow/lite/toco/import_tensorflow.cc:1324] Converting unsupported operation: Enter
2019-06-19 14:49:25.979116: I tensorflow/lite/toco/import_tensorflow.cc:1324] Converting unsupported operation: Enter
2019-06-19 14:49:25.979261: I tensorflow/lite/toco/import_tensorflow.cc:1324] Converting unsupported operation: Enter
2019-06-19 14:49:25.979268: I tensorflow/lite/toco/import_tensorflow.cc:193] Unsupported data type in placeholder op: 20
2019-06-19 14:49:25.979276: I tensorflow/lite/toco/import_tensorflow.cc:1324] Converting unsupported operation: TensorArrayWriteV3
2019-06-19 14:49:25.979296: I tensorflow/lite/toco/import_tensorflow.cc:1324] Converting unsupported operation: Exit
2019-06-19 14:49:25.979305: I tensorflow/lite/toco/import_tensorflow.cc:1324] Converting unsupported operation: TensorArraySizeV3
2019-06-19 14:49:25.979327: I tensorflow/lite/toco/import_tensorflow.cc:1324] Converting unsupported operation: TensorArrayGatherV3
2019-06-19 14:49:25.979453: I tensorflow/lite/toco/import_tensorflow.cc:1324] Converting unsupported operation: TensorArrayV3
2019-06-19 14:49:25.979462: I tensorflow/lite/toco/import_tensorflow.cc:193] Unsupported data type in placeholder op: 20
2019-06-19 14:49:25.979472: I tensorflow/lite/toco/import_tensorflow.cc:1324] Converting unsupported operation: TensorArrayV3
2019-06-19 14:49:25.979480: I tensorflow/lite/toco/import_tensorflow.cc:193] Unsupported data type in placeholder op: 20
2019-06-19 14:49:25.979516: I tensorflow/lite/toco/import_tensorflow.cc:1324] Converting unsupported operation: TensorArrayScatterV3
2019-06-19 14:49:25.979533: I tensorflow/lite/toco/import_tensorflow.cc:1324] Converting unsupported operation: Enter
2019-06-19 14:49:25.979542: I tensorflow/lite/toco/import_tensorflow.cc:1324] Converting unsupported operation: Enter
2019-06-19 14:49:25.979551: I tensorflow/lite/toco/import_tensorflow.cc:1324] Converting unsupported operation: Enter
2019-06-19 14:49:25.979569: I tensorflow/lite/toco/import_tensorflow.cc:1324] Converting unsupported operation: Enter
2019-06-19 14:49:25.979580: I tensorflow/lite/toco/import_tensorflow.cc:1324] Converting unsupported operation: Enter
2019-06-19 14:49:25.979591: I tensorflow/lite/toco/import_tensorflow.cc:1324] Converting unsupported operation: LoopCond
2019-06-19 14:49:25.979622: I tensorflow/lite/toco/import_tensorflow.cc:1324] Converting unsupported operation: Enter
2019-06-19 14:49:25.979628: I tensorflow/lite/toco/import_tensorflow.cc:193] Unsupported data type in placeholder op: 20
2019-06-19 14:49:25.979637: I tensorflow/lite/toco/import_tensorflow.cc:1324] Converting unsupported operation: Enter
2019-06-19 14:49:25.979645: I tensorflow/lite/toco/import_tensorflow.cc:1324] Converting unsupported operation: TensorArrayReadV3
2019-06-19 14:49:25.979653: I tensorflow/lite/toco/import_tensorflow.cc:1324] Converting unsupported operation: Enter
2019-06-19 14:49:25.979667: I tensorflow/lite/toco/import_tensorflow.cc:1324] Converting unsupported operation: Enter
2019-06-19 14:49:25.979680: I tensorflow/lite/toco/import_tensorflow.cc:1324] Converting unsupported operation: Enter
2019-06-19 14:49:25.979686: I tensorflow/lite/toco/import_tensorflow.cc:193] Unsupported data type in placeholder op: 20
2019-06-19 14:49:25.979693: I tensorflow/lite/toco/import_tensorflow.cc:1324] Converting unsupported operation: TensorArrayWriteV3
2019-06-19 14:49:25.979714: I tensorflow/lite/toco/import_tensorflow.cc:1324] Converting unsupported operation: Exit
2019-06-19 14:49:25.979721: I tensorflow/lite/toco/import_tensorflow.cc:1324] Converting unsupported operation: TensorArraySizeV3
2019-06-19 14:49:25.979741: I tensorflow/lite/toco/import_tensorflow.cc:1324] Converting unsupported operation: TensorArrayGatherV3
2019-06-19 14:49:25.979867: I tensorflow/lite/toco/import_tensorflow.cc:1324] Converting unsupported operation: TensorArrayV3
2019-06-19 14:49:25.979875: I tensorflow/lite/toco/import_tensorflow.cc:193] Unsupported data type in placeholder op: 20
2019-06-19 14:49:25.979911: I tensorflow/lite/toco/import_tensorflow.cc:1324] Converting unsupported operation: TensorArrayScatterV3
2019-06-19 14:49:25.979926: I tensorflow/lite/toco/import_tensorflow.cc:1324] Converting unsupported operation: TensorArrayV3
2019-06-19 14:49:25.979935: I tensorflow/lite/toco/import_tensorflow.cc:193] Unsupported data type in placeholder op: 20
2019-06-19 14:49:25.979947: I tensorflow/lite/toco/import_tensorflow.cc:1324] Converting unsupported operation: Enter
2019-06-19 14:49:25.979956: I tensorflow/lite/toco/import_tensorflow.cc:1324] Converting unsupported operation: Enter
2019-06-19 14:49:25.979964: I tensorflow/lite/toco/import_tensorflow.cc:1324] Converting unsupported operation: Enter
2019-06-19 14:49:25.979979: I tensorflow/lite/toco/import_tensorflow.cc:1324] Converting unsupported operation: Enter
2019-06-19 14:49:25.979994: I tensorflow/lite/toco/import_tensorflow.cc:1324] Converting unsupported operation: LoopCond
2019-06-19 14:49:25.980024: I tensorflow/lite/toco/import_tensorflow.cc:1324] Converting unsupported operation: Enter
2019-06-19 14:49:25.980030: I tensorflow/lite/toco/import_tensorflow.cc:193] Unsupported data type in placeholder op: 20
2019-06-19 14:49:25.980036: I tensorflow/lite/toco/import_tensorflow.cc:1324] Converting unsupported operation: Enter
2019-06-19 14:49:25.980045: I tensorflow/lite/toco/import_tensorflow.cc:1324] Converting unsupported operation: TensorArrayReadV3
2019-06-19 14:49:25.980066: I tensorflow/lite/toco/import_tensorflow.cc:1324] Converting unsupported operation: Enter
2019-06-19 14:49:25.980097: I tensorflow/lite/toco/import_tensorflow.cc:1324] Converting unsupported operation: Enter
2019-06-19 14:49:25.980111: I tensorflow/lite/toco/import_tensorflow.cc:1324] Converting unsupported operation: Enter
2019-06-19 14:49:25.980118: I tensorflow/lite/toco/import_tensorflow.cc:193] Unsupported data type in placeholder op: 20
2019-06-19 14:49:25.980125: I tensorflow/lite/toco/import_tensorflow.cc:1324] Converting unsupported operation: TensorArrayWriteV3
2019-06-19 14:49:25.980144: I tensorflow/lite/toco/import_tensorflow.cc:1324] Converting unsupported operation: Exit
2019-06-19 14:49:25.980151: I tensorflow/lite/toco/import_tensorflow.cc:1324] Converting unsupported operation: TensorArraySizeV3
2019-06-19 14:49:25.980172: I tensorflow/lite/toco/import_tensorflow.cc:1324] Converting unsupported operation: TensorArrayGatherV3
2019-06-19 14:49:25.980305: I tensorflow/lite/toco/import_tensorflow.cc:1324] Converting unsupported operation: Where
2019-06-19 14:49:25.980350: I tensorflow/lite/toco/import_tensorflow.cc:1324] Converting unsupported operation: ReverseV2
2019-06-19 14:49:25.980440: I tensorflow/lite/toco/import_tensorflow.cc:1324] Converting unsupported operation: Where
2019-06-19 14:49:25.980472: I tensorflow/lite/toco/import_tensorflow.cc:1324] Converting unsupported operation: GatherNd
2019-06-19 14:49:25.980496: I tensorflow/lite/toco/import_tensorflow.cc:1324] Converting unsupported operation: CTCLoss
2019-06-19 14:49:25.985282: I tensorflow/lite/toco/graph_transformations/graph_transformations.cc:39] Before Removing unused ops: 350 operators, 629 arrays (0 quantized)
2019-06-19 14:49:25.989871: I tensorflow/lite/toco/graph_transformations/graph_transformations.cc:39] Before general graph transformations: 350 operators, 629 arrays (0 quantized)
2019-06-19 14:49:25.999322: F tensorflow/lite/toco/graph_transformations/propagate_fixed_sizes.cc:1499] Check failed: dim_size > 0 (0 vs. 0)Output size for an axis must be greater than 0. Axis 0 computes to size 0 for StridedSlice op with output "ctc/boolean_mask/strided_slice_1".
如有必要,我很乐意提供更多背景信息。
答案 0 :(得分:0)
当前TensorFlow Lite不支持TensorArray和Control Flow操作(例如Enter)。其他错误可能是由于不受支持的操作。
这些操作似乎来自GRU。您可以尝试传递unroll=True
并查看它是否有效吗? (如果您的模型处理的是固定数量的时间步,那将是可行的)
我们正在积极地进行控制流程,并希望能尽快(在1个月内)使某些东西工作。