Created
January 31, 2016 05:52
-
-
Save eerwitt/518b0c9564e500b4b50f to your computer and use it in GitHub Desktop.
Example loading multiple JPEG files with TensorFlow and make them available as Tensors with the shape [[R, G, B], ... ].
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Typical setup to include TensorFlow. | |
import tensorflow as tf | |
# 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("./images/*.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 = tf.image.decode_jpeg(image_file) | |
# Start a new session to show example output. | |
with tf.Session() as sess: | |
# Required to get the filename matching to run. | |
tf.initialize_all_variables().run() | |
# 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) |
filename_queue = tf.train.string_input_producer(tf.train.match_filenames_once('./apple2orange/trainA/*.jpg'))
gives me error TypeError: Fetch argument <tensorflow.python.ops.data_flow_ops.FIFOQueue object at 0xb1a840ef0> has invalid type <class 'tensorflow.python.ops.data_flow_ops.FIFOQueue'>, must be a string or Tensor. (Can not convert a FIFOQueue into a Tensor or Operation.)
can anybody tell me why tf.train.match_filenames_once is giving me error of Can not convert a FIFOQueue into a Tensor or Operation?
how to solve this
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hi all, the code will work after you change the code from
to
I donnot know why, so who can explain it.