Я обучил 2 модели.
Первая модель - UNet:
print(model_unet.summary())
__________________________________________________________________________________________________
Layer (type) Output Shape Param # Connected to
==================================================================================================
input_4 (InputLayer) (None, 128, 128, 1) 0
__________________________________________________________________________________________________
conv2d_26 (Conv2D) (None, 128, 128, 32) 320 input_4[0][0]
__________________________________________________________________________________________________
conv2d_27 (Conv2D) (None, 128, 128, 32) 9248 conv2d_26[0][0]
.....
.....
conv2d_44 (Conv2D) (None, 128, 128, 1) 33 zero_padding2d_4[0][0]
==================================================================================================
Total params: 7,846,081
Trainable params: 7,846,081
Non-trainable params: 0
Вторая - ResNet:
print(model_resnet.summary())
__________________________________________________________________________________________________
Layer (type) Output Shape Param # Connected to
==================================================================================================
input_3 (InputLayer) (None, 128, 128, 3) 0
__________________________________________________________________________________________________
conv1_pad (ZeroPadding2D) (None, 134, 134, 3) 0 input_3[0][0]
....
....
conv2d_25 (Conv2D) (None, 128, 128, 3) 99 zero_padding2d_3[0][0]
==================================================================================================
Total params: 24,186,915
Trainable params: 24,133,795
Non-trainable params: 53,120
У UNet есть 1 канал (серый)и ResNet имеет 3 канала.
Затем я пытаюсь создать модель ансамбля:
def ensemble(models, models_input):
outputs = [model(models_input[idx]) for idx, model in enumerate(models)]
x = Average()(outputs)
model_inputs = [model for model in models_input]
model = Model(model_inputs, x)
return model
models = [model_unet, model_resnet]
models_input = [Input((128,128,1)), Input((128,128, 3))]
ensemble_model = ensemble(models, models_input)
Когда я пытаюсь прогнозировать данные проверки:
pred_val = ensemble_model.predict(X_val)
Я получаю сообщение об ошибке:
Error when checking model input: the list of Numpy arrays that you are passing to your model is not the size the model expected. Expected to see 2 array(s), but instead got the following list of 1 arrays: [array([[[[0.46755977],
[0.52268691],
[0.52766109],
....
X_val.shape is : (800, 128, 128, 1)
Я думаю, что проблема в каналах, но я не знаю, как это преодолеть.