I have a 2-channeled imagelike file from which I am cutting patches as training/validation datasets for a convolutional autoencoder. I am using a custom data generator from TensorFlow to use different data for each batch and epoch.
Here is my CustomDataGenerator class:
class CustomDataGenerator(tf.keras.utils.Sequence):
def __init__(self, file, sample_size, batch_size=32, width=28, height=28, resolution=(28, 28)):
'Initialization'
self.sample_size = sample_size
self.batch_size = batch_size
self.resolution = resolution
self.width = width
self.height = height
def __len__(self):
'Denotes the number of batches per epoch'
return int(np.floor(self.sample_size / self.batch_size))
def __getitem__(self, index):
'Generate one batch of data'
batch = []
for i in range(self.batch_size):
....
x = np.asarray(batch)
x = tf.transpose(x, [0, 2, 3, 1])
return x, x
and training code:
...
train_gen = data_generator.CustomDataGenerator(file=file, sample_size=10000)
val_gen = data_generator.CustomDataGenerator(file=file, sample_size=2000)
history = autoencoder.fit(train_gen, epochs=100, validation_data=val_gen)
...
when I run the code it throws:
ValueError: Failed to find data adapter that can handle input: <class 'data_generator.CustomDataGenerator'>, <class 'NoneType'>
in model.fit line during training.
tensorflow ==2.5.0, keras ==2.4.3