Skip to content

Instantly share code, notes, and snippets.

@frogermcs
Created January 30, 2019 21:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save frogermcs/65db385dc57fd69ab367db2b94762d38 to your computer and use it in GitHub Desktop.
Save frogermcs/65db385dc57fd69ab367db2b94762d38 to your computer and use it in GitHub Desktop.
public static MnistClassifier classifier(AssetManager assetManager, String modelPath) throws IOException {
ByteBuffer byteBuffer = loadModelFile(assetManager, modelPath);
Interpreter interpreter = new Interpreter(byteBuffer);
return new MnistClassifier(interpreter);
}
private static ByteBuffer loadModelFile(AssetManager assetManager, String modelPath) throws IOException {
AssetFileDescriptor fileDescriptor = assetManager.openFd(modelPath);
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);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment