tflite-support
tflite-support copied to clipboard
ER: Allow memory mapped files outside the assets folder
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);
}
}
Can you please provide more detailed description of your problem, such as code snippet, logs, error messages, etc.