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?
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'
}
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'
}
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:
libandroid_tensorflow_inference_java.jar
in itlibtensorflow_demo.so
and libtensorflow_inference.so
files (corresponding to that architecture) in itIn 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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With