ImageDataGenerator() is deprecated in Tensorflow 2.9

I see TF 2.9.0 deprecates all of tf.keras.preprocessing
(Module: tf.keras.preprocessing  |  TensorFlow Core v2.9.0)

Looks like ImageDataGenerator() is to be replaced by tf.keras.utils.image_dataset_from_directory()

If anyone has examples of code that use the new approach, much appreciated if you could provide examples. If I develop anything I’ll post links here.

I dont think ImageDataGenerator() will be replaced by tf.keras.utils.image_dataset_from_directory(), as far as remember they do different things.

tf.keras.utils.image_dataset_from_directory can replace ImageDataGenerator in many cases. When it comes to week 4 assignment, it can replace ImageDataGenerator since the only operation done is rescaling the image.

The reason I say it can mostly replace ImageDataGenerator is because some functions like shear seem missing from tensorflow.

tf.keras.utils.image_dataset_from_directory returns a Dataset. You can either use a map method in the dataset or use tf.keras.layers.Rescaling directly in the model.

1 Like

Thanks. Do you happen to know, if we take the Google exam, which approach is examined, if either?

Image classification section in this link says that you are likely to get tested on using ImageDataGenerator.

Noticed the same thing, the documentation for ImageDataGenerator contains the following message:

Deprecated: 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.

I don’t mind using it for now, but I think the course content should eventually be updated to use non-deprecated alternatives.

The key word there is “eventually”. These courses were originally published in 2017 and early 2018 (Sequence Models) and TF 2.0 didn’t even exist at that point, so they used TF 1.x. It wasn’t until April of 2021 that they updated them to use TF 2.x. To be fair, that was a pretty major rewrite, so it took a while for them to muster the resources to do that. But for more minor upgrades from, say, TF 2.3.0 to whatever the current version is, what is the real point? TF changes practically every month. All the packages in this space are pretty dynamic. It would not be a good use of their resources to update everything every couple of months just for the sake of being “current” for a week until something else changes. They wait until there’s an important “forcing function” like the TF 2.0 upgrade.

2 Likes

We probably shouldn’t worry. As Paul said, they can’t update the course all the time. If you have mastered the basics, then even if they change the exam, you have 5 hours and it’s an “open book” exam, so you can probably figure out whatever the replacement API is in that amount of time given that it won’t be that different from what it replaced.

1 Like

I just passed the TensorFlow Developer exam yesterday. Came here to follow up to some old threads just to give a hand up to my fellow classmates. Will do so without divulging anything specific from the exam as that would destroy the integrity of the exam and make it worth less to all of us.

The way the exam is graded is not based on your code but on a saved model. So the test doesn’t care really how you generated it, so long as you follow the specs given in the problem. They take the saved model and run some unseen test data on it to score you.

I was able to pass using the things we learned in class, all marked deprecated, specifically for image and text processing.

My advice is try to learn the differences and how both work. After this class, I didn’t really feel ready for the exam, so I also read chapters 10-16 of “Hands On Machine Learning with Keras and TensorFlow” by Aurelien Geron. I highly recommend it, and he covers the non-deprecated ways to these problems. I also did about two dozen practice tutorials straight from the TensorFlow.org website. I think this hands-on practice really helped me personally.

Good luck!

2 Likes