我在使用Tensorflow-for-poets-2 TFLite教程中的MappedByteBuffer方法加载TFLite模型时遇到了问题 .

private MappedByteBuffer loadModelFile(Activity activity,String MODEL_FILE) throws IOException {
    AssetFileDescriptor fileDescriptor = activity.getAssets().openFd(MODEL_FILE);
    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);

特别是当我返回fileChannel.map时,我用tflite_convert(以前的toco)工具转换的模型失败了 . 该模型是浮点TFLite模式 .

问题似乎是由startOffset和declaredLength变量引起的 . 我在logcat中收到的错误是

7525-7525/dp.thexor A/libc: Fatal signal 6 (SIGABRT), code -6 in tid 7525 (dp.thexor), pid 7525 (dp.thexor)

如果我将这些值修复为成功加载的模型中的值,则该方法将成功返回fileChannel.map . 我的模型中的值是startOffset = 2846788 declaredLength = 45525464

我知道我的TFlite模型可以成功映射到内存,因为tensorflow / contrib / lite / tools / benchmark:benchmark_model能够对它进行基准测试 .

我尝试加载量化的TFLite模型,但目前我的模型包含没有量化等价物的运算(transpose_conv) .

可能是什么导致了这个?

我的.tflite模型可以在这里找到:https://github.com/andrewginns/CycleGAN-Tensorflow-PyTorch/releases/download/tf1.7-py3.6.4/float.tflite