我有一个ResNet模型,我使用Ubuntu 16.04和TensorFlow v1.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
我已经描述过here
我想避免这种解决方法,而是直接转换模型。有没有人找到解决方案?