Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save thepulkitagarwal/4dc64626470d535edda7c7dfa77636fb to your computer and use it in GitHub Desktop.

Select an option

Save thepulkitagarwal/4dc64626470d535edda7c7dfa77636fb to your computer and use it in GitHub Desktop.

Revisions

  1. thepulkitagarwal revised this gist Oct 25, 2017. No changes.
  2. thepulkitagarwal revised this gist Oct 13, 2017. 1 changed file with 5 additions and 5 deletions.
    10 changes: 5 additions & 5 deletions TensorflowAndroidSample.java
    Original file line number Diff line number Diff line change
    @@ -1,16 +1,16 @@
    import org.tensorflow.contrib.android.TensorFlowInferenceInterface;

    /** One time initialization: */
    TensorFlowInferenceInterface tensorflow = new TensorFlowInferenceInterface();
    tensorflow.initializeTensorFlow(getAssets(), "file:///android_asset/model.pb");
    TensorFlowInferenceInterface tensorflow = new TensorFlowInferenceInterface(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
    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};
    tensorflow.runInference(outputNodes);
    tensorflow.readNodeFloat(outputNode, output); // output is a preallocated float[] in the size of the expected output vector
    boolean enableStats = false;
    tensorflow.run(outputNodes, enableStats);
    tensorflow.fetch(outputNode, output); // output is a preallocated float[] in the size of the expected output vector
  3. @YoniTsafir YoniTsafir created this gist Mar 29, 2017.
    16 changes: 16 additions & 0 deletions TensorflowAndroidSample.java
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,16 @@
    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