Java Code Examples for org.tensorflow.contrib.android.TensorFlowInferenceInterface#initializeTensorFlow()

The following examples show how to use org.tensorflow.contrib.android.TensorFlowInferenceInterface#initializeTensorFlow() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: Camera2BasicFragment.java    From Cam2Caption with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
TensorFlowInferenceInterface InitSession(){
    inferenceInterface = new TensorFlowInferenceInterface();
    inferenceInterface.initializeTensorFlow(getActivity().getAssets(), MODEL_FILE);
    OutputNodes = LoadFile(OUTPUT_NODES);
    WORD_MAP = LoadFile("idmap");
    return inferenceInterface;
}
 
Example 2
Source File: MainActivity.java    From TFDroid with MIT License 3 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    inferenceInterface = new TensorFlowInferenceInterface();
    inferenceInterface.initializeTensorFlow(getAssets(), MODEL_FILE);


    final Button button = (Button) findViewById(R.id.button);

    button.setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {

            final EditText editNum1 = (EditText) findViewById(R.id.editNum1);
            final EditText editNum2 = (EditText) findViewById(R.id.editNum2);
            final EditText editNum3 = (EditText) findViewById(R.id.editNum3);

            float num1 = Float.parseFloat(editNum1.getText().toString());
            float num2 = Float.parseFloat(editNum2.getText().toString());
            float num3 = Float.parseFloat(editNum3.getText().toString());

            float[] inputFloats = {num1, num2, num3};

            inferenceInterface.fillNodeFloat(INPUT_NODE, INPUT_SIZE, inputFloats);

            inferenceInterface.runInference(new String[] {OUTPUT_NODE});

            float[] resu = {0, 0};
            inferenceInterface.readNodeFloat(OUTPUT_NODE, resu);

            final TextView textViewR = (TextView) findViewById(R.id.txtViewResult);
            textViewR.setText(Float.toString(resu[0]) + ", " + Float.toString(resu[1]));
        }
    });

}