我正在尝试使用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()