我想合并两个通过不同数据集训练的CNN。我有两个顺序模型并合并它们。但是当使用自定义的fit_generato时,验证损失不会收敛。我如何传递不同数据集的生成器?
input1_1 = keras.layers.Input(shape=(129,129,3))
x1 = keras.layers.Conv2D(kernel_size = (3,3), filters = 32,
activation='PReLU')(input1_1)
x3 = keras.layers.MaxPooling2D(2,2)(x1)
x4 = keras.layers.Conv2D(kernel_size = (5,5), filters = 64,
activation='relu')(x3)
x5 = keras.layers.MaxPooling2D(2,2)(x4)
x6 = keras.layers.Conv2D(kernel_size = (7,7), filters = 128,
activation='relu')(x5)
d1_1 = keras.layers.Dropout(0.5)(x6)
br1_1= keras.layers.MaxPooling2D(2,2)(d1_1)
br1_1 = keras.layers.Flatten()(br1_1)
input2_2 = keras.layers.Input(shape=(129,129,3))
x1 = keras.layers.Conv2D(kernel_size = (3,3), filters = 32,
activation='PReLU')(input2_2)
x3 = keras.layers.MaxPooling2D(2,2)(x1)
x4 = keras.layers.Conv2D(kernel_size = (5,5), filters = 64,
activation='relu')(x3)
x5 = keras.layers.MaxPooling2D(2,2)(x4)
x6 = keras.layers.Conv2D(kernel_size = (7,7), filters = 128,
activation='relu')(x5)
d2_2 = keras.layers.Dropout(0.5)(x6)
br2_2= keras.layers.MaxPooling2D(2,2)(d2_2)
br2_2 = keras.layers.Flatten()(br2_2)
added1_1 = keras.layers.concatenate([br1_1, br2_2], axis=1)
d2_3 = keras.layers.Dropout(0.5)(added1_1)
# d2_4 = keras.layers.Dropout(0.4)(d2_3)
out1_1 = keras.layers.Dense(159,activation='softmax',kernel_regularizer=regularizers.l2(0.01),
activity_regularizer=regularizers.l1(0.01))(d2_3)
# model=keras.layers.Conv2DTranspose(kernel_size= (4,4), filters=10, activation='relu')(out)
modal1_1 = keras.models.Model(inputs=[input1_1,input2_2], outputs=out1_1)
modal1_1.summary()
modal1_1.compile(##args)
modal1_1.fit_genrator(????)
应该在fit_generator中传递哪些参数,它们将组合除zip之外的两个生成器。我已经使用Zip进行了一些实验,但它没有达到目的。
答案 0 :(得分:0)
目前还不清楚你要做什么。如果您以后不使用它们,为什么要合并图层? 我想你需要的是:
layer = concatenate ([face, sig])
model = Model (inputs = [inputs], outputs=[layer])
答案 1 :(得分:0)
好的,这是一个简短的例子。
input_face = Input(shape=(148, 148, 3))
input_sig = Input(shape=(148, 148, 3))
face = Conv2D(32, kernel_size=(3, 3))(input_face)
face = Conv2D(32, kernel_size=(3, 3))(face)
face = Flatten()(face)
sig = Conv2D(32, kernel_size=(3, 3))(input_sig)
sig = Conv2D(32, kernel_size=(3, 3))(sig)
sig = Flatten()(sig)
output = concatenate([sig, face])
output = Dense(2, activation='softmax')(output)
model = Model(inputs=[input_face, input_sig], outputs=[output])
model.compile(#args)
model.fit([np.array, np.array])
所以这里的输入数据应该是包含图像的两个numpy数组的列表
答案 2 :(得分:0)
你应该这样做:
model.fit_generator([face_gen, sig_gen], arg)
答案 3 :(得分:0)
尝试重写你的生成器,使它产生这样的输出([sig,face],target),因为fit_generator只需要一个生成器。