我从头开始使用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)
编辑:顺便说一句,我运行evaluation
和bazel-bin/tensorflow/examples/label_image/label_image
,两人都在macOS
训练有素的模型上工作。
问题是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解决了问题。