我想在 Keras 中为图像语义分割建立两个并行模型。
input1 = Input(shape=(480,480,3))
input2 = Input(shape=(480,480,1))
c1_1 = Conv2D(filters=64, kernel_size=(3,3), activation='relu', padding='same')(input1)
c1_1 = MaxPool2D(strides=(2,2))(c1_1)
c2_1 = Conv2D(filters=16, kernel_size=(3,3), activation='relu', padding='same')(input2)
c2_1 = MaxPool2D(strides=(2,2))(c2_1)
(...)
# Merge to models:
c = concatenate([c1_n, c2_n], axis=3)
c = UpSampling2D(size=(2,2))(c)
c = Conv2D(filters=512, kernel_size=(3,3), activation='relu', padding='same')(c)
(...)
output_layer = Conv2D(6, kernel_size=(1,1), activation='softmax')(c)
model = Model([input1, input2], output_layer)
model.compile(optimizer=Adam(2e-4), loss='categorical_crossentropy', metrics=['categorical_accuracy'])
def my_generator(x_train, y_train, batch_size):
data_generator = ImageDataGenerator(
(...).flow(x_train, x_train, batch_size, seed=42)
mask_generator = ImageDataGenerator(
(...).flow(y_train, y_train, batch_size, seed=42)
while True:
x_batch, _ = data_generator.next()
y_batch, _ = mask_generator.next()
yield [x_batch[:,:,:,:3], x_batch[:,:,:,3]], y_batch
#X = [72, 480, 480, 4]
#Y = [72, 480, 480, 5]
model.fit_generator(my_generator(X, Y, 7),
steps_per_epoch = 60,
validation_data = (X_test, Y_test),
epochs=150, verbose=2)
但我有一个错误:
ValueError: 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.33891213, 0.37238494, 0.33054393, 0. ],
[ 0.34728033, 0.38493724, 0.33472803, 0. ],
[ 0.35146444, 0.39330544, 0.35983264, 0. ],
....
你能帮我解决我的错误或告诉我这个假设是否正确吗?