如何验证 TensorFlow 数据集中的图像?
How do I verify images in a TensorFlow Dataset?
我正在使用从 TensorFlow 文档中获取的以下代码创建标签和图像的张量流数据集 here。
# Reads an image from a file, decodes it into a dense tensor, and resizes it
# to a fixed shape.
def _parse_function(filename, label):
image_string = tf.read_file(filename)
image_decoded = tf.image.decode_jpeg(image_string)
image_resized = tf.image.resize_images(image_decoded, [28, 28])
return image_resized, label
# A vector of filenames.
filenames = tf.constant(["/var/data/image1.jpg", "/var/data/image2.jpg", ...])
# `labels[i]` is the label for the image in `filenames[i].
labels = tf.constant([0, 37, ...])
dataset = tf.data.Dataset.from_tensor_slices((filenames, labels))
dataset = dataset.map(_parse_function)
我现在想验证图像是否已添加到数据集中并检查尺寸。我该怎么做?
访问数据集中元素的标准方法是创建迭代器
iterator = dataset.make_one_shot_iterator()
image, label = iterator.get_next()
with tf.Session() as sess:
print(sess.run(label))
print(sess.run(image.get_shape()))
我正在使用从 TensorFlow 文档中获取的以下代码创建标签和图像的张量流数据集 here。
# Reads an image from a file, decodes it into a dense tensor, and resizes it
# to a fixed shape.
def _parse_function(filename, label):
image_string = tf.read_file(filename)
image_decoded = tf.image.decode_jpeg(image_string)
image_resized = tf.image.resize_images(image_decoded, [28, 28])
return image_resized, label
# A vector of filenames.
filenames = tf.constant(["/var/data/image1.jpg", "/var/data/image2.jpg", ...])
# `labels[i]` is the label for the image in `filenames[i].
labels = tf.constant([0, 37, ...])
dataset = tf.data.Dataset.from_tensor_slices((filenames, labels))
dataset = dataset.map(_parse_function)
我现在想验证图像是否已添加到数据集中并检查尺寸。我该怎么做?
访问数据集中元素的标准方法是创建迭代器
iterator = dataset.make_one_shot_iterator()
image, label = iterator.get_next()
with tf.Session() as sess:
print(sess.run(label))
print(sess.run(image.get_shape()))