tensorflow Save Tensorflow model in Python and load with Java Load and use the model in Java.


public static void main( String[] args ) throws IOException
    // good idea to print the version number, 1.2.0 as of this writing
    final int NUM_PREDICTIONS = 1;

    // load the model Bundle
    try (SavedModelBundle b = SavedModelBundle.load("/tmp/model", "serve")) {

        // create the session from the Bundle
        Session sess = b.session();
        // create an input Tensor, value = 2.0f
        Tensor x = Tensor.create(
            new long[] {NUM_PREDICTIONS}, 
            FloatBuffer.wrap( new float[] {2.0f} ) 
        // run the model and get the result, 4.0f.
        float[] y = sess.runner()
            .feed("x", x)
            .copyTo(new float[NUM_PREDICTIONS]);

        // print out the result.