Revaapriyan
Revaapriyan

Reputation: 309

Error in converting model into Tensorflow-lite

I have trained a custom model using DNN and tried to use TF_Lite for using that in Android. I'm using the same method in the demo app for loading the asset file.

private MappedByteBuffer loadModelFile() throws IOException {
AssetFileDescriptor fileDescriptor = getAssets().openFd(getModelPath());
FileInputStream inputStream = new FileInputStream(fileDescriptor.getFileDescriptor());
FileChannel fileChannel = inputStream.getChannel();
long startOffset = fileDescriptor.getStartOffset();
long declaredLength = fileDescriptor.getDeclaredLength();
return fileChannel.map(FileChannel.MapMode.READ_ONLY, startOffset, declaredLength);

But I'm getting following error.

E/AndroidRuntime: FATAL EXCEPTION: main Process: revan.locationspeed,     
PID: 12072 java.lang.RuntimeException: Unable to start activity     
ComponentInfo{revan.locationspeed/thambu.locationspeed.MainActivity}:     
java.lang.IllegalArgumentException: Contents of /dnn_frozen_graph.tflite     
does not encode a valid TensorFlowLite model: Could not open '/dnn_frozen_graph.tflite'.The model is not a valid Flatbuffer file. 
Caused by: java.lang.IllegalArgumentException: Contents of /dnn_frozen_graph.tflite does not encode a valid TensorFlowLite model: 
Could not open '/dnn_frozen_graph.tflite'.The model is not a valid Flatbuffer file.

I used toco for conversion... A single Activity Class in Android.

Upvotes: 2

Views: 1363

Answers (1)

Revaapriyan
Revaapriyan

Reputation: 309

I added this in Gradle file

aaptOptions {
        noCompress "tflite"
        noCompress "lite"
}

Then the things worked fine.

Upvotes: 2

Related Questions