Created
January 30, 2019 21:14
-
-
Save frogermcs/65db385dc57fd69ab367db2b94762d38 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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