【发布时间】:2017-06-22 22:55:57
【问题描述】:
我是 tensorflow 的新手,所以我想先测试一下我的基本函数。我有以下读取数据的python方法:
def read_data(filename_queue):
# Whole file reader required for jpeg decoding
image_reader = tf.WholeFileReader()
# We don't care about the filename, so we ignore the first tuple
_, image_file = image_reader.read(filename_queue)
# Decode the jpeg images and set them to a universal size
# so we don't run into "out of bounds" issues down the road
image_orig = tf.image.decode_jpeg(image_file, channels=3)
image = tf.image.resize_images(image_orig, [224, 224])
return image
“filename_queue”是“images”子目录中各个 jpeg 文件的路径队列。我运行一个 for 循环遍历文件名,以确保只有具有有效路径的文件名被添加到队列中:
filenames = []
for i in range(1000):
filename = os.path.join(os.path.dirname(os.path.realpath(__file__)),
"./images/seatbelt%d.jpg" % i)
if not tf.gfile.Exists(filename):
# print("Filename %s does not exist" % filename)
continue
else:
filenames.append(filename)
# Create a string queue out of all filenames found in local 'images' directory
filename_queue = tf.train.string_input_producer(filenames)
input = read_data(filename_queue)
我想断言图像被正确读取并且所有数据都包含在重新整形的张量中。我怎么能这样做?
【问题讨论】:
标签: python tensorflow