How to transform tensorflow PrefetchDataset to use it with ImageDataGenerator for data augmentation?

Viewed 144

I am pretty new to tensorflow and keras and I have an ussue with working "cats_vs_dogs" tensorflow dataset. I am loading it using the tfds.load() function, which gives me an object of type PrefetchDataset. I need to add data augmentation to the training split of this dataset and I'd like to use the tf.keras.preprocessing.image.ImageDataGenerator with it's flow() function. I tried to transform my dataset as follows:

trainDataset = list(trainDataset)
trainDataset = tf.data.Dataset.from_tensor_slices(trainDataset)

but I keep getting InvalidArgumentError: cannot compute Pack as input #1(zero-based) was expected to be a uint8 tensor but is a int64 tensor [Op:Pack] name: 0.

Without this transformation, when calling this function :

train_generator = train_datagen.flow(trainDataset, batch_size = 20)

I get float() argument must be a string or a number, not 'PrefetchDataset'.

How can I transform this dataset to be able to use it with ImageDataGenerator? Or which other apporach can I use for data augmentation in this case?

0 Answers
Related