Dmitry  Sokolov
Dmitry Sokolov

Reputation: 1383

How to use augmentations with ImageDataGenerator().flow_from_dataframe?

Seems like there is no map method:

aug_ds = train_ds.map(
  lambda x, y: (resize_and_rescale(x, training=True), y))

AttributeError: 'DataFrameIterator' object has no attribute 'map'

Of course I can use preprocessing layers in the model, but I need custom functions for augmentations.

Upvotes: 0

Views: 235

Answers (1)

AloneTogether
AloneTogether

Reputation: 26698

You can use the preprocessing_function parameter of the ImageDataGenerator to add additional augmentations. The function will run after the image is resized and augmented. However, note the warning in the docs:

Warning: tf.keras.preprocessing.image.ImageDataGenerator is not recommended for new code. Prefer loading images with tf.keras.utils.image_dataset_from_directory and transforming the output tf.data.Dataset with preprocessing layers. For more information, see the tutorials for loading images and augmenting images, as well as the preprocessing layer guide.

So, maybe just work with tf.keras.utils.image_dataset_from_directory.

Upvotes: 1

Related Questions