英文:
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.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论