Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Tensorflow Mobile App: Not a valid TensorFlow Graph serialization: NodeDef mentions attr 'dilations' not in Op

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?

like image 950
magenta Avatar asked Dec 16 '17 23:12

magenta


3 Answers

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'
        }
like image 122
Eric White Avatar answered Sep 28 '22 01:09

Eric White


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'
             }
like image 21
Vikas Avatar answered Sep 28 '22 01:09

Vikas


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.

like image 39
eca Avatar answered Sep 27 '22 23:09

eca