Python 将带有布尔输入占位符的TensorFlow模型转换为TensorFlow Lite

Python 将带有布尔输入占位符的TensorFlow模型转换为TensorFlow Lite,python,tensorflow,tensorflow-lite,Python,Tensorflow,Tensorflow Lite,我有一个ResNet模型,我用ubuntu16.04和tensorflowv1.10.0训练过。我想将此模型转换为在TensorFlow Lite中使用 该模型有两个输入占位符。首先是图像(1 x 512 x 512 x 3),然后是一个布尔占位符,该占位符定义为 is_training = tf.placeholder_with_default(False, shape=(), name="is_training") 我将模型转换为独立的GraphDef文件,如下所示: bazel run

我有一个ResNet模型,我用ubuntu16.04和tensorflowv1.10.0训练过。我想将此模型转换为在TensorFlow Lite中使用

该模型有两个输入占位符。首先是图像(1 x 512 x 512 x 3),然后是一个布尔占位符,该占位符定义为

is_training = tf.placeholder_with_default(False, shape=(), name="is_training")
我将模型转换为独立的GraphDef文件,如下所示:

bazel run -c opt tensorflow/python/tools:freeze_graph -- --input_graph=/home/user/model/graph.pbtxt --input_checkpoint=/home/user/model/model-checkpoint --output_graph=/home/user/model/frozen.pb --output_node_names=output
这很有效

在第二步中,我想将独立GraphDef文件转换为TFLite格式:

bazel run -c opt //tensorflow/contrib/lite/python:tflite_convert -- --output_file=/home/user/model/model.lite --graph_def_file=/home/user/model/frozen_model.pb --input_arrays=model_input/input --output_arrays=output --input_shape=1,512,512,3
失败,并显示以下错误消息:

RuntimeError: TOCO failed see console for info.
b'2018-08-14 10:10:00.486547: I tensorflow/core/platform/cpu_feature_guard.cc:141] Your CPU supports instructions that this TensorFlow binary was not compiled to use: SSE4.1 SSE4.2 AVX
2018-08-14 10:10:00.680867: I tensorflow/contrib/lite/toco/import_tensorflow.cc:1096] Converting unsupported operation: Iterator
2018-08-14 10:10:00.680949: I tensorflow/contrib/lite/toco/import_tensorflow.cc:1096] Converting unsupported operation: IteratorGetNext
2018-08-14 10:10:00.804511: I tensorflow/contrib/lite/toco/graph_transformations/graph_transformations.cc:39] Before Removing unused ops: 1662 operators, 2722 arrays (0 quantized)
2018-08-14 10:10:00.860103: I tensorflow/contrib/lite/toco/graph_transformations/graph_transformations.cc:39] After Removing unused ops pass 1: 1551 operators, 2558 arrays (0 quantized)
2018-08-14 10:10:00.933723: I tensorflow/contrib/lite/toco/graph_transformations/graph_transformations.cc:39] Before general graph transformations: 1551 operators, 2558 arrays (0 quantized)
2018-08-14 10:10:00.934610: F tensorflow/contrib/lite/toco/graph_transformations/resolve_tensorflow_switch.cc:95] Check failed: other_op->type == OperatorType::kMerge 
Aborted (core dumped)
'
None
我可以通过将上面的占位符变量替换为

is_training = False
正如我已经描述的那样


我希望避免这种变通方法,直接转换我的模型。有人找到了解决方案吗?

请不要删除某些行并显示整个日志。我还原了您的编辑并将
\n
更改为新行。这很有意义。谢谢@Patwiether是一个看似相关的bug。结论是“错误消息已被更新,以提供有关该问题的更多上下文。不幸的是,支持任意开关语句在不久的将来将不受支持。下一步最好的方法是找出如何从图表中删除该语句。”