尝试使用tensorflow在从头开始训练的模型上分类android示例时出现异常

时间:2017-07-31 12:59:05

标签: android tensorflow

我从头开始使用inception_v3训练slim模型,创建了冻结模型,将其添加到tensorflow android示例中,我得到以下异常:


E/TensorFlowInferenceInterface: Failed to run TensorFlow inference with inputs:[input], outputs:[InceptionV3/Predictions/Reshape_1]
E/AndroidRuntime: FATAL EXCEPTION: inference
    Process: org.tensorflow.demo, PID: 14648
    java.lang.IllegalArgumentException: Tried to explicitly squeeze dimension 1 but dimension was not 1: 0
    [[Node: InceptionV3/Logits/SpatialSqueeze = Squeeze[T=DT_FLOAT, squeeze_dims=[1, 2], _device="/job:localhost/replica:0/task:0/cpu:0"](InceptionV3/Logits/Conv2d_1c_1x1/BiasAdd)]]
    at org.tensorflow.Session.run(Native Method)
    at org.tensorflow.Session.access$100(Session.java:48)
    at org.tensorflow.Session$Runner.runHelper(Session.java:295)
    at org.tensorflow.Session$Runner.runAndFetchMetadata(Session.java:257)
    at org.tensorflow.contrib.android.TensorFlowInferenceInterface.run(TensorFlowInferenceInterface.java:134)
    at org.tensorflow.demo.TensorFlowImageClassifier.recognizeImage(TensorFlowImageClassifier.java:150)
    at org.tensorflow.demo.ClassifierActivity$2.run(ClassifierActivity.java:228)
    at android.os.Handler.handleCallback(Handler.java:751)
    at android.os.Handler.dispatchMessage(Handler.java:95)
    at android.os.Looper.loop(Looper.java:154)
    at android.os.HandlerThread.run(HandlerThread.java:61)

修改:顺便说一下,我运行了evaluationbazel-bin/tensorflow/examples/label_image/label_image,并且都在macOS上处理了经过培训的模型。

1 个答案:

答案 0 :(得分:2)

问题是INPUT_SIZE。由于inception_v3上的默认图片尺寸为299x299

  The default image size used to train this network is 299x299.

但android示例中的输入大小为224

  private static final int INPUT_SIZE = 224;

将其更改为299解决了问题。