Skip to content

Instantly share code, notes, and snippets.

@mmeendez8
Created January 18, 2019 12:50
Show Gist options
  • Select an option

  • Save mmeendez8/3643d657ae490dfc762c66d11331ab0e to your computer and use it in GitHub Desktop.

Select an option

Save mmeendez8/3643d657ae490dfc762c66d11331ab0e to your computer and use it in GitHub Desktop.
Test iterator and show images
import matplotlib.pyplot as plt
init_vars = [tf.local_variables_initializer(), tf.global_variables_initializer()]
with tf.Session() as sess:
sess.run([init_vars, iterator.initializer]) # Initialize variables and the iterator
while 1: # Iterate until we get out of range error!
try:
batch = sess.run(input_batch)
print(batch.shape) # Get batch dimensions
plt.imshow(batch[0,:,:,0] , cmap='gray')
plt.show()
except tf.errors.OutOfRangeError: # This exception is triggered when all batches are iterated
print('All batches have been iterated!')
break
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment