Module containing procedures for an input layer
This module implements the input layer which serves as the entry point for data into a neural network. It handles data conversion and batching.
Operation: Accepts external data and converts to internal array_type format - Validates input shape matches specified dimensions - Handles both dense arrays and graph-structured data - No learnable parameters (pass-through layer)
Properties: - First layer in any network architecture - Defines expected input shape for subsequent layers - Supports multiple input sources in multi-input networks
Interface for an input layer
Set up layer
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| integer, | intent(in), | optional, | dimension(:) | :: | input_shape |
Shape of the input data |
| integer, | intent(in), | optional | :: | index |
Index of the layer |
|
| logical, | intent(in), | optional | :: | use_graph_input |
Use graph input |
|
| integer, | intent(in), | optional | :: | verbose |
Verbosity level |
Instance of the input layer
Type for an input layer
| Type | Visibility | Attributes | Name | Initial | |||
|---|---|---|---|---|---|---|---|
| type(graph_type), | public, | allocatable, dimension(:) | :: | graph |
Graph structure of input data |
||
| integer, | public | :: | id |
Unique identifier |
|||
| integer, | public | :: | index | = | 1 |
Index of the layer |
|
| logical, | public | :: | inference | = | .false. |
Inference mode |
|
| integer, | public | :: | input_rank | = | 0 |
Rank of input data |
|
| integer, | public, | allocatable, dimension(:) | :: | input_shape |
Input shape |
||
| character(len=:), | public, | allocatable | :: | name |
Layer name |
||
| integer, | public | :: | num_outputs |
Number of outputs |
|||
| class(array_type), | public, | allocatable, dimension(:,:) | :: | output |
Output |
||
| integer, | public | :: | output_rank | = | 0 |
Rank of output data |
|
| integer, | public, | allocatable, dimension(:) | :: | output_shape |
Output shape |
||
| character(len=20), | public | :: | subtype | = | repeat(" ", 20) | ||
| character(len=4), | public | :: | type | = | 'base' |
Layer type |
|
| logical, | public | :: | use_graph_input | = | .false. |
Use graph input |
|
| logical, | public | :: | use_graph_output | = | .false. |
Use graph output |
Interface for an input layer
| private module function layer_setup (input_shape, index, use_graph_input, verbose) | Set up layer |
| procedure, public, pass(this) :: build_from_onnx => build_from_onnx_input | Build fully connected layer from ONNX node and initialiser |
| procedure, public, pass(this) :: emit_onnx_graph_inputs => emit_onnx_graph_inputs_base | Emit graph input tensor declarations for this layer |
| procedure, public, pass(this) :: emit_onnx_nodes => emit_onnx_nodes_base | Emit ONNX JSON nodes for this layer (format-aware and polymorphic) |
| procedure, public, pass(this) :: extract_output => extract_output_base | Extract the output of the layer as a standard real array |
| procedure, public, pass(this) :: forward => forward_input | Forward propagation derived type handler |
| procedure, public, pass(this) :: forward_eval => forward_eval_base | Forward pass of layer and return output for evaluation |
| procedure, public, pass(this) :: get_attributes => get_attributes_base | Get the attributes of the layer (for ONNX export) |
| procedure, public, pass(this) :: get_num_params => get_num_params_base | Get the number of parameters in the layer |
| procedure, public, pass(this) :: init => init_input | Initialise layer |
| procedure, public, pass(this) :: nullify_graph => nullify_graph_base | Nullify the forward pass data of the layer to free memory |
| procedure, public, pass(this) :: print => print_base | Print the layer to a file with additional information |
| procedure, public, pass(this) :: print_to_unit => print_to_unit_input | Print layer to unit |
| procedure, public, pass(this) :: read => read_input | Read layer from file |
| generic, public :: set => set_input_real, set_input_graph | Generic interface for setting input values |
| procedure, public, pass(this) :: set_graph => set_graph_base | Set the graph structure of the input data !! this is adjacency and edge weighting |
| procedure, public, pass(this) :: set_hyperparams => set_hyperparams_input | Set hyperparameters |
| procedure, public, pass(this) :: set_input_graph | Set input values |
| procedure, public, pass(this) :: set_input_real | Set input values |
| procedure, public, pass(this) :: set_rank => set_rank_base | Set the input and output ranks of the layer |
| procedure, public, pass(this) :: set_shape => set_shape_base | Set the input shape of the layer |
Build fully connected layer from attributes and return layer
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| type(onnx_node_type), | intent(in) | :: | node |
ONNX node information |
||
| type(onnx_initialiser_type), | intent(in), | dimension(:) | :: | initialisers |
ONNX initialiser information |
|
| type(onnx_tensor_type), | intent(in), | dimension(:) | :: | value_info |
ONNX value info |
|
| integer, | intent(in), | optional | :: | verbose |
Verbosity level |
Instance of the 2D convolutional layer
Read an input layer from a file
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| integer, | intent(in) | :: | unit |
Unit number |
||
| integer, | intent(in), | optional | :: | verbose |
Verbosity level |
Instance of the input layer
Set up layer
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| integer, | intent(in), | optional, | dimension(:) | :: | input_shape |
Shape of the input data |
| integer, | intent(in), | optional | :: | index |
Index of the layer |
|
| logical, | intent(in), | optional | :: | use_graph_input |
Use graph input |
|
| integer, | intent(in), | optional | :: | verbose |
Verbosity level |
Instance of the input layer
Read ONNX attributes for fully connected layer
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| class(input_layer_type), | intent(inout) | :: | this |
Instance of the fully connected layer |
||
| type(onnx_node_type), | intent(in) | :: | node |
ONNX node information |
||
| type(onnx_initialiser_type), | intent(in), | dimension(:) | :: | initialisers |
ONNX initialiser information |
|
| type(onnx_tensor_type), | intent(in), | dimension(:) | :: | value_info |
ONNX value info |
|
| integer, | intent(in) | :: | verbose |
Verbosity level |
Forward propagation for an input layer
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| class(input_layer_type), | intent(inout) | :: | this |
Instance of the input layer |
||
| class(array_type), | intent(in), | dimension(:,:) | :: | input |
Input data |
Initialise an input layer
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| class(input_layer_type), | intent(inout) | :: | this |
Instance of the input layer |
||
| integer, | intent(in), | dimension(:) | :: | input_shape |
Shape of the input data |
|
| integer, | intent(in), | optional | :: | verbose |
Verbosity level |
Print input layer to unit
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| class(input_layer_type), | intent(in) | :: | this |
Instance of the input layer |
||
| integer, | intent(in) | :: | unit |
File unit |
Read an input layer from a file
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| class(input_layer_type), | intent(inout) | :: | this |
Instance of the input layer |
||
| integer, | intent(in) | :: | unit |
Unit number |
||
| integer, | intent(in), | optional | :: | verbose |
Verbosity level |
Set hyperparameters for an input layer
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| class(input_layer_type), | intent(inout) | :: | this |
Instance of the input layer |
||
| integer, | intent(in), | optional | :: | input_rank |
Rank of the input data |
|
| integer, | intent(in), | optional | :: | index |
Index of the layer |
|
| logical, | intent(in), | optional | :: | use_graph_input |
Use graph input |
|
| integer, | intent(in), | optional | :: | verbose |
Verbosity level |
Set input values for an input layer
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| class(input_layer_type), | intent(inout) | :: | this |
Instance of the input layer |
||
| type(graph_type), | intent(in), | dimension(:) | :: | input |
Input data |
Set input values for an input layer
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| class(input_layer_type), | intent(inout) | :: | this |
Instance of the input layer |
||
| real(kind=real32), | intent(in), | dimension(..) | :: | input |
Input data |