Image loading in TensorFlow

Now let's look at how TensorFlow loads images. Let's define a constant with a small array of three images and load them into a session:

sess = tf.InteractiveSession()image_batch = tf.constant([   [ # First Image     [[255, 0, 0], [255, 0, 0], [0, 255, 0]],     [[255, 0, 0], [255, 0, 0], [0, 255, 0]]   ],   [ # Second Image     [[0, 0, 0], [0, 255, 0], [0, 255, 0]],     [[0, 0, 0], [0, 255, 0], [0, 255, 0]]   ],   [ # Third Image     [[0, 0, 255], [0, 0, 255], [0, 0, 255]],     [[0, 0, 255], [0, 0, 255], [0, 0, 255]]   ] ]) print(image_batch.get_shape()) print(sess.run(image_batch)[1][0][0])

The output of the preceding listing shows the shape of the tensor and the first pixel of the first image. In this example code, an array of images is created ...

Get Neural Network Programming with TensorFlow now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.