我对ML比较陌生,对TensorfFlow也很陌生。我花了很多时间在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的工作
谢谢!
最近添加的^{} API 使此操作更容易:
请注意,对于培训,您需要从某处获得标签。
Dataset.zip()
转换是将image_dataset
与来自不同源的标签数据集组合在一起的可能方法。相关问题 更多 >
编程相关推荐