9
$\begingroup$

What is the main diffrence between flow_from_directory VS image_dataset_from_directory in keras?

which one should I use?

$\endgroup$

2 Answers 2

9
$\begingroup$

tf.keras.preprocessing.image_dataset_from_directory
Generates a tf.data.Dataset from image files in a directory.

ImageDataGenerator.flow_from_directory
Takes the path to a directory & generates batches of augmented data.

While their return type also differs but the key difference is that flow_from_directory is a method of ImageDataGenerator while image_dataset_from_directory is a preprocessing function to read image form directory.
image_dataset_from_directory will not facilitate you with augmented image generation capability on-the-fly.

which one should I use?

It's quite common to generate augmented images when working with CNN, so better to use flow_from_directory. If you do not need augmented image, you may control the same by the parameters of ImageDataGenerator

Reference - Keras docs

$\endgroup$
0
$\begingroup$

Some response elements can be found in this interesting post

As mentioned above:

tf.keras.preprocessing**.image_dataset_from_directory** Generates a tf.data.Dataset from image files in a directory.

The .image_dataset_from_directory function/method enables the use of the new tf 2.8.x (and later version) data structure tf.data.Dataset. Rather than loading your data into lists, which is not a recommended practice, the .image_dataset_from_directory allows to load your data in the tf.data.Dataset format. Hence, it enables also the use, and this is the best, of the Keras preprocessing layers, including data augmentation. Contrary to what is being said that:

image_dataset_from_directory will not facilitate you with augmented image generation capability on-the-fly.

the .image_dataset_from_director allows to put data in a format that can be directly pluged into the keras pre-processing layers, and data augmentation is run on the fly (real time) with other downstream layers.

This is the main advantage beside allowing the use of the advantageous tf.data.Dataset.from_tensor_slices method.

To sum up, .image_dataset_from_director is an upgraded version of .flow_from_directory for handling datasets and passing them to deep learning models.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.