0

Keras を使用して GAN をモデル化しています。出力が 2 つあるため、2 つの損失を組み合わせる必要があります。1 つの出力は Discriminator からのもので、次のコードで「label」と示されています。もう 1 つは Generator からのもので、「Bloss」と示されています。では、それぞれ G と D からの 2 つの出力を使用して、GAN の結合モデル (Generator と Discriminator を結合) をトレーニングすることは可能ですか?

    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)
4

1 に答える 1