I am acutally working on a mini-project based on cifar10
dataset. I have loaded the data from tfds.load(...)
and practicing image augmentation techniques.
As I am using tf.data.Dataset
object, which is my dataset, real-time data augmentation is quite unachievable, hence I want to pass all the features into tf.keras.preprocessing.image.ImageDataGenerator.flow(...)
to gain the functionality of real-time augmentation.
But this flow(...)
method accepts NumPy arrays which in no way related to tf.data.Dataset
object.
Can somebody guide me in this regard (or any alternative) and how do I proceed further?
Are tf.image
transformations real-time? If not, what can be the best aproach other than ImageDataGenerator.flow(...)
?
My code:
import tensorflow as tf
import tensorflow_datasets as tfds
from tensorflow.keras.preprocessing.image import ImageDataGenerator
splitting = tfds.Split.ALL.subsplit(weighted=(70, 20, 10))
dataset_cifar10, dataset_info = tfds.load(name='cifar10',
split=splitting,
as_supervised=True,
with_info=True)
train_dataset, valid_dataset, test_dataset = dataset_cifar10
BATCH_SIZE = 32
train_dataset = train_dataset.batch(batch_size=BATCH_SIZE)
train_dataset = train_dataset.prefetch(buffer_size=1)
image_generator = ImageDataGenerator(rotation_range=45,
width_shift_range=0.15,
height_shift_range=0.15,
zoom_range=0.2,
horizontal_flip=True,
vertical_flip=True,
rescale=1./255)
train_dataset_generator = image_generator.flow(...)
...