【问题标题】:Can't Load Files with Tensorflow Dataset无法使用 TensorFlow 数据集加载文件
【发布时间】:2018-01-19 11:41:28
【问题描述】:

我正在尝试使用tf.Dataset 来加载输入图像和标签图像。因此,我正在关注 https://www.tensorflow.org/programmers_guide/datasets 上的 Tensorflow 数据集教程。但我得到这个错误:

ValueError: 'images' contains no shape.

我打印了几行:

这就是我的input_files['images/kitchen-1687121_1280.jpg', 'images/room-1706801_1280.jpg']

input_filename:Tensor("arg0:0", shape=(), dtype=string)

image_string:Tensor("ReadFile:0", shape=(), dtype=string)

class DatasetImporter():

    def __init__(self, inputs_path, labels_path):
        self.inputs_path = inputs_path
        self.labels_path = labels_path
        self.dataset = None

    def _get_files(self, path):
        return sorted([path+"/"+f for f in listdir(path) if isfile(join(path, f))])

    def _parse_function(self, input_filename, label_filename):
        print(input_filename) # Tensor("arg0:0", shape=(), dtype=string)
        image_string = tf.read_file(input_filename)
        print(image_string) # Tensor("ReadFile:0", shape=(), dtype=string)
        image_decoded = tf.image.decode_image(image_string)
        image_resized = tf.image.resize_images(image_decoded, [28, 28]) # *ERROR* in this line 
        # Similar for the label...
        return image_resized, label

    def loadData(self):
        input_files = self._get_files(dsi.inputs_path)
        label_files = self._get_files(dsi.labels_path)
        print(input_files) # ['images/kitchen-1687121_1280.jpg', 'images/room-1706801_1280.jpg']
        self.dataset = tf.data.Dataset.from_tensor_slices((tf.constant(input_files), tf.constant(label_files)))
        self.dataset = dataset.map(self._parse_function)

dsi = DatasetImporter("images", "labels")
dsi.loadData()

【问题讨论】:

    标签: python tensorflow tensorflow-datasets


    【解决方案1】:

    问题在于您使用tf.image.decode_image 而不是tf.image.decode_jpeg。由于herehere 描述的一些问题,第一个不返回任何形状。

    我已经写了一个更广泛的答案here

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-10-24
      • 2021-03-29
      • 2015-07-19
      • 1970-01-01
      • 1970-01-01
      • 2023-03-09
      相关资源
      最近更新 更多