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

问题描述 投票:2回答:1

我从头开始使用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训练有素的模型上工作。

android tensorflow
1个回答
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解决了问题。

© www.soinside.com 2019 - 2024. All rights reserved.