Advanced Deep Learning with Keras

fourpersent2020
from fourpersent2020 More from this publisher
16.03.2021 Views

Chapter 8# instantiate encoder modelencoder = Model(inputs, [z_mean, z_log_var, z], name='encoder')encoder.summary()plot_model(encoder, to_file='vae_cnn_encoder.png', show_shapes=True)# build decoder modellatent_inputs = Input(shape=(latent_dim,), name='z_sampling')x = Dense(shape[1]*shape[2]*shape[3], activation='relu')(latent_inputs)x = Reshape((shape[1], shape[2], shape[3]))(x)for i in range(2):x = Conv2DTranspose(filters=filters,kernel_size=kernel_size,activation='relu',strides=2,padding='same')(x)filters //= 2outputs = Conv2DTranspose(filters=1,kernel_size=kernel_size,activation='sigmoid',padding='same',name='decoder_output')(x)# instantiate decoder modeldecoder = Model(latent_inputs, outputs, name='decoder')decoder.summary()plot_model(decoder, to_file='vae_cnn_decoder.png', show_shapes=True)# instantiate vae modeloutputs = decoder(encoder(inputs)[2])vae = Model(inputs, outputs, name='vae')[ 251 ]

Variational Autoencoders (VAEs)Figure 8.1.8: The encoder of VAE CNNFigure 8.1.9: The decoder of VAE CNN[ 252 ]

Variational Autoencoders (VAEs)

Figure 8.1.8: The encoder of VAE CNN

Figure 8.1.9: The decoder of VAE CNN

[ 252 ]

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!