I am concatenating two different CNN model trained on two completely different dataset
My model is going in the infinite loop while predicting( full_model.predict(inputgenerator)). I think there is some issue with the datagenerator code that I have written(especially with while loop).please help me)
Dataset_A/
Train/
Type_1/
Image_0
Image_1
…..
Type_2/
Image_0
Image_1
…..
Test/
Type_1/
Image_0
Image_1
…..
Type_2/
Image_0
Image_1
…..
Dataset_B/
Train/
Type_1/
Image_0
Image_1
…..
Type_2/
Image_0
Image_1
…..
Test/
Type_1/
Image_0
Image_1
…..
Type_2/
Image_0
Image_1
…..
CODE
input_imgen_1 = ImageDataGenerator() input_imgen_2 = ImageDataGenerator()
def generate_generator_multiple(generator_1, generator_2 ,dir1, dir2, batch_size, img_height,img_width): gen1 = generator_1.flow_from_directory(dir1, target_size = (img_height,img_width), class_mode = 'binary', batch_size = 16, shuffle=False, seed=7)
gen2 = generator_2.flow_from_directory(dir2,
target_size = (img_height,img_width),
class_mode = 'binary',
batch_size = 16,
shuffle=False,
seed=7)
while True:
X1i = gen1.next()
X2i = gen2.next()
yield [X1i[0], X2i[0]], X1i[1] #X1i[1] is the label
inputgenerator=generate_generator_multiple(generator_1 = input_imgen_1, generator_2 = input_imgen_2, dir1='dataset_A_path', dir2=' dataset_B_path ', batch_size=16, img_height=390, img_width=390)
CNN_for_dataset_1
input_1 = tf.keras.layers.Input(shape=(390, 390, 3)) conv2d_p1 = tf.keras.layers.Conv2D(16, kernel_size=3, activation=tf.keras.activations.relu)(input_1) conv2d_p2 = tf.keras.layers.Conv2D(32, kernel_size=3, activation=tf.keras.activations.relu)(conv2d_p1) conv2d_p3 = tf.keras.layers.Conv2D(32, kernel_size=3, activation=tf.keras.activations.relu)(conv2d_p2) maxpool_1 = tf.keras.layers.MaxPool2D(pool_size=(2, 2))(conv2d_p3) conv2d_p4 = tf.keras.layers.Conv2D(64, kernel_size=3, activation=tf.keras.activations.relu)(conv2d_p3) conv2d_p5 = tf.keras.layers.Conv2D(64, kernel_size=3, activation=tf.keras.activations.relu)(conv2d_p4) maxpool_2 = tf.keras.layers.MaxPool2D(pool_size=(2, 2))(conv2d_p5)
CNN_for_dataset_2
input_2 = tf.keras.layers.Input(shape=(390, 390, 3)) conv2d_b1 = tf.keras.layers.Conv2D(16, kernel_size=3, activation=tf.keras.activations.relu)(input_2) conv2d_b2 = tf.keras.layers.Conv2D(32, kernel_size=3, activation=tf.keras.activations.relu)(conv2d_b1) conv2d_b3 = tf.keras.layers.Conv2D(32, kernel_size=3, activation=tf.keras.activations. 338