Submodule containing the implementation of the base layer types
This submodule contains the implementation of the base layer types used in the ATHENA library. The base layer types are the abstract types from which all other layer types are derived. The submodule contains the implementation of the procedures that are common to all layer types, such as setting the input shape, getting the number of parameters, and printing the layer to a file.
The following procedures are based on code from the neural-fortran library https://github.com/modern-fortran/neural-fortran/blob/main/src/nf/nf_layer.f90 procedures: - get_num_params - get_params - set_params - get_gradients - set_gradients*
Add two learnable layers together
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| class(learnable_layer_type), | intent(in) | :: | a |
Instances of layers |
||
| class(learnable_layer_type), | intent(in) | :: | b |
Instances of layers |
Output layer
Forward pass of layer and return output for evaluation
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| class(base_layer_type), | intent(inout), | target | :: | this |
Instance of the layer |
|
| class(array_type), | intent(in), | dimension(:,:) | :: | input |
Input data |
Output data
Get the attributes of the layer (for ONNX export)
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| class(base_layer_type), | intent(in) | :: | this |
Instance of the layer |
Attributes of the layer
Get the attributes of a batch normalisation layer (for ONNX export)
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| class(batch_layer_type), | intent(in) | :: | this |
Instance of the layer |
Attributes of the layer
Get the attributes of a convolutional layer (for ONNX export)
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| class(conv_layer_type), | intent(in) | :: | this |
Instance of the layer |
Attributes of the layer
Get the attributes of a pooling layer (for ONNX export)
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| class(pool_layer_type), | intent(in) | :: | this |
Instance of the layer |
Attributes of the layer
Get the gradients of the layer
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| class(learnable_layer_type), | intent(in) | :: | this |
Instance of the layer |
||
| type(clip_type), | intent(in), | optional | :: | clip_method |
Method to clip the gradients |
Gradients of the layer
Get the number of parameters in the layer
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| class(base_layer_type), | intent(in) | :: | this |
Instance of the layer |
Number of parameters
Get the number of parameters in batch normalisation layer
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| class(batch_layer_type), | intent(in) | :: | this |
Instance of the layer |
Number of parameters
Get the number of parameters in convolutional layer
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| class(conv_layer_type), | intent(in) | :: | this |
Instance of the layer |
Number of parameters
Get the learnable parameters of the layer
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| class(learnable_layer_type), | intent(in) | :: | this |
Instance of the layer |
Learnable parameters
Build layer from ONNX node and initialiser
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| class(base_layer_type), | intent(inout) | :: | this |
Instance of the layer |
||
| type(onnx_node_type), | intent(in) | :: | node |
ONNX node |
||
| type(onnx_initialiser_type), | intent(in), | dimension(:) | :: | initialisers |
ONNX initialisers |
|
| type(onnx_tensor_type), | intent(in), | dimension(:) | :: | value_info |
ONNX value info |
|
| integer, | intent(in) | :: | verbose |
Verbosity level |
Default implementation: no-op (standard layers don't add graph inputs)
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| class(base_layer_type), | intent(in) | :: | this |
Instance of the layer |
||
| character(len=*), | intent(in) | :: | prefix |
Prefix for input names |
||
| type(onnx_tensor_type), | intent(inout), | dimension(:) | :: | graph_inputs |
ONNX graph inputs |
|
| integer, | intent(inout) | :: | num_inputs |
Number of ONNX graph inputs |
Default implementation: no-op (standard layers are handled by write_onnx)
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| class(base_layer_type), | intent(in) | :: | this |
Instance of the layer |
||
| character(len=*), | intent(in) | :: | prefix |
Prefix for node names |
||
| type(onnx_node_type), | intent(inout), | dimension(:) | :: | nodes |
ONNX nodes |
|
| integer, | intent(inout) | :: | num_nodes |
Number of ONNX nodes |
||
| integer, | intent(in) | :: | max_nodes |
Maximum number of ONNX nodes |
||
| type(onnx_initialiser_type), | intent(inout), | dimension(:) | :: | inits |
ONNX initialisers |
|
| integer, | intent(inout) | :: | num_inits |
Number of ONNX initialisers |
||
| integer, | intent(in) | :: | max_inits |
Maximum number of ONNX initialisers |
||
| character(len=*), | intent(in), | optional | :: | input_name |
Name of the input tensor from the previous layer |
|
| logical, | intent(in), | optional | :: | is_last_layer |
Whether this is the last non-input layer |
|
| integer, | intent(in), | optional | :: | format |
Export format selector |
Get the output of the layer
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| class(base_layer_type), | intent(in) | :: | this |
Instance of the layer |
||
| real(kind=real32), | intent(out), | allocatable, dimension(..) | :: | output |
Output of the Layer |
Forward pass for the layer
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| class(base_layer_type), | intent(inout) | :: | this |
Instance of the layer |
||
| class(array_type), | intent(in), | dimension(:,:) | :: | input |
Input data |
Nullify the forward pass data of the layer to free memory
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| class(base_layer_type), | intent(inout) | :: | this |
Instance of the layer |
Merge two learnable layers via summation
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| class(learnable_layer_type), | intent(inout) | :: | this |
Instance of the layer |
||
| class(learnable_layer_type), | intent(in) | :: | input |
Instance of a layer |
Set the gradients of the layer
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| class(learnable_layer_type), | intent(inout) | :: | this |
Instance of the layer |
||
| real(kind=real32), | intent(in), | dimension(..) | :: | gradients |
Gradients of the layer |
Set the graph structure of the input data
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| class(base_layer_type), | intent(inout) | :: | this |
Instance of the layer |
||
| type(graph_type), | intent(in), | dimension(:) | :: | graph |
Graph structure of input data |
Set the learnable parameters of the layer
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| class(learnable_layer_type), | intent(inout) | :: | this |
Instance of the layer |
||
| real(kind=real32), | intent(in), | dimension(this%num_params) | :: | params |
Learnable parameters |
Set the input and output ranks of the layer
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| class(base_layer_type), | intent(inout) | :: | this |
Instance of the layer |
||
| integer, | intent(in) | :: | input_rank |
Input rank |
||
| integer, | intent(in) | :: | output_rank |
Output rank |
Set the input shape of the layer
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| class(base_layer_type), | intent(inout) | :: | this |
Instance of the layer |
||
| integer, | intent(in), | dimension(:) | :: | input_shape |
Input shape |