模型转化lite格式报错Output array not found: MobilenetV1/Predictions/Reshape_1

问题一

描述:

~/tensorflow-master$ bazel-bin/tensorflow/contrib/lite/toco/toco  
--input_file=/home/tclxa/下载/TensorFlowMnist-master/output/mnist-tf1.0.1.pb  
--input_format=TENSORFLOW_GRAPHDEF  
--output_format=TFLITE   
--output_file=/tmp/mobilenet_v1_1.0_224.lite 
--inference_type=FLOAT   
--input_type=FLOAT 
--input_arrays=input   
--output_arrays=MobilenetV1/Predictions/Reshape_1 
--input_shapes=1,224,224,3

报错信息:

F tensorflow/contrib/lite/toco/tooling_util.cc:830] 
Check failed: model.HasArray(output_array) Output array not 
found: MobilenetV1/Predictions/Reshape_1

解决:

模型中保存pb文件代码:

MNIST github

softmax_out= tf.nn.softmax(logits, name="out_softmax")
prediction_labels = tf.argmax(softmax_out, axits=1, 
    name="output")

from tensorflow.python.framework import 
graph_util constant_graph =
    graph_util.convert_variables_to_constants(sess, 
    sess.graph_def, ["out_softmax"]) 
with tf.gfile.FastGFile(pb_file_path,mode='wb') as f: 
       f.write(constant_graph.SerializeToString())
修改后的代码

将–output_arrays=MobilenetV1/Predictions/Reshape_1 修改为- -output_arrays=output

 bazel-bin/tensorflow/contrib/lite/toco/toco  
 --input_format=TENSORFLOW_GRAPHDEF  
 --output_file=/tmp/mobilenet_v1_1.0_224.lite 
 --input_type=FLOAT 
--output_arrays=output 
--input_shapes=1,224,224,3 

问题二

报错信息

F tensorflow/contrib/lite/toco/tflite/export.cc:363] Some of 
the operators in the model are not supported by the standard 
TensorFlow Lite runtime.

解决

在命令后面加 --allow_custom_ops:
bazel-bin/tensorflow/contrib/lite/toco/toco  
 --input_format=TENSORFLOW_GRAPHDEF  
 --output_file=/tmp/mobilenet_v1_1.0_224.lite 
 --input_type=FLOAT 
--output_arrays=output 
--input_shapes=1,224,224,3
--allow_custom_ops

你可能感兴趣的:(tensorflow,android)