Convolutional layers

Convolutional layers

Convolution2D 2D convolution layer
class braid.berry.layers.Convolution2D(incoming, num_filters, kernel_size, stride=1, pad='VALID', activation='linear', init=None, W_stddev=0.01, b_val=0.1, **kwargs)

2D convolution layer

incoming
: Layer or tf.Tensor
Parent layer, whose output is given as input to the current layer.
num_filters
: int
The number of filters to learn.
kernel_size
: int
The size of the kernel to consider for pooling.
stride
: int, optional (default = 1)
The amount of subsample.
pad
: string, optional (default = “VALID”)
Type of padding to apply to the input layer before doing pooling. Expected values - “VALID”, “SAME”. No padding is applied for “VALID”, while a padding of (kernel_size + 1) / 2 if “SAME”. This ensures that the output layer shape is the same as that of the input layer shape.
activation
: string, optional (default = “linear”)
Nonlinearity to apply afer performing convolution. See berry.activations
init
: string, optional (default = None)
Weight initialization method to choose. See berry.initializations
W_stddev
: float, optional (default = 1e-2)
Standard deviation for Normal distribution to initialize the weights, if init = None.
b_val
: float, optional (default = 0.1)
Constant value to initialize the biases.
W
: tf.Variable, optional (default = None)
Weight tensor in case if the layer has any trainable parameters (inherited from Layer).
b
: tf.Variable, optional (default = None)
Bias vector in case of trainable parameters (inherited from Layer).
name
: string, optional (default = None)
Name of the layer. Should be specified for better readability ( inherited from Layer).
input_layer
: Layer or tf.Tensor
Input layer to this layer.
input_shape
: tuple
Shape of the incoming layer.
output
: tf.Tensor
The Tensor obtained after performing the transformation applied by this layer.
output_shape
: tuple
Shape of the output tensor.
type
: string
Return the name of the class.

See also

Inherits class Layer.

get_W_shape()

Shape of the weight tensor

list
[kernel_size, kernel_size, input_channels, num_filters]
get_b_shape()

Number of bias units

list
[num_filters]
get_fan_in()

Input receptive field

int
kernel_size * kernel_size * input_channels
get_fan_out()

Output receptive field

int
kernel_size * kernel_size * num_filters
get_output_for()

Perform the convolution operation, activation and return the output tf.Tensor.

tf.Tensor
Output tensor of this layer.
get_output_shape_for(input_shape)

Shape of the output tensor after performing convolution.

input_shape
: tuple or list
Shape of the input layer.
tuple
Shape of the output tensor.

Note

Each dimension of the output is given as

\[l_o = \frac{( W - F +2P)}{S} + 1\]

where \(W\) is the width of the input layer dim, \(F\) is the kernel_size, \(P\) is the amount of padding applied and \(S\) is the stride.

validate_input_layer(incoming)

Validate the input layer shape

Returns True if the input layer is 4D else, raise an exceptions.AssertError.