Example of a VAE model
:paperclip: You can find the full code for this example in a Jupyter notebook.
This example demonstrates how to build a VAE model using the method VAE.models.VAE
.
1 2 3 4 |
|
We first define the parameters of the model:
5 6 7 8 9 10 11 12 13 |
|
Then we build the different parts of the model. We start with the encoder:
14 |
|
and the latent sampling layer:
15 |
|
and finally the decoder:
16 17 18 19 20 |
|
Once we have the different parts of the model, we can build the full model:
20 |
|
Let's have a look at the model:
21 |
|
Model: "VAE"
__________________________________________________________________________________________________
Layer (type) Output Shape Param # Connected to
==================================================================================================
encoder_input (InputLayer) [(None, 1, 16, 7)] 0
__________________________________________________________________________________________________
encoder_cond (InputLayer) [(None, 1, 12)] 0
__________________________________________________________________________________________________
encoder (Functional) [(None, 10), (None, 16496 encoder_input[0][0]
encoder_cond[0][0]
__________________________________________________________________________________________________
latent (Functional) (None, 1, 10) 0 encoder[0][0]
encoder[0][1]
__________________________________________________________________________________________________
decoder_cond (InputLayer) [(None, 1, 12)] 0
__________________________________________________________________________________________________
decoder (Functional) (None, 1, 16, 7) 16243 latent[0][0]
decoder_cond[0][0]
==================================================================================================
Total params: 32,739
Trainable params: 156
Non-trainable params: 32,583
__________________________________________________________________________________________________
We can also have a look at the trainable parameters:
22 |
|
________________________________________________________________________________
Layer Type # params
================================================================================
VAE Functional 156
________________________________________________________________________________
encoder Functional 78
encoder_input_bn BatchNormalization 14
encoder_block_1 Functional 64
encoder_block_1_R1_bn1 BatchNormalization 32
encoder_block_1_R1_bn2 BatchNormalization 32
________________________________________________________________________________
decoder Functional 78
decoder_block_1 Functional 64
decoder_block_1_R1_bn1 BatchNormalization 32
decoder_block_1_R1_bn2 BatchNormalization 32
decoder_output_bn BatchNormalization 14
________________________________________________________________________________
and plot the model:
23 |
|