Click here to Skip to main content
15,886,110 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Dear forum,
I have 2 separate CNN:
Each CNN train images and classify 2 classes as output ,lets say:
eg.first CNN X1,Y1
second CNN X2,Y2
I would like to ensemble the two cnn and provide the final classes Z,Y.
I have read some papers and one of them takes the average of two cnn,which seem an acceptable solution.
So even though i have understand the way theoretically(load the weights from the classification of each CNN),i have stuck in the implementation part of how to combine them.Any guidance regarding this mater would be appreciated.
Thank you

What I have tried:

Python
path = "C:\\Users\\Desktop\\"
# define paths
train_normal_dir = path + 'train/X1/'
 
train_covid_dir = path + 'train/X2/'

Python
....
....
....
model.add(Conv2D(filters=128, kernel_size=(3,3), padding='same', activation='relu'))
model.add(Conv2D(filters=128, kernel_size=(3,3), padding='same', activation='relu'))
model.add(MaxPooling2D(pool_size=(2,2)))
model.add(Flatten())
model.add(Dense(1024, activation='relu'))
model.add(Dropout(0.2))
model.add(Dense(2, activation='softmax'))
model.summary()
optimizer = Adam(lr=0.0001, decay=1e-5)
model.compile(loss='categorical_crossentropy', optimizer=optimizer, metrics=['accuracy'])
history = model.fit(datagen.flow(X_train,y_train, batch_size=4), validation_data=(X_test, y_test), epochs = 20, verbose = 1, class_weight={0:6.0, 1:0.5})
model.save('CNN1.h5')
Posted
Updated 19-Oct-21 16:37pm
v4

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900