Smaa ElNagar
Smaa ElNagar

Reputation: 11

java.lang.IllegalArgumentException: ByteBuffer is not a valid flatbuffer model

Please, I'm in desperate need of help, have been trying to solve this for 10 days. The TensorFlow lite model I trained is here. I ran the python inference test and it worked. However, no way it is working on the Android sample object detection app here https://github.com/tensorflow/examples/tree/master/lite/examples/object_detection/android

by debugging the issue this long modelHandle = createModelWithBuffer(this.modelByteBuffer, errorHandle); specifically this part in NativeInterpreterWrapper.class

NativeInterpreterWrapper(ByteBuffer buffer, Options options) {
  this.inferenceDurationNanoseconds = -1L;
  this.isMemoryAllocated = false;
  this.delegates = new ArrayList();
  this.ownedDelegates = new ArrayList();
  TensorFlowLite.init();
  if (buffer != null && (buffer instanceof MappedByteBuffer || buffer.isDirect() && buffer.order() == ByteOrder.nativeOrder())) {
    this.modelByteBuffer = buffer;
    long errorHandle = createErrorReporter(512);
    long modelHandle = createModelWithBuffer(this.modelByteBuffer, errorHandle);
    this.init(errorHandle, modelHandle, options);
  } else {
    throw new IllegalArgumentException("Model ByteBuffer should be either a MappedByteBuffer of the model file, or a direct ByteBuffer using ByteOrder.nativeOrder() which contains bytes of model content.");
  }
}

System information

Have I written custom code (as opposed to using a stock example script provided in TensorFlow): OS Platform MACOS sieera 10.13 Android Studio 4 I have tried every possible solution and updated the NDK I used in the Gradle

buildscript {
    repositories {
        google()
        jcenter()
        mavenLocal()
    }

    aaptOptions {
        noCompress "tflite"
        noCompress "lite"
    }

    implementation 'org.tensorflow:tensorflow-lite-metadata:0.0.0-nightly'
    implementation 'org.tensorflow:tensorflow-lite-select-tf-ops:0.0.0-nightly'
    //also tried
    implementation 'org.tensorflow:tensorflow-lite-metadata:0.1.2-nightly' //and no difference
    //...

Please help me, I don't know if it is the file itself or the android libraries.

Upvotes: 1

Views: 3041

Answers (1)

Sahil13399
Sahil13399

Reputation: 41

There is a chance your model file might be corrupted. I faced the same issue and then I realised my model file was corrupted it was only 4mb in size whereas the actual model size was over 160mb.

Upvotes: 3

Related Questions