models module
Creates DIRESA and (V)AE models out of an encoder and decoder model. Creates DIRESA and AE models from hyperparameters.
- Author:
Geert De Paepe
- Email:
- License:
MIT License
Creating (V)AE and Diresa models out of an encoder and decoder model:
autoencoder_model(x, encoder, decoder, mask_layer=False)
vae_model(x, encoder, decoder)
cov_reg_ae_model(x, encoder, decoder)
siamese_twin_model(x, x_twin, encoder, decoder)
diresa_model(x, x_twin, encoder, decoder)
Creating AE and Diresa models from hyperparameters
build_ae(input_shape, stack, stack_filters, latent_filters, kernel_size=(3, 3), conv_transpose=False, up_first=False, residual=False, batchnorm=False, dense_units=(), mask_layer=False, activation=’relu’, encoder_activation=’linear’, decoder_activation=’linear’)
build_diresa(input_shape, stack, stack_filters, latent_filters, kernel_size=(3, 3), conv_transpose=False, up_first=False, residual=False, batchnorm=False, dense_units=(), activation=’relu’, encoder_activation=’linear’, decoder_activation=’linear’)
- Encoder:
0 or more [blocks] with C (Conv2D) or residual units and a P (MaxPooling layer)
0 or 1 [block] of D (Dense layers)
optionally a mask layer (only for AE)
- Decoder:
0 or 1 [block] with D (Dense layers)
0 or more [blocks] with C (Conv2D) or residual units and an U (UpSampling layer)
- Examples:
stack; dense_units; Encoder; Decoder (up_first=True); Decoder (up_first=False)
[1]; (); [C-P]-Cout; [U-C]-Cout; [C-U]-Cout
[3]; (); [C-C-C-P]-Cout; [U-C-C-C]-Cout; [C-U-C-C]-Cout
[1,1]; (); [C-P]-[C-P]-Cout; [U-C]-[U-C]-Cout; [C-U]-[C-U]-Cout
(); [20,10]; [D-Dout]; [D-Dout]; [D-Dout]
[2]; [20,10]; [C-C-P]-[D-Dout]; [D-D]-[U-C]-Cout; [D-D]-[C-U]-Cout
[1,1]; [20,10]; [C-P]-[C-P]-[D-Dout]; [D-D]-[U]-[U-C]-Cout; [D-D]-[U]-[C-U]-Cout
If conv_transpose=True, C is a ConvTranspose layer, only possible for up_first=True. If residual=True, C is a residual unit with a skip connection, only possible for up_first=True. Input shape should be 3 if Conv2D blocks, first 2 dimensions of input_shape should be a multiple of 2^len(stack). Input shape should be 1 if only a Dense block.
- models.autoencoder_model(x, encoder, decoder, mask_layer=False)
Creates autoencoder model out of an encoder and a decoder model
- Parameters:
x – keras input tensor (keras.Input())
encoder – encoder functional Keras model
decoder – decoder functional Keras model
mask_layer – if True, adds a MaskLayer to the encoder
- Returns:
autoencoder model
- models.cov_reg_ae_model(x, encoder, decoder)
Creates a covariance regulated autoencoder model out of an encoder and a decoder model
- Parameters:
x – keras input tensor (keras.Input())
encoder – encoder functional Keras model
decoder – decoder functional Keras model
- Returns:
covariance regulated autoencoder model
- models.siamese_twin_model(x, x_twin, encoder, decoder)
Creates a Diresa model (without cov regularization on latent space) out of an encoder and a decoder model
- Parameters:
x – keras input tensor (keras.Input())
x_twin – keras input tensor for shuffled input
encoder – encoder functional Keras model
decoder – decoder functional Keras model
- Returns:
Diresa model without cov regularization on latent space
- models.diresa_model(x, x_twin, encoder, decoder)
Creates a Diresa model out of an encoder and a decoder model
- Parameters:
x – keras input tensor (keras.Input())
x_twin – keras input tensor for shuffled input
encoder – encoder functional Keras model
decoder – decoder functional Keras model
- Returns:
Diresa model
- models.vae_model(x, encoder, decoder)
Creates a variational autoencoder model out of an encoder and a decoder model
- Parameters:
x – keras input tensor (keras.Input())
encoder – variational encoder functional Keras model
decoder – decoder functional Keras model
- Returns:
variational autoencoder model
- models.build_ae(input_shape=(), stack=(), stack_filters=(), latent_filters=1, kernel_size=(3, 3), conv_transpose=False, up_first=False, residual=False, batchnorm=False, dense_units=(), mask_layer=False, activation='relu', encoder_activation='linear', decoder_activation='linear')
Creates an AE model out of hyperparameters
- Parameters:
input_shape – 3-dimensional with Conv2D layers, first 2 dimensions should be a multiple of 2^len(stack), 1-dimensional if only Dense layers
stack – elements are nbr of Conv2D or residual units in a block
stack_filters – elements are nbr of filters in a block
latent_filters – nbr of filters in convolutional output (only used if no dense units)
kernel_size – kernel size for convolution
conv_transpose – if True ConvTranspose is used in decoder, only possible for up_first=True
up_first – if True UpSampling is first in decoder block, if False UpSampling is second
residual – if True, elements in blocks are residual units, if False elements are Conv2D layers
batchnorm – if True, each Conv2D is followed by a BatchNormalization layer, if False no BN is used
dense_units – elements are nbr of nodes of a Dense layer in the dense block
mask_layer – if True a MaskLayer is added between encoder and decoder
activation – activation function used (except for output of encoder/decoder)
encoder_activation – activation function used for output of encoder
decoder_activation – activation function used for output of decoder
- Returns:
AE functional Keras model
- models.build_diresa(input_shape=(), stack=(), stack_filters=(), latent_filters=1, kernel_size=(3, 3), conv_transpose=False, up_first=False, residual=False, batchnorm=False, dense_units=(), activation='relu', encoder_activation='linear', decoder_activation='linear')
Creates a Diresa model out of hyperparameters
- Parameters:
input_shape – 3-dimensional with Conv2D layers, first 2 dimensions should be a multiple of 2^len(stack) 1-dimensional if only Dense layers
stack – elements are nbr of Conv2D or residual units in a block
stack_filters – elements are nbr of filters in a block
latent_filters – nbr of filters in convolutional output (only used if no dense units)
kernel_size – kernel size for convolution
conv_transpose – if True ConvTranspose is used in decoder, only possible for up_first=True
up_first – if True UpSampling is first in decoder block, if False UpSampling is second
residual – if True, elements in blocks are residual units, if False elements are Conv2D layers
batchnorm – if True, each Conv2D is followed by a BatchNormalization layer, if False no BN is used
dense_units – elements are nbr of nodes of a Dense layer in the dense block
activation – activation function used (except for output of encoder/decoder)
encoder_activation – activation function used for output of encoder
decoder_activation – activation function used for output of decoder
- Returns:
Diresa functional Keras model