Tensorflow变分自编码器,解码器是如何连接的?

huangapple go评论49阅读模式
英文:

Tensorflow variational autoencoder, how is decoder connected?

问题

在 keras 示例中的 https://blog.keras.io/building-autoencoders-in-keras.html,"Variational autoencoder (VAE)" 部分编写了以下内容:

z = layers.Lambda(sampling)([z_mean, z_log_sigma])
# 创建编码器
encoder = keras.Model(inputs, [z_mean, z_log_sigma, z], name='encoder')

# 创建解码器
latent_inputs = keras.Input(shape=(latent_dim,), name='z_sampling')
x = layers.Dense(intermediate_dim, activation='relu')(latent_inputs)
outputs = layers.Dense(original_dim, activation='sigmoid')(x)
decoder = keras.Model(latent_inputs, outputs, name='decoder')

我对连接到 latent_inputs 的层以及连接是在哪里进行定义感到困惑。例如,在 vae.fit() 中,x_train 作为 VAE 的输入传递,并传递到 inputs 层,该层被定义为 inputs = keras.Input(shape=(original_dim,)),而 VAE 模型的输入被定义为 vae = keras.Model(inputs, outputs, name='vae_mlp')

英文:

In the keras example at https://blog.keras.io/building-autoencoders-in-keras.html, the section "Variational autoencoder (VAE)" writes

z = layers.Lambda(sampling)([z_mean, z_log_sigma])
# Create encoder
encoder = keras.Model(inputs, [z_mean, z_log_sigma, z], name='encoder')

# Create decoder
latent_inputs = keras.Input(shape=(latent_dim,), name='z_sampling')
x = layers.Dense(intermediate_dim, activation='relu')(latent_inputs)
outputs = layers.Dense(original_dim, activation='sigmoid')(x)
decoder = keras.Model(latent_inputs, outputs, name='decoder')

I am confused which layer is connected to latent_inputs and where does it define the connection? For example, in vae.fit(), x_train is passed as VAE input and goes to the layer inputs, which is defined as inputs = keras.Input(shape=(original_dim,)) and input of the VAE model is defined as vae = keras.Model(inputs, outputs, name='vae_mlp').

答案1

得分: 0

你漏掉了教程中的一个重要部分:

# 实例化VAE模型
outputs = decoder(encoder(inputs)[2])
vae = keras.Model(inputs, outputs, name='vae_mlp')

在Keras中,Model可以作为另一个Model中的Layer使用。(来源)

因此,编码器的输出 z 被馈送到解码器作为输入,以构建VAE模型。

英文:

You're missing one important part of the tutorial:

# instantiate VAE model
outputs = decoder(encoder(inputs)[2])
vae = keras.Model(inputs, outputs, name='vae_mlp')

In Keras, a Model can be used as a Layer in an other Model. (Source)

So the output z of the encoder is fed as the input of the decoder to form the VAE model.

huangapple
  • 本文由 发表于 2023年6月9日 02:32:43
  • 转载请务必保留本文链接:https://go.coder-hub.com/76434766.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定