java.lang.IllegalArgumentException:ByteBuffer 不是有效的平面缓冲区模型

问题描述 投票:0回答:1

拜托,我迫切需要帮助,已经尝试解决这个问题 10 天了。我训练的 TensorFlow lite 模型在这里。我运行了 python 推理测试并且它有效。但是,它无法在此处的 Android 示例对象检测应用程序上运行 https://github.com/tensorflow/examples/tree/master/lite/examples/object_detection/android

通过调试这么长时间的问题

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.");
  }
}

系统信息

我是否编写了自定义代码(而不是使用 TensorFlow 中提供的库存示例脚本): 操作系统平台 MACOS sieera 10.13 安卓工作室4 我已经尝试了所有可能的解决方案并更新了NDK 我在 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
    //...

请帮助我,我不知道是文件本身还是android库的问题。

android gradle exception object-detection tensorflow-lite
1个回答
3
投票

您的模型文件可能已损坏。我遇到了同样的问题,然后我意识到我的模型文件已损坏,大小只有 4mb,而实际模型大小超过 160mb。

© www.soinside.com 2019 - 2024. All rights reserved.