我正在使用TF 2.2,并尝试使用tf.data创建管道。
下列工程优良:
def load_image(filePath, label):
print('Loading File: {}' + filePath)
raw_bytes = tf.io.read_file(filePath)
image = tf.io.decode_image(raw_bytes, expand_animations = False)
return image, label
# TrainDS Pipeline
trainDS = getDataset()
trainDS = trainDS.shuffle(size['train'])
trainDS = trainDS.map(load_image, num_parallel_calls=AUTOTUNE)
for d in trainDS:
print('Image: {} - Label: {}'.format(d[0], d[1]))
我想将load_image()
与Dataset.interleave()
一起使用。然后我尝试:
# TrainDS Pipeline
trainDS = getDataset()
trainDS = trainDS.shuffle(size['train'])
trainDS = trainDS.interleave(lambda x, y: load_image_with_label(x, y), cycle_length=4)
for d in trainDS:
print('Image: {} - Label: {}'.format(d[0], d[1]))
但我得到以下错误:
Exception has occurred: TypeError
`map_func` must return a `Dataset` object. Got <class 'tuple'>
File "/data/dev/train_daninhas.py", line 44, in <module>
trainDS = trainDS.interleave(lambda x, y: load_image_with_label(x, y), cycle_length=4)
如何修改代码,使Dataset.interleave()
与load_image()
一起并行读取图像?
1条答案
按热度按时间b09cbbtk1#
根据错误提示,您需要修改
load_image
,以便它返回一个Dataset
对象,我已经展示了一个示例,其中有两张图片,说明如何在tensorflow 2.2.0
中执行此操作: