In Kaggle I was given the input data folders.
#Training data
train_datagen = ImageDataGenerator(
rescale=1./255,
rotation_range=10,
zoom_range=0.4,
horizontal_flip=True,
validation_split=0.01
)
train_generator = train_datagen.flow_from_directory(
'../input/chest-xray-covid19-pneumonia/Data/train',
target_size=(256, 256),
batch_size=32,
class_mode='categorical',
subset='training'
)
I had to add some more images to this dataset. Hence I converted my train_generator to a NumPy (nd) array using this code.
x_train=np.concatenate([train_generator.next()[0] for i in range(train_generator.__len__())])
y_train=np.concatenate([train_generator.next()[1] for i in range(train_generator.__len__())])
Thanks to this
Now I have concatenated some more images to these image array
gan_images = np.concatenate((x_train,t_x), axis=0)
gan_labels = np.concatenate((y_train,t_y), axis=0)
Now how can I again convert back it to the train_generator format?
Type of train_generator is keras.preprocessing.image.DirectoryIterator
EDIT
As per suggestion, I tried
train_dataset = train_datagen.flow(x_train,y_train)
additional_gan_dataset = train_datagen.flow(t_x,t_y)
abc = np.concatenate((gan_dataset,train_dataset), axis=0)
OOM error in kaggle;
Another way I tried
dataset = train_datagen.flow(gan_images, gan_labels)
history1 = model1.fit(dataset,validation_data=val_generator, verbose=1, epochs= 500,
callbacks=[early_stopping, reduce_lr , learning_rate_reduction]
)
It is working, but here accuracy is coming so poor, I am sure it has not properly merged. I had a total of 5094 images. I have created another 100 images. As these are prefetch datasets I am unable to understand by checking the length. len(train_dataset) is giving me 160 After merging it is giving me 163. How to fix these? How to understand properly with these prefetch datasets?