5

I tried to replace a graph.pb file in the exampe of https://codelabs.developers.google.com/codelabs/tensorflow-for-poets-2 But it failed to launch in Andriod with the error:

Not a valid TensorFlow Graph serialization: NodeDef mentions attr 'dilations' not in Op name=Conv2D.

12-16 15:06:24.986 4310-4310/org.tensorflow.demo E/AndroidRuntime: Caused by: java.io.IOException: Not a valid TensorFlow Graph serialization: NodeDef mentions attr 'dilations' not in Op<name=Conv2D; signature=input:T, filter:T -> output:T; attr=T:type,allowed=[DT_HALF, DT_FLOAT]; attr=strides:list(int); attr=use_cudnn_on_gpu:bool,default=true; attr=padding:string,allowed=["SAME", "VALID"]; attr=data_format:string,default="NHWC",allowed=["NHWC", "NCHW"]>; NodeDef: conv0/Conv2D = Conv2D[T=DT_FLOAT, data_format="NHWC", dilations=[1, 1, 1, 1], padding="SAME", strides=[1, 2, 2, 1], use_cudnn_on_gpu=true](truediv, conv0/W). (Check whether your GraphDef-interpreting binary is up to date with your GraphDef-generating binary.).
at org.tensorflow.contrib.android.TensorFlowInferenceInterface.loadGraph(TensorFlowInferenceInterface.java:392)

How to generate the inference pb file with the right Conv2D graphDef?

Tom Aranda
  • 5,919
  • 11
  • 35
  • 51
magenta
  • 139
  • 2
  • 8
  • More details about how you obtained the new graph.pb would be useful. Without this info, I am wondering if you tried the step under "Optimize for Inference" in https://codelabs.developers.google.com/codelabs/tensorflow-for-poets-2/#3 – iga Dec 19 '17 at 05:19

3 Answers3

6

I had the same problem and attempted to follow the above workaround. (without success)

But then I was reevaluating the original error. "Version miss match with Tensorflow"

Which lead me to (the obvious) and easy solution which worked for me.

Verify the version of Tensorflow used on the Laptop to build 1.5.0

Set same version in Android build. Slaps forehead....

dependencies {
            compile 'org.tensorflow:tensorflow-android:1.5.0'
        }
Eric White
  • 71
  • 2
2

Make sure to put this in the app gradle file .

dependencies {
            compile 'org.tensorflow:tensorflow-android:+'
//                compile 'org.tensorflow:tensorflow-android:1.2.0-preview'
             }
Vikas
  • 4,263
  • 1
  • 34
  • 39
1

I had the same issue. As explained here, this error seems to be due to a version mismatch between the version of TensorFlow used to run the training script and the version of the library included in your Android application.

To workaround this problem you can try the following:

  • Download the nightly build libtensorflow_* from http://ci.tensorflow.org/view/Nightly/job/nightly-android/lastSuccessfulBuild/artifact/out/
  • Create a directory called "libs" in the root Android demo project directory (besides "assets", "src", "jni", etc.) and copy the (downloaded) libandroid_tensorflow_inference_java.jar in it
  • Inside "libs", create a directory called "armeabi-v7a" (or whatever matches your architecture) and copy the downloaded libtensorflow_demo.so and libtensorflow_inference.so files (corresponding to that architecture) in it
  • In build.gradle, set nativeBuildSystem = 'none' and modify the last "dependencies" as follows:

    dependencies { if (nativeBuildSystem == 'cmake' || nativeBuildSystem == 'none') { implementation files('libs/libandroid_tensorflow_inference_java.jar') } }

  • Compile, upload to the test device and run the app. It worked for me.

eca
  • 411
  • 1
  • 4
  • 11