smash.factory.Net.add#

Net.add(layer, options)[source]#

Add layers to the neural network.

Parameters:
layerstr

Layer name. Should be one of ‘dense’, ‘activation’, ‘scale’, ‘dropout’.

optionsdict

A dictionary to configure layers added to the network.

Hint

See options for each layer type:

Examples

Initialize the neural network:

>>> from smash.factory import Net
>>> net = Net()

Define graph:

>>> # First Dense Layer
>>> # input_shape is only required for the first layer
>>> net.add(layer="dense", options={"input_shape": (8,), "neurons": 32})
>>> # Activation funcion following the first dense layer
>>> net.add(layer="activation", options={"name": "relu"})
>>> # Second Dense Layer
>>> net.add(layer="dense", options={"neurons": 16})
>>> # Activation function following the second dense layer
>>> net.add(layer="activation", options={"name": "relu"})
>>> # Third Dense Layer
>>> net.add(layer="dense", options={"neurons": 4})
>>> # Last Activation function (output of the network)
>>> net.add(layer="activation", options={"name": "sigmoid"})

Display a summary of the network:

>>> net
+----------------------------------------------------------+
| Layer Type            Input/Output Shape  Num Parameters |
+----------------------------------------------------------+
| Dense                 (8,)/(32,)          288            |
| Activation (ReLU)     (32,)/(32,)         0              |
| Dense                 (32,)/(16,)         528            |
| Activation (ReLU)     (16,)/(16,)         0              |
| Dense                 (16,)/(4,)          68             |
| Activation (Sigmoid)  (4,)/(4,)           0              |
+----------------------------------------------------------+
Total parameters: 884
Trainable parameters: 884