With Keras2 being implemented into TensorFlow and TensorFlow 2.0 on the horizon, should you use Keras ImageDataGenerator
with e.g, flow_from_directory
or tf.data
from TensorFlow which also can be used with fit_genearator
of Keras now?
Will both methods will have their place by serving a different purpose or will tf.data
be the new way to go and Keras generators deprecated in the future?
Thanks, I would like to take the path which keeps me up to date a bit longer in this fast moving field.
Alongside custom defined Python generators, you can wrap the ImageDataGenerator
from Keras inside tf.data
.
The following snippets are taken from the TensorFlow 2.0 documentation.
img_gen = tf.keras.preprocessing.image.ImageDataGenerator(rescale=1./255, rotation_range=20)
ds = tf.data.Dataset.from_generator(
img_gen.flow_from_directory, args=[flowers],
output_types=(tf.float32, tf.float32),
output_shapes = ([32,256,256,3],[32,5])
)
Therefore, one can still use the typical Keras ImageDataGenerator
, you just need to wrap it into a tf.data.Dataset
like above.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With