Conv2D

class Conv2D(out_channels: int, kernel_size: int = 3, stride: int = 1, padding: bool = True)

Bases: bluebird.layers.layer.Layer

Applies a 2D convolution over and input.

Example:

conv = Conv2D(32, kernel_size=5)
net = NeuralNet([
        ...
        conv,
        ...
    ])
__init__(out_channels: int, kernel_size: int = 3, stride: int = 1, padding: bool = True)

Initializes the object.

Parameters
  • out_channels (int) – number of output channels

  • kernel_size (int, optional) – size of the window, defaults to 3

  • stride (int, optional) – determens how much the filter moves, defaults to 1

  • padding (bool, optional) – True if you want to add padding to the input image, defualts to True

Methods

__init__(out_channels[, kernel_size, …])

Initializes the object.

backward(grad)

Used to calculate the gradients of weights and biases.

build(in_channels)

Builds the layer.

forward(inputs[, training])

Called each time the data passes throughout the nework.

get_params()

Returns params of layer.

remove_zero_padding(inp)

Add zero padding to the input Tensor.

step(inp, w, b)

Perform single step in convolution.

zero_padding(inp)

Add zero padding to the input Tensor.

backward(grad: numpy.ndarray) → numpy.ndarray

Used to calculate the gradients of weights and biases.

Parameters

grad (Tensor) – gradient from previous layer or loss function.

Returns

Gradient

Return type

Tensor

build(in_channels: int)

Builds the layer.

Parameters

in_channels (int) – number of input channels

forward(inputs: numpy.ndarray, training: bool = False) → numpy.ndarray

Called each time the data passes throughout the nework.

Parameters
  • inputs (Tensor) – output from the previous layer

  • training (bool, optional) – set to true during training, and is false when network predicts

Returns

processed input data

Return type

Tensor

get_params() → Dict

Returns params of layer.

Returns

all params of layer

Return type

dict

remove_zero_padding(inp: numpy.ndarray) → numpy.ndarray

Add zero padding to the input Tensor.

Parameters

inputs (Tensor) – input to the layer

Returns

Tensor: padded input

step(inp: numpy.ndarray, w: numpy.ndarray, b: numpy.ndarray) → numpy.ndarray

Perform single step in convolution.

Parameters
  • inp (Tensor) – slice of input

  • w (Tensor) – weights

  • b (Tensor) – bias

zero_padding(inp: numpy.ndarray) → numpy.ndarray

Add zero padding to the input Tensor.

Parameters

inputs (Tensor) – input to the layer

Returns

Tensor: padded input