I copied a test script to load a directory of images into Tensorflow:
# Typical setup to include TensorFlow.
import tensorflow as tf
from sys import argv
# Make a queue of file names including all the JPEG images files in the relative
# image directory.
filename_queue = tf.train.string_input_producer(
tf.train.match_filenames_once(argv[1] + "/*.jpg"))
# Read an entire image file which is required since they're JPEGs, if the images
# are too large they could be split in advance to smaller files or use the Fixed
# reader to split up the file.
image_reader = tf.WholeFileReader()
# Read a whole file from the queue, the first returned value in the tuple is the
# filename which we are ignoring.
_, image_file = image_reader.read(filename_queue)
# Decode the image as a JPEG file, this will turn it into a Tensor which we can
# then use in training.
image_orig = tf.image.decode_jpeg(image_file)
image = tf.image.resize_images(image_orig, [224, 224])
image.set_shape((224, 224, 3))
# Start a new session to show example output.
with tf.Session() as sess:
However, when I ran the script, I received an odd bug:
OutOfRangeError (see above for traceback): FIFOQueue '_1_input_producer' is closed and has insufficient elements (requested 1, current size 0)
And when I tried to look up a solution, I got several different answers:
tf.initialize_all_variables().run()
tf.local_variables_initializer().run()
sess.run(tf.local_variables_initializer())
sess.run(tf.global_variables_initializer())
coord = tf.train.Coordinator()
threads = tf.train.start_queue_runners(coord=coord)
I have tried all of those options, and all of them have failed. The original script (https://gist.github.com/eerwitt/518b0c9564e500b4b50f) has barely 40 lines. What solution am I missing?
UPDATE
I'm now running this:
# Start a new session to show example output.
with tf.Session() as sess:
# Required to get the filename matching to run.
sess.run(tf.local_variables_initializer())
sess.run(tf.global_variables_initializer())
# Coordinate the loading of image files.
coord = tf.train.Coordinator()
threads = tf.train.start_queue_runners(coord=coord)
# Get an image tensor and print its value.
image_tensor = sess.run([image])
print(image_tensor)
# Finish off the filename queue coordinator.
coord.request_stop()
coord.join(threads)
And the error still occurs.