tflite-support icon indicating copy to clipboard operation
tflite-support copied to clipboard

ER: Allow memory mapped files outside the assets folder

Open frippe75 opened this issue 3 years ago • 1 comments

Not sure what hinders from allowing downloading models in runtime and serving them?

https://github.com/tensorflow/tflite-support/blob/master/tensorflow_lite_support/java/src/java/org/tensorflow/lite/support/common/FileUtil.java

  public static MappedByteBuffer loadMappedFile(@NonNull Context context, @NonNull String filePath)
      throws IOException {
    SupportPreconditions.checkNotNull(context, "Context should not be null.");
    SupportPreconditions.checkNotNull(filePath, "File path cannot be null.");
    try (AssetFileDescriptor fileDescriptor = context.getAssets().openFd(filePath);
        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);
    }
  }

frippe75 avatar Feb 05 '22 22:02 frippe75

Can you please provide more detailed description of your problem, such as code snippet, logs, error messages, etc.

lu-wang-g avatar Feb 07 '22 18:02 lu-wang-g