Forked from YoniTsafir/TensorflowAndroidSample.java
Last active
July 31, 2019 11:04
-
-
Save thepulkitagarwal/4dc64626470d535edda7c7dfa77636fb to your computer and use it in GitHub Desktop.
TensorFlow Android Sample Code, for https://medium.com/@thepulkitagarwal/deploying-a-keras-model-on-android-3a8bb83d75ca
This file contains hidden or 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
import org.tensorflow.contrib.android.TensorFlowInferenceInterface; | |
/** One time initialization: */ | |
TensorFlowInferenceInterface tensorflow = new TensorFlowInferenceInterface(getAssets(), "file:///android_asset/model.pb"); | |
/** Continuous inference (floats used in example, can be any primitive): */ | |
// loading new input | |
tensorflow.feed("input:0", input, INPUT_SHAPE); // INPUT_SHAPE is an long[] of expected shape, input is a float[] with the input data | |
// running inference for given input and reading output | |
String outputNode = "output:0"; | |
String[] outputNodes = {outputNode}; | |
boolean enableStats = false; | |
tensorflow.run(outputNodes, enableStats); | |
tensorflow.fetch(outputNode, output); // output is a preallocated float[] in the size of the expected output vector |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment