Skip to content

Instantly share code, notes, and snippets.

@YoniTsafir
Created March 29, 2017 11:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save YoniTsafir/905d80bee341107bd79f10132f23405d to your computer and use it in GitHub Desktop.
Save YoniTsafir/905d80bee341107bd79f10132f23405d to your computer and use it in GitHub Desktop.
TensorFlow Android Sample Code
import org.tensorflow.contrib.android.TensorFlowInferenceInterface;
/** One time initialization: */
TensorFlowInferenceInterface tensorflow = new TensorFlowInferenceInterface();
tensorflow.initializeTensorFlow(getAssets(), "file:///android_asset/model.pb");
/** Continuous inference (floats used in example, can be any primitive): */
// loading new input
tensorflow.fillNodeFloat("input:0", INPUT_SHAPE, input); // INPUT_SHAPE is an int[] 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};
tensorflow.runInference(outputNodes);
tensorflow.readNodeFloat(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