brainpy.layers module#

Basic ANN Layer Class#

Layer([name, mode])

Base class for a layer of artificial neural network.

Convolutional Layers#

Conv1d(in_channels, out_channels, kernel_size)

One-dimensional convolution.

Conv2d(in_channels, out_channels, kernel_size)

Two-dimensional convolution.

Conv3d(in_channels, out_channels, kernel_size)

Three-dimensional convolution.


alias of Conv1d


alias of Conv2d


alias of Conv3d

ConvTranspose1d(in_channels, out_channels, ...)

One dimensional transposed convolution (aka.

ConvTranspose2d(in_channels, out_channels, ...)

Two dimensional transposed convolution (aka.

ConvTranspose3d(in_channels, out_channels, ...)

Three dimensional transposed convolution (aka.

Dropout Layers#

Dropout(prob[, seed, mode, name])

A layer that stochastically ignores a subset of inputs each training step.

Function Layers#

Activation(activate_fun[, name, mode])

Applies an activation function to the inputs

Flatten([name, mode])

Flattens a contiguous range of dims into 2D or 1D.

FunAsLayer(fun[, name, mode])

Dense Connection Layers#

Dense(num_in, num_out[, W_initializer, ...])

A linear transformation applied over the last dimension of the input.


alias of Dense

Identity(*args, **kwargs)

A placeholder identity operator that is argument-insensitive.

Normalization Layers#

BatchNorm1d(num_features[, axis, epsilon, ...])

1-D batch normalization [1]_.

BatchNorm2d(num_features[, axis, epsilon, ...])

2-D batch normalization [1]_.

BatchNorm3d(num_features[, axis, epsilon, ...])

3-D batch normalization [1]_.


alias of BatchNorm1d


alias of BatchNorm2d


alias of BatchNorm3d

LayerNorm(normalized_shape[, epsilon, ...])

Layer normalization (

GroupNorm(num_groups, num_channels[, ...])

Group normalization layer.

InstanceNorm(num_channels[, epsilon, ...])

Instance normalization layer.

NVAR Layers#

NVAR(num_in, delay[, order, stride, ...])

Nonlinear vector auto-regression (NVAR) node.

Pooling Layers#

MaxPool(kernel_size[, stride, padding, ...])

Pools the input by taking the maximum over a window.

MinPool(kernel_size[, stride, padding, ...])

Pools the input by taking the minimum over a window.

AvgPool(kernel_size[, stride, padding, ...])

Pools the input by taking the average over a window.

AvgPool1d(kernel_size[, stride, padding, ...])

Applies a 1D average pooling over an input signal composed of several input

AvgPool2d(kernel_size[, stride, padding, ...])

Applies a 2D average pooling over an input signal composed of several input

AvgPool3d(kernel_size[, stride, padding, ...])

Applies a 3D average pooling over an input signal composed of several input

MaxPool1d(kernel_size[, stride, padding, ...])

Applies a 1D max pooling over an input signal composed of several input

MaxPool2d(kernel_size[, stride, padding, ...])

Applies a 1D max pooling over an input signal composed of several input

MaxPool3d(kernel_size[, stride, padding, ...])

Applies a 1D max pooling over an input signal composed of several input

AdaptiveAvgPool1d(target_shape[, ...])

Adaptive one-dimensional average down-sampling.

AdaptiveAvgPool2d(target_shape[, ...])

Adaptive two-dimensional average down-sampling.

AdaptiveAvgPool3d(target_shape[, ...])

Adaptive three-dimensional average down-sampling.

AdaptiveMaxPool1d(target_shape[, ...])

Adaptive one-dimensional maximum down-sampling.

AdaptiveMaxPool2d(target_shape[, ...])

Adaptive two-dimensional maximum down-sampling.

AdaptiveMaxPool3d(target_shape[, ...])

Adaptive three-dimensional maximum down-sampling.

Reservoir Layers#

Reservoir(input_shape, num_out[, ...])

Reservoir node, a pool of leaky-integrator neurons with random recurrent connections [1]_.

Artificial Recurrent Layers#

RNNCell(num_in, num_out[, ...])

Basic fully-connected RNN core.

GRUCell(num_in, num_out[, Wi_initializer, ...])

Gated Recurrent Unit.

LSTMCell(num_in, num_out[, Wi_initializer, ...])

Long short-term memory (LSTM) RNN core.

Conv1dLSTMCell(input_shape, in_channels, ...)

1-D convolutional LSTM.

Conv2dLSTMCell(input_shape, in_channels, ...)

2-D convolutional LSTM.

Conv3dLSTMCell(input_shape, in_channels, ...)

3-D convolutional LSTM.