1

I am trying to run mobilenet model trained over imagenet on Android Tensorflow for object recognition and facing the issue as described below.

 TensorFlowInferenceInterface: Failed to load model 
    from 'file:///android_asset/mobilenet_imagenet.pb': java.io.IOException: 
    Not a valid TensorFlow Graph serialization: 
    NodeDef mentions attr 'data_format' not in Op<name=DepthwiseConv2dNative;
    signature=input:T, filter:T -> output:T; 
    attr=T:type,allowed=[DT_FLOAT, DT_DOUBLE]; attr=strides:list(int); 
    attr=padding:string,allowed=["SAME", "VALID"]>; 
    NodeDef: conv_dw_1/depthwise = 
DepthwiseConv2dNative[T=DT_FLOAT, data_format="NHWC", padding="SAME", strides=[1, 1, 1, 1]]
    (conv1_relu/clip_by_value, conv_dw_1/depthwise_kernel/read)

I followed the tutorial as given in the link to integrate Tensorflow on Android. I could run basic CNN classifier custom trained (using python 2.7.12, Tensorflow 1.2 on Ubuntu 16.04)and it is working fine.

I could successfully run Mobilenet trained over imagenet on python 2.7.12 on Ubuntu 16.04 using Tensorflow 1.2 and 1.3. Now when I try to run the same '.pb' model on Android it gives me the error as mentioned above.

The code for initializing the model is as given below :

TensorFlowImageClassifier c = new TensorFlowImageClassifier();
c.inferenceInterface = new TensorFlowInferenceInterface();
if (c.inferenceInterface.initializeTensorFlow(assetManager, modelFilename) != 0) {
         throw new RuntimeException("TF initialization failed");
}

Please provide me a solution or a work around

Vikas
  • 116
  • 10

2 Answers2

4

The above issue has been resolved by updating the "libandroid_tensorflow_inference_java.jar" and "libtensorflow_inference.so" to the latest version i.e. Tensorflow - 1.4. The latest ".jar" and ".so" files can be found here.

The issue was due to mismatch of Tensorflow versions. Mobilenet classifier trained over ImageNet was built on Tensorflow - 1.3 and was being used for inference on Android with Tensorflow - 1.1.

Vikas
  • 116
  • 10
0

It says here in main activity java file

private static final String MODEL_FILE = "file:///android_asset/expert-graph.pb";
private static final String LABEL_FILE = "file:///android_asset/labels.txt";

Where your model files seems to be "mobilenet_imagenet.pb". After you make sure your model and labels name match for the project file here, change the input size what you trained on.(retrain.py file maybe has this information.)

private static final int INPUT_SIZE = 160;//
private static final int IMAGE_MEAN = 128;
private static final float IMAGE_STD = 128;
private static final String OUTPUT_NAME = "final_result";
NONONONONO
  • 612
  • 1
  • 6
  • 10
  • Thank you for the response. I have already initialized the variables as you have suggested. But the error occurs while it executes this.load((InputStream)var4); inside c.inferenceInterface.initializeTensorFlow(assetManager, modelFilename) – Vikas Oct 27 '17 at 09:57