Skip to content

Instantly share code, notes, and snippets.

@leechanwoo
Created August 25, 2017 08:06
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save leechanwoo/cf03c80080605fe32c9fcd5fdc1b3180 to your computer and use it in GitHub Desktop.
Save leechanwoo/cf03c80080605fe32c9fcd5fdc1b3180 to your computer and use it in GitHub Desktop.
key value batch
import tensorflow as tf
import numpy as np
import os
import matplotlib.pyplot as plt
%matplotlib inline
file_dir = os.path.join(os.getcwd(), "dataset/test_dataset_png")
image_paths = [os.path.join(file_dir, i) for i in os.listdir(file_dir)]
filename_queue = tf.train.string_input_producer(image_paths)
reader = tf.WholeFileReader()
key, value = reader.read(filename_queue)
decoded_img = tf.image.decode_png(value)
image = tf.reshape(decoded_img, [61, 49])
filename, train_img = tf.train.batch([key, image], 10)
train_label = tf.string_to_number(tf.substr(filename, 70, 1))
with tf.Session() as sess:
coord = tf.train.Coordinator()
thread = tf.train.start_queue_runners(sess, coord)
_image, _label, _filename = sess.run([train_img, train_label, filename])
imnum = 8
print(_filename[imnum])
print(_label[imnum])
plt.imshow(_image[imnum])
coord.request_stop()
coord.join(thread)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment