I'm using TF 2.2 and I'm trying to use tf.data to create a pipeline.
The following works fine:
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])) I would like to use the load_image() with the Dataset.interleave(). Then I tried:
# 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])) But I'm getting the following error:
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) How can I adapt my code to have the Dataset.interleave() working with the load_image() to read the images in parallel ?