我正在使用Keras来模拟GAN,我需要将两个输出结合起来,因为我有两个输出 . 一个输出来自Discriminator,在下面的代码中表示为“label”,另一个来自Generator,表示为“Bloss” . 那么是否可以将GAN(组合发电机和鉴别器)的组合模型分别与G和D的两个输出进行训练?
input = Input(shape=self.input_shape)
output_G, Bloss = self.G(input)
# For the combined model we will only train the generator
self.D.trainable = False
label = self.D(output_G)
self.combined = Model(inputs=input,
outputs=[label, Bloss])
self.combined.compile(loss=['categorical_crossentropy', B_loss],
optimizer='RMSprop',
loss_weights=[1,0.01])
...
def B_loss(y_true, y_pred):
return K.mean(y_pred - y_true, axis=-1)
1 回答
我不明白为什么不,只要你创建一个结合了标签(D输出)和Bloss(部分G输出)的正确的y .