Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Tensorflow Java API - sophisticated example

I have already asked the question as a github issue, but was redirected to here. I have seen the example for importing model created and trained in Python imported into Java code and used for predictions. However, I had some problems understanding what was actually going on especially in this block and the GraphBuilder class declaration between lines 156-207. Could someone please give some explanation for them?

Moreover, I know the Java API is still under construction. However, I would be interested in if it is possible to see some more sophisticated examples, if it is possible including:

  • importing model into Java and then performing training on the model

  • implementing, training, evaluating, saving, loading a model from scratch in Java with Tensorflow

Does anyone have such an example, and willing to share it?

Thank you for any help!

Cheers,

Peter

like image 712
szi Avatar asked Apr 19 '17 07:04

szi


1 Answers

The code block you pointed to generates a TensorFlow graph to "normalize" an image so that the image can be fed into the other TensorFlow graph (inception). It is achieving the equivalent of something like this in Python:

image = tf.cast(tf.image.decode_jpeg(input, channels = 3), tf.float32)
batch = tf.expand_dims(image, 0);
resized = tf.image.resize_bilinear(dims_expander, [input_height, input_width])
normalized = tf.divide(tf.subtract(resized, [input_mean]), [input_std])

Many of the Python functions for executing TensorFlow operations (like tf.cast, tf.image.decode_jpeg etc.) are generated from the TensorFlow op definitions. However, such generated functions do not exist yet in the Java API so the operations have to be constructed from lower level primitives, which is what the GraphBuilder class is doing.

Hope that helps.

Your other questions seem too broad, so not sure how to answer them here.

like image 106
ash Avatar answered Oct 06 '22 23:10

ash