src/models/utils/building_blocks.py
def convolutional_block(x,
                        filters,
                        name,
                        kernel_size=3,
                        padding="same",
                        pooling="max",
                        pool_size=(2, 2),
                        strides=None,
                        activation="relu",
                        batch_norm = False
                        ):

    '''
    Returns the output tensor of a CNN block given an input tensor x.

    Parameters:
        x (tensor): the entry tensor.
        filters (int): number of convolutional filters.
        name (str): name of the CNN block.
        kernel_size (int): size of the squared kernel of the convolutional filter (kernel_size,kernel_size).
        padding ("valid" or "same"): "valid" -> no padding, "same" -> padding such that output has the same dimensions as the input.
        pooling ("max","average" or None): "max" -> Apply MaxPooling2D, "average" -> Apply AveragePooling2D, None -> apply no pooling.
        pool_size (int or tuple of 2 ints): factors by which to downscale (vertical, horizontal). If only one integer is specified, the same window length will be used for both dimensions.
        strides (int or tuple of 2 ints or None): Strides values. If None, it will default to pool_size.
        activation (str): activation function. See available functions at: https://keras.io/api/layers/activations/#available-activations
        batch_norm (bool): whether to apply batch normalization or not.

    Returns:
        x (tensor): Tensor outputs of original tensor x passing through the defined CNN block.
    '''
    
    x = layers.Conv2D(filters,kernel_size,padding=padding,name="Conv2D_"+name)(x)
    
    if activation=='relu':
        x = layers.Activation('relu',name="ReLU_"+name)(x)

    if pooling=='max':
        x = layers.MaxPooling2D(pool_size=pool_size,strides=strides,name="MaxPooling2D_"+name)(x)
    elif pooling=='average':
        x = layers.AveragePooling2D(pool_size=pool_size,strides=strides,name="MaxPooling2D_"+name)(x)
    
    if batch_norm=='true':
        x = layers.BatchNormalization(name="BatchNorm_"+name)(x)

    return x

    Returns the output tensor of a CNN block given an input tensor x.

    Parameters:
        x (tensor): the entry tensor.
        filters (int): number of convolutional filters.
        name (str): name of the CNN block.
        kernel_size (int): size of the squared kernel of the convolutional filter (kernel_size,kernel_size).
        padding ("valid" or "same"): "valid" -> no padding, "same" -> padding such that output has the same dimensions as the input.
        pooling ("max","average" or None): "max" -> Apply MaxPooling2D, "average" -> Apply AveragePooling2D, None -> apply no pooling.
        pool_size (int or tuple of 2 ints): factors by which to downscale (vertical, horizontal). If only one integer is specified, the same window length will be used for both dimensions.
        strides (int or tuple of 2 ints or None): Strides values. If None, it will default to pool_size.
        activation (str): activation function. See available functions at: https://keras.io/api/layers/activations/#available-activations
        batch_norm (bool): whether to apply batch normalization or not.

    Returns:
        x (tensor): Tensor outputs of original tensor x passing through the defined CNN block.
    
Returns the output tensor of a CNN block given an input tensor x.
Returns the output tensor of a CNN block given an input tensor x .
def convolutional_block(x,
                        filters,
                        name,
                        kernel_size=3,
                        padding="same",
                        pooling="max",
                        pool_size=(2, 2),
                        strides=None,
                        activation="relu",
                        batch_norm = False
                        ):
    x = layers.Conv2D(filters,kernel_size,padding=padding,name="Conv2D_"+name)(x)
    if activation=='relu':
        x = layers.Activation('relu',name="ReLU_"+name)(x)
    if pooling=='max':
        x = layers.MaxPooling2D(pool_size=pool_size,strides=strides,name="MaxPooling2D_"+name)(x)
    elif pooling=='average':
        x = layers.AveragePooling2D(pool_size=pool_size,strides=strides,name="MaxPooling2D_"+name)(x)
    if batch_norm=='true':
        x = layers.BatchNormalization(name="BatchNorm_"+name)(x)
    return x
def convolutional_block ( x , filters , name , kernel_size = 3 , padding = "same" , pooling = "max" , pool_size = ( 2 , 2 ) , strides = None , activation = "relu" , batch_norm = False ) : x = layers . Conv2D ( filters , kernel_size , padding = padding , name = "Conv2D_" + name ) ( x ) if activation == 'relu' : x = layers . Activation ( 'relu' , name = "ReLU_" + name ) ( x ) if pooling == 'max' : x = layers . MaxPooling2D ( pool_size = pool_size , strides = strides , name = "MaxPooling2D_" + name ) ( x ) elif pooling == 'average' : x = layers . AveragePooling2D ( pool_size = pool_size , strides = strides , name = "MaxPooling2D_" + name ) ( x ) if batch_norm == 'true' : x = layers . BatchNormalization ( name = "BatchNorm_" + name ) ( x ) return x
Returns the output tensor of a CNN block given an input tensor x.
Returns the output tensor of a CNN block given an input tensor x .
'''
    Returns the output tensor of a CNN block given an input tensor x.

    Parameters:
        x (tensor): the entry tensor.
        filters (int): number of convolutional filters.
        name (str): name of the CNN block.
        kernel_size (int): size of the squared kernel of the convolutional filter (kernel_size,kernel_size).
        padding ("valid" or "same"): "valid" -> no padding, "same" -> padding such that output has the same dimensions as the input.
        pooling ("max","average" or None): "max" -> Apply MaxPooling2D, "average" -> Apply AveragePooling2D, None -> apply no pooling.
        pool_size (int or tuple of 2 ints): factors by which to downscale (vertical, horizontal). If only one integer is specified, the same window length will be used for both dimensions.
        strides (int or tuple of 2 ints or None): Strides values. If None, it will default to pool_size.
        activation (str): activation function. See available functions at: https://keras.io/api/layers/activations/#available-activations
        batch_norm (bool): whether to apply batch normalization or not.

    Returns:
        x (tensor): Tensor outputs of original tensor x passing through the defined CNN block.
    '''
x (tensor): Tensor outputs of original tensor x passing through the defined CNN block.
x ( tensor ) : Tensor outputs of original tensor x passing through the defined CNN block .
x
the entry tensor.
the entry tensor .
filters
number of convolutional filters.
number of convolutional filters .
name
name of the CNN block.
name of the CNN block .
kernel_size
size of the squared kernel of the convolutional filter (kernel_size,kernel_size).
size of the squared kernel of the convolutional filter ( kernel_size kernel_size ) .
padding
"valid" -> no padding, "same" -> padding such that output has the same dimensions as the input.
" valid " - > no padding " same " - > padding such that output has the same dimensions as the input .
pooling
"max" -> Apply MaxPooling2D, "average" -> Apply AveragePooling2D, None -> apply no pooling.
" max " - > Apply MaxPooling2D " average " - > Apply AveragePooling2D None - > apply no pooling .
pool_size
factors by which to downscale (vertical, horizontal). If only one integer is specified, the same window length will be used for both dimensions.
factors by which to downscale ( vertical horizontal ) . If only one integer is specified the same window length will be used for both dimensions .
strides
Strides values. If None, it will default to pool_size.
Strides values . If None it will default to pool_size .
activation
None
batch_norm
whether to apply batch normalization or not.
whether to apply batch normalization or not .