Recurrent Layers#

Classes#

class Recurrent(idx, shapes, *, batch_norm=False, layers=2, filters=1, dropout=0, mode='gru', activation='ELU', bidirectional=None, **kwargs)[source]#

Bases: BaseSingleLayer

Recurrent layer constructor for either RNN, GRU or LSTM.

Attributes:
groupint

Layer group, if 0 it will always be used, else it will only be used if its group matches the Networks

descriptionstr

Description of the layer

layersSequential

Layers to loop through in the forward pass

Parameters:
idxint

Layer number

shapeslist[list[int]]

Shape of the outputs from each layer

batch_normbool, Optional

If batch normalisation should be used, default = False

layersint, Optional

Number of stacked recurrent layers, default = 2

filtersint, Optional

Number of output filters, default = 1

dropoutfloat, Optional

Probability of dropout, requires layers > 1, default = 0

mode{‘gru’, ‘rnn’, ‘lstm’}

Type of recurrent layer

activationstr | NoneType, Optional

Which activation function to use, if mode is ‘rnn’, ReLU activation will always be used, default = ‘ELU’

bidirectional{NoneType, ‘sum’, ‘mean’, ‘concatenate’}

If a bidirectional recurrence should be used and method for combining the two directions

**kwargs

Leftover parameters to pass to base layer for checking

extra_repr()[source]#

Displays layer parameters when printing the network

Returns:
str

Layer parameters

forward(x, *_, **__)[source]#

Forward pass of the recurrent layer

Parameters:
xTensor

Input tensor with shape (N,C_{in},L) and type float, where N is the batch size, C_{in} is the number of input channels and L is the length of the sequence

Returns:
Tensor

Output tensor with shape (N,C_{out},L) and type float, where C_{out} is the number of output channels