【问题标题】:How do I verify images in a TensorFlow Dataset? [duplicate]如何验证 TensorFlow 数据集中的图像? [复制]
【发布时间】:2019-08-04 08:49:24
【问题描述】:

我正在使用取自 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)

我现在想验证图像是否已添加到数据集中并检查尺寸。我该怎么做呢?

【问题讨论】:

    标签: python tensorflow image-segmentation tensorboard tensorflow-datasets


    【解决方案1】:

    访问数据集中元素的标准方法是创建一个迭代器

    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()))
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-12-15
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-12-14
      • 1970-01-01
      • 2017-06-09
      • 2021-04-11
      相关资源
      最近更新 更多