I am training an CNN to compare two images. The CNN then can say if new images i put in the CNN are equal or not. Therefor i concatenate the images via cv2 so that i have images of shape (330,530,6) (in rgb) or like i would do it in grayscale (330,530,2). This works fine for me, but i would like to know how the CNN works if i concatenate two models after flattening both of them. I'm working with the keras sequential modells. Is there a way to concatenate these two models without changing everything? Because i give the Data in the fit method i m not sure how i hand over both data to each model.
Here is the Modle i work with:
CNN = Sequential()
CNN.add(layers.Conv2D(32,(3,3),activation='relu',kernel_regularizer=regularizers.l2(l2Reg),input_shape=(330,530,2)))
CNN.add(layers.MaxPool2D(pool_size=(2, 2)))
CNN.add(layers.Conv2D(32,(3,3),activation='relu',kernel_regularizer=regularizers.l2(l2Reg)))
CNN.add(layers.MaxPool2D(pool_size=(3, 3)))
CNN.add(layers.Conv2D(64,(3,3),activation='relu',kernel_regularizer=regularizers.l2(l2Reg)))
CNN.add(layers.MaxPool2D(pool_size=(3, 3)))
CNN.add(layers.Conv2D(64,(3,3),activation='relu',kernel_regularizer=regularizers.l2(l2Reg)))
CNN.add(layers.MaxPool2D(pool_size=(3, 3)))
CNN.add(layers.Flatten())
CNN.add(layers.Dropout(0.5))
CNN.add(layers.Dense(128,activation='relu',kernel_regularizer=regularizers.l2(l2Reg)))
CNN.add(layers.Dense(2,activation='softmax'))
CNN.summary()
CNN.compile(optimizer=optimizers.RMSprop(lr=1e-4),loss='categorical_crossentropy',metrics=['accuracy'])
history=CNN.fit(XTrain,YTrain,epochs=40,batch_size=32,validation_split=0.15)
scores = CNN.evaluate(XTest,YTest,batch_size=32)
print("Accuracy: %.2f%%" % (scores[1]*100))
CNN.save("AnodenerkennungDreiV")
