我对机器学习和TensorFlow都比较新手。我花了很多时间在TensorFlow MINST教程上,以及https://github.com/tensorflow/tensorflow/tree/master/tensorflow/examples/how_tos/reading_data,试图找出如何读取自己的数据,但是我有点困惑。
我有一堆图片(.png)在目录/images/0_Non/中。我正在尝试将它们转换成TensorFlow数据集,然后我可以基本上运行MINST教程中的内容作为第一步。
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/0_Non/*.png"))
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)
image = tf.image.decode_png(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)
我有一点难以理解这里发生了什么。所以似乎image
是一个张量,而image_tensor
是一个numpy数组?
我该如何将我的图像放入数据集中?我还尝试了跟随Iris示例(用于CSV),这让我来到了这里:https://github.com/tensorflow/tensorflow/blob/master/tensorflow/contrib/learn/python/learn/datasets/base.py,但不确定如何使其适用于我有大量PNG的情况。
谢谢!