我在这里学习tutorial。我的模型部分是:
input_img = keras.Input(shape=img_shape)
x = layers.Conv2D(32, (3, 3),
padding='same', activation='relu')(input_img)
...
x = layers.Conv2D(64, (3, 3),
padding='same', activation='relu')(x)
shape_before_flattening = K.int_shape(x)
x = layers.Flatten()(x)
x = layers.Dense(32, activation='relu')(x)
z_mean = layers.Dense(latent_dim)(x)
z_log_var = layers.Dense(latent_dim)(x)
def sampling(args):
...
z = layers.Lambda(sampling)([z_mean, z_log_var])
decoder_input = layers.Input(K.int_shape(z)[1:])
x = layers.Dense(np.prod(shape_before_flattening[1:]),
activation='relu')(decoder_input)
x = layers.Reshape(shape_before_flattening[1:])(x)
x = layers.Conv2DTranspose(32, 3,
padding='same', activation='relu',
strides=(2, 2))(x)
x = layers.Conv2D(1, 3,
padding='same', activation='sigmoid')(x)
# This is our decoder model from letent space to reconstructed images
decoder = Model(decoder_input, x)
# We then apply it to `z` to recover the decoded `z`.
z_decoded = decoder(z)
def vae_loss(self, x, z_decoded):
...
# Fit the end-to-end model
vae = Model(input_img, z_decoded) # vae = Model(input_img, x)
vae.compile(optimizer='rmsprop', loss=vae_loss)
vae.summary()我的问题是:端到端是vae = Model(input_img, z_decoded)还是vae = Model(input_img, x)。我们应该计算input_img和z_decoded的损失,还是计算input_img和x之间的损失?谢谢
发布于 2018-11-11 15:11:45
X在整个模型中都在变化,您可以将x设置为解码器模型的最后一层。
在执行z_decoded = decoder(z)时,您将解码器直接链接到编码器之后,z_decoded实际上是解码器的输出层,因此,与前面的x相同。此外,您还可以在实际输入和输出之间创建链接。
计算损失将在两者上产生相同的结果(因为它们都表示相同的层)。
简而言之- vae = Model(input_img, z_decoded)和vae = Model(input_img, x)都是端到端模型,为了可读性,我建议使用z_decoded版本。
https://stackoverflow.com/questions/53245079
复制相似问题