如何使用 ImageDataGenerator().flow_from_dataframe 进行扩充?

How to use augmentations with ImageDataGenerator().flow_from_dataframe?

好像没有map方法:

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

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

当然我可以在模型中使用预处理层,但我需要自定义函数来进行扩充。

您可以使用 ImageDataGeneratorpreprocessing_function 参数来添加额外的扩充。在调整图像大小和增强图像后,该函数将 运行。但是,请注意 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.

所以,也许只使用 tf.keras.utils.image_dataset_from_directory