Module containing implementation of a 3D average pooling layer
This module implements 3D average pooling for downsampling volumetric data by computing mean values within 3D pooling windows.
Mathematical operation: output[i,j,k,c] = (1/V) * sum_{l,m,n} input[is+l, js+m, k*s+n, c]
where: (i,j,k) are output spatial coordinates c is the channel index (l,m,n) iterate over the 3D pooling window V = pool_size^3 is the window volume s is stride in each dimension
Smoother downsampling for volumetric/video data than max pooling. Shape: (W,H,D,C) -> (W//stride,H//stride,D//stride,C)
Interface for setting up the 3D average pooling layer
Set up the 3D average pooling layer
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| integer, | intent(in), | optional, | dimension(:) | :: | input_shape |
Input shape |
| integer, | intent(in), | optional, | dimension(..) | :: | pool_size |
Pool size |
| integer, | intent(in), | optional, | dimension(..) | :: | stride |
Stride |
| character(len=*), | intent(in), | optional | :: | padding |
Padding |
|
| integer, | intent(in), | optional | :: | verbose |
Verbosity level |
Instance of the 3D average pooling layer
Type for 3D average pooling layer with overloaded procedures
| Type | Visibility | Attributes | Name | Initial | |||
|---|---|---|---|---|---|---|---|
| type(graph_type), | public, | allocatable, dimension(:) | :: | graph |
Graph structure of input data |
||
| integer, | public | :: | id |
Unique identifier |
|||
| 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_channels |
Number of channels |
|||
| 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 |
||
| class(pad_layer_type), | public, | allocatable | :: | pad_layer |
Padding layer |
||
| integer, | public, | allocatable, dimension(:) | :: | pool |
Pooling and stride sizes |
||
| integer, | public, | allocatable, dimension(:) | :: | strd |
Pooling and stride sizes |
||
| 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 setting up the 3D average pooling layer
| private module function layer_setup (input_shape, pool_size, stride, padding, verbose) | Set up the 3D average pooling layer |
| procedure, public, pass(this) :: build_from_onnx => build_from_onnx_base | Build 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_avgpool3d | 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_pool | 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_pool | Initialise the 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_pool | Print layer to unit |
| procedure, public, pass(this) :: read => read_avgpool3d | Read 3D average pooling layer from file |
| 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_avgpool3d | Set hyperparameters for 3D average pooling layer |
| 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 |
Read 3D average pooling layer from file and return layer
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| integer, | intent(in) | :: | unit |
File unit |
||
| integer, | intent(in), | optional | :: | verbose |
Verbosity level |
Instance of the 3D average pooling layer
Set up the 3D average pooling layer
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| integer, | intent(in), | optional, | dimension(:) | :: | input_shape |
Input shape |
| integer, | intent(in), | optional, | dimension(..) | :: | pool_size |
Pool size |
| integer, | intent(in), | optional, | dimension(..) | :: | stride |
Stride |
| character(len=*), | intent(in), | optional | :: | padding |
Padding |
|
| integer, | intent(in), | optional | :: | verbose |
Verbosity level |
Instance of the 3D average pooling layer
Read ONNX attributes for 3D average pooling layer
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| class(avgpool3d_layer_type), | intent(inout) | :: | this |
Instance of the 3D average pooling 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
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| class(avgpool3d_layer_type), | intent(inout) | :: | this |
Instance of the 3D average pooling layer |
||
| class(array_type), | intent(in), | dimension(:,:) | :: | input |
Input values |
Read 3D average pooling layer from file
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| class(avgpool3d_layer_type), | intent(inout) | :: | this |
Instance of the 3D average pooling layer |
||
| integer, | intent(in) | :: | unit |
File unit |
||
| integer, | intent(in), | optional | :: | verbose |
Verbosity level |
Set hyperparameters for 3D average pooling layer
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| class(avgpool3d_layer_type), | intent(inout) | :: | this |
Instance of the 3D average pooling layer |
||
| integer, | intent(in), | dimension(3) | :: | pool_size |
Pool size |
|
| integer, | intent(in), | dimension(3) | :: | stride |
Stride |
|
| character(len=*), | intent(in), | optional | :: | padding |
Padding |
|
| integer, | intent(in), | optional | :: | verbose |
Verbosity level |