Keras多种输入,输出,损失模型 [英] Keras multiple input, output, loss model
问题描述
我正在研究超分辨率GAN,并且对我在Github上找到的代码有一些疑问.特别是,我在模型中有多个输入,多个输出.另外,我有两个不同的损失函数.
I am working on super-resolution GAN and having some doubts about the code I found on Github. In particular, I have multiple inputs, multiple outputs in the model. Also, I have two different loss functions.
在下面的代码中,是否将ms损失应用于img_hr和fake_features?
In the following code will the mse loss be applied to img_hr and fake_features?
# Build and compile the discriminator
self.discriminator = self.build_discriminator()
self.discriminator.compile(loss='mse',
optimizer=optimizer,
metrics=['accuracy'])
# Build the generator
self.generator = self.build_generator()
# High res. and low res. images
img_hr = Input(shape=self.hr_shape)
img_lr = Input(shape=self.lr_shape)
# Generate high res. version from low res.
fake_hr = self.generator(img_lr)
# Extract image features of the generated img
fake_features = self.vgg(fake_hr)
# For the combined model we will only train the generator
self.discriminator.trainable = False
# Discriminator determines validity of generated high res. images
validity = self.discriminator(fake_hr)
self.combined = Model([img_lr, img_hr], [validity, fake_features])
self.combined.compile(loss=['binary_crossentropy', 'mse'],
loss_weights=[1e-3, 1],
optimizer=optimizer)
推荐答案
在以下代码中,mse损失将应用于img_hr和fake_features?
In the following code will the mse loss be applied to img_hr and fake_features?
从文档中, https://keras.io/models/model/#compile
"如果模型具有多个输出,则可以通过传递字典或损失列表来对每个输出使用不同的损失."
在这种情况下,mse损失将应用于fake_features,并将相应的y_true作为 self.combined.fit()
的一部分传递.
In this case, the mse loss will be applied to fake_features and the corresponding y_true passed as part of self.combined.fit()
.
这篇关于Keras多种输入,输出,损失模型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!