# Augmenting images?

**URL:** <https://discuss.ai.google.dev/t/augmenting-images/29987>\
**Category:** General Discussion\
**Tags:** keras, models, api\
**Created:** [January 13, 2023, 3:05am UTC](https://discuss.ai.google.dev/t/augmenting-images/29987 "2023-01-13T03:05:08Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Margaret\_Johnson](https://d1dlmcr85iqnpo.cloudfront.net/user_avatar/discuss.ai.google.dev/margaret_johnson/32/15465_2.png) [@Margaret\_Johnson](https://discuss.ai.google.dev/u/Margaret_Johnson)\
**Post date:** [January 13, 2023, 3:05am UTC](https://discuss.ai.google.dev/t/augmenting-images/29987/1 "2023-01-13T03:05:08Z")

</div>

I apologize. I am new to tensorflow. My question is most likely obvious (but not to me). I have seen a lot of image augmentation that uses tf.keras.preprocessing.image.ImageGenerator(). In a tensorflow hub example, the author used:

```auto
do_data_augmentation = False
if do_data_augmentation:
  preprocessing_model.add(
      tf.keras.layers.RandomRotation(40))
  preprocessing_model.add(
      tf.keras.layers.RandomTranslation(0, 0.2))
  preprocessing_model.add(
...

```

The other notes the ImageDataGenerator() method is “old”. Why is it old? Why is the new method better? Thank you.

---

<div class="post-metadata">

**Author:** ![chunduriv](https://avatars.discourse-cdn.com/v4/letter/c/bbe5ce/32.png) [@chunduriv](https://discuss.ai.google.dev/u/chunduriv)\
**Post date:** [January 13, 2023, 10:13am UTC](https://discuss.ai.google.dev/t/augmenting-images/29987/3 "2023-01-13T10:13:17Z")

</div>

@Margaret_Johnson,

Welcome to the Tensorflow Forum!

[`tf.keras.preprocessing.image.ImageDataGenerator`](https://www.tensorflow.org/api_docs/python/tf/keras/preprocessing/image/ImageDataGenerator) is obsolete, which is not recommended in the new code. Prefer loading images with [`tf.keras.utils.image_dataset_from_directory`](https://www.tensorflow.org/api_docs/python/tf/keras/utils/image_dataset_from_directory) and transforming the output [`tf.data.Dataset`](https://www.tensorflow.org/api_docs/python/tf/data/Dataset) with preprocessing layers. For more information, see the tutorials for [loading images](https://www.tensorflow.org/tutorials/load_data/images) and [augmenting images](https://www.tensorflow.org/tutorials/images/data_augmentation) as well as the [preprocessing layer guide](https://www.tensorflow.org/guide/keras/preprocessing_layers).

Thank you!
