Tensorflow — Simple Transformations

I am trying out stuff from http://learningtensorflow.com/lesson3/ which talks about simple image transformations using tensorflow. I am trying this out in zeppelin + pyspark. %sh wget http://learningtensorflow.com/images/MarshOrchid.jpg readlink -f MarshOrchid.jpg -------------------------------------------------------------------- %pyspark import numpy as np import StringIO import matplotlib matplotlib.use('Agg') # turn off interactive charting so this works for server side SVG rendering from matplotlib import pyplot as plt import matplotlib.image as mpimg def show(p): img = StringIO.StringIO() p.savefig(img, format='svg') img.seek(0) print "%html <div style='width:600px'>" + img.buf + "</div>" -------------------------------------------------------------------- %pyspark plt.clf() filename = “MarshOrchid.jpg” image = mpimg.imread(filename) print (image.shape) tf.reset_default_graph() x = tf.Variable(image, name=”image”) init = tf.initialize_all_variables() with tf.Session(config=config) as sess: rotate1 = tf.transpose(x, perm=[1, 0, 2]) sess.run(init) result1 = sess.run(rotate1) plt.subplot(121) plt.imshow(image) plt.subplot(122) plt.imshow(result1) show(plt)

November 23, 2016 · 1 min · Bharath

Tensorflow — Order of fetches

I am playing with Tensorflow and found this interesting effect. The following code fragment gives different results each time you run it. tf.reset_default_graph() state = tf.Variable(2.0, name=”state”) one = tf.constant(1.0, name=”one”) update = tf.assign(state, tf.add(state, one)) init = tf.initialize_all_variables() with tf.Session(config=config) as sess: sess.run(init) result = sess.run([update, state]) print(result) result = sess.run([update, state]) print(result) [3.0, 2.0] [4.0, 3.0] [3.0, 2.0] [4.0, 4.0] It looks like the order of fetches in Tensorflow is not fixed. For tensors, they might be evaluated after the ops or before the ops. Depending on the actual order the fetch result will be different.

November 21, 2016 · 1 min · Bharath