smash.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

>>> net = smash.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"})

Compile and display a summary of the network

>>> net.compile()
>>> 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
Optimizer: (adam, lr=0.001)