phitodeep.layers.base

Classes

Layer

Base class for all layers in the network.

Flatten

Flattens the input tensor into a 2D tensor.

Dense

Fully connected layer.

Module Contents

class phitodeep.layers.base.Layer(name: str, initializer: phitodeep.optimization.initialization.Initializer = Initializer())[source]

Base class for all layers in the network.

name
cache
grads
initializer
abstractmethod forward(X: numpy.ndarray)[source]
abstractmethod backward(dL_dZ)[source]

Backward pass through the block.

Parameters:

dL_dZ – gradient of loss w.r.t. output of this block

Returns:

gradient of loss w.r.t. input (to pass to previous layer)

Return type:

dL_dX

abstractmethod copy()[source]
class phitodeep.layers.base.Flatten[source]

Bases: Layer

Flattens the input tensor into a 2D tensor.

forward(X: numpy.ndarray)[source]

X: (batch_size, …) -> (batch_size, …)

backward(dL_dZ)[source]

dL_dZ: (batch_size, …) -> (batch_size, …)

copy()[source]
class phitodeep.layers.base.Dense(input_size: int, output_size: int, initializer: phitodeep.optimization.initialization.Initializer = He())[source]

Bases: Layer

Fully connected layer.

grads
input_size
output_size
W
b
forward(X: numpy.ndarray)[source]

X: (batch_size, input_size) -> (batch_size, output_size)

backward(dL_dZ)[source]

Backpropagate through Dense layer.

Parameters:

dL_dZ – (batch_size, output_size) - gradient of loss w.r.t. output

Returns:

(batch_size, input_size) - gradient to pass to previous layer

Return type:

dL_dX

copy()[source]