How to use model.fit() which supports generators (because fit_generator() is deprecated)?

Muhammad Iqbal bazmi
2 min readMar 14, 2021

--

Let’s solve this issue…

Photo by Jason Leung on Unsplash

I have personally got this deprecation warning while using model.fit_generator() in TensorFlow like below.

Warning image: by Author

You can see in the above image that the system recommend us to use Model.fit instead Model.fit_generator, right.

So, the question is How can we use Model.fit()?

In the above image, I have marked a word generator . The above image is the reference from the official Tensorflow documentation where it is mentioned that we can use the generator in the fit method.

You can use Model.fit() like below.

Note:

We can’t use validation_split when our dataset is generator or keras.utils.Sequence in the fit() method.

Now, we can use validation_split in flow_from_directory() .

Let’s start

  1. See my dataset directory
created by: Author

2. Split your dataset into logical train and validation dataset. like below…

created by: Author

Note:

dir_path in the above image is the path of my complete dataset.

the full dataset directory path

3. Use Model.fit()

model.fit(): by Author

I do hope that it will help you to understand Model.fit() .

If you liked it, please clap and SUBSCRIBE my YOUTUBE channel. Thanks!

Click here to subscribe to my YOUTUBE channel to get more Data Science updates and courses from absolute zero to HERO.

--

--

Muhammad Iqbal bazmi

A self-taught programmer, Data Scientist and Machine Learning Engineer