将Inception V3自定义模型移植到Android Tensor Flow Camera演示中的崩溃

我的目标是:

>使用初始V3 arch:Inception in TensorFlow为我的自定义类(一个类)创建检查点文件
>使用freeze_graph将它们冻结到protobuf(.pb)
>使用optimize_for_inference优化冻结图
>在android TF相机演示中使用pb文件进行分类:TensorFlow Android Camera Demo

在步骤1中,在训练时,批量大小设置为1.
还添加了images = tf.identity(images,name =’Inputs_layer’)来命名张量网络,如问题所示
No Operation named [input] in the Graph” error while fine tuning/retraining inceptionV1 slim model.

在第3步之前,

>> bazel-bin/tensorflow/tools/graph_transforms/summarize_graph --
   in_graph=frozen_graph.pb
   No inputs spotted.
   No variables spotted.
   Found 1 possible outputs: (name=tower_0/logits/predictions, op=Softmax)
   Found 21781804 (21.78M) const parameters, 0 (0) variable parameters, and 188 
   control_edges
   Op types used: 777 Const, 378 Mul, 284 Add, 283 Sub, 190 Identity, 188 Sum, 
   96 Reshape, 94
   Conv2D, 94 StopGradient, 94 SquaredDifference, 94 Square, 94 Mean, 94 Rsqrt, 
   94 Relu, 94
   Reciprocal, 15 ConcatV2, 10 AvgPool, 4 MaxPool, 1 RealDiv, 1 RandomUniform, 1
   QueueDequeueManyV2, 1 Softmax, 1 Split, 1 MatMul, 1 Floor, 1 FIFOQueueV2, 1 
   BiasAdd

在第3步中,

bazel-bin/tensorflow/python/tools/optimize_for_inference \
   --input=tensorflow/examples/android/assets/frozen_graph.pb \
   --output=tensorflow/examples/android/assets/stripped_graph.pb \
   --input_names=inputs_layer \
   --output_names=tower_0/logits/predictions

在第3步之后,

 >>> bazel-bin/tensorflow/tools/graph_transforms/summarize_graph --
   in_graph=stripped_graph.pb
   No inputs spotted.
   No variables spotted.
   Found 1 possible outputs: (name=tower_0/logits/predictions, op=Softmax) 
   Found 21781804 (21.78M) const parameters, 0 (0) variable parameters, and 188 
   control_edges
   Op types used: 777 Const, 378 Mul, 284 Add, 283 Sub, 188 Sum, 96 Reshape, 94 
   Conv2D, 94 StopGradient, 94 SquaredDifference, 94 Square, 94 Mean, 94 Rsqrt, 
   94 Relu, 94 Reciprocal, 15 ConcatV2, 10 AvgPool, 4 MaxPool, 1 RealDiv, 1 
   RandomUniform, 1 QueueDequeueManyV2, 1 Softmax, 1 Split, 1 MatMul, 1 Floor, 1 
   FIFOQueueV2, 1 BiasAdd
   To use with tensorflow/tools/benchmark:benchmark_model try these arguments:
   run tensorflow/tools/benchmark:benchmark_model -- --
   graph=stripped_graph.pb --show_flops --logtostderr --input_layer= --
   input_layer_type= --input_layer_shape= --
   output_layer=tower_0/logits/predictions

在ClassifierActivity.java中,

private static final int INPUT_SIZE = 224;//299; //224;  
private static final int IMAGE_MEAN = 117;
private static final float IMAGE_STD = 1;
private static final String INPUT_NAME = "inputs_layer";
private static final String OUTPUT_NAME = "tower_0/logits/predictions";
private static final String MODEL_FILE = 
                       "file:///android_asset/stripped_graph.pb";
private static final String LABEL_FILE =
      "file:///android_asset/custom_label.txt";

完成以上4个步骤后,APK崩溃登录Android设备:

E/AndroidRuntime( 8558): FATAL EXCEPTION: inference
   E/AndroidRuntime( 8558): Process: org.tensorflow.demo, PID: 8558
   E/AndroidRun time( 8558): java.lang.IllegalArgumentException: No Operation 
   named [inputs_layer] in the Graph

如何解决这个问题?

最佳答案 在优化推理时,它没有正确的输入节点名称.您刚刚给出了inputs_layer,因此在Android中无法正确识别optimized.pb文件.

它说无处输入节点是inputs_layer.给出正确的输入节点名称,它应该工作.

点赞