athena__conv3d_layer Module

Module containing implementation of a 3D convolutional layer

This module implements 3D convolution for processing volumetric data such as video, medical imaging, or 3D point clouds.

Mathematical operation:

where: - are spatial coordinates in the output - is the output channel (filter) index - are kernel offsets: depth, height, width - is the input channel index - are kernel dimensions - is the activation function

Shape:



Interfaces

public interface conv3d_layer_type

Interface for setting up the 3D convolutional layer

  • private module function layer_setup(input_shape, num_filters, kernel_size, stride, dilation, padding, use_bias, activation, kernel_initialiser, bias_initialiser, verbose) result(layer)

    Set up the 3D convolutional layer

    Arguments

    Type IntentOptional Attributes Name
    integer, intent(in), optional, dimension(:) :: input_shape

    Input shape

    integer, intent(in), optional :: num_filters

    Number of filters

    integer, intent(in), optional, dimension(..) :: kernel_size

    Kernel size

    integer, intent(in), optional, dimension(..) :: stride

    Stride

    integer, intent(in), optional, dimension(..) :: dilation

    Dilation

    character(len=*), intent(in), optional :: padding

    Padding method

    logical, intent(in), optional :: use_bias

    Use bias

    class(*), intent(in), optional :: activation

    Activation function, kernel initialiser, bias initialiser

    class(*), intent(in), optional :: kernel_initialiser

    Activation function, kernel initialiser, bias initialiser

    class(*), intent(in), optional :: bias_initialiser

    Activation function, kernel initialiser, bias initialiser

    integer, intent(in), optional :: verbose

    Verbosity level

    Return Value type(conv3d_layer_type)

    Instance of the 3D convolutional layer


Derived Types

type, public, extends(conv_layer_type) ::  conv3d_layer_type

Type for 3D convolutional layer with overloaded procedures

Components

Type Visibility Attributes Name Initial
class(base_actv_type), public, allocatable :: activation

Activation function

real(kind=real32), public, pointer :: bias(:) => null()

Bias pointer

class(base_init_type), public, allocatable :: bias_init

Initialisers for kernel and bias

character(len=14), public :: bias_initialiser = ''

Initialisers for kernel and bias

integer, public, allocatable, dimension(:) :: bias_shape

Shape of biases

class(array_type), public, allocatable :: di_padded

Padded input gradients

integer, public, allocatable, dimension(:) :: dil

Kernel, stride, and dilation sizes

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

class(base_init_type), public, allocatable :: kernel_init

Initialisers for kernel and bias

character(len=14), public :: kernel_initialiser = ''

Initialisers for kernel and bias

integer, public, allocatable, dimension(:) :: knl

Kernel, stride, and dilation sizes

character(len=:), public, allocatable :: name

Layer name

integer, public :: num_channels

Number of channels

integer, public :: num_filters

Number of filters

integer, public :: num_params = 0

Number of learnable parameters

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

Optional preprocess padding layer

type(array_type), public, allocatable, dimension(:) :: params

Learnable parameters

integer, public, allocatable, dimension(:) :: stp

Kernel, stride, and dilation sizes

character(len=20), public :: subtype = repeat(" ", 20)
character(len=4), public :: type = 'base'

Layer type

logical, public :: use_bias = .false.

Layer has bias

logical, public :: use_graph_input = .false.

Use graph input

logical, public :: use_graph_output = .false.

Use graph output

integer, public, allocatable, dimension(:,:) :: weight_shape

Shape of weights

type(array_type), public, dimension(2) :: z

Temporary arrays for forward propagation

Constructor

Interface for setting up the 3D convolutional layer

private module function layer_setup (input_shape, num_filters, kernel_size, stride, dilation, padding, use_bias, activation, kernel_initialiser, bias_initialiser, verbose)

Set up the 3D convolutional layer

Finalizations Procedures

final :: finalise_conv3d

Finalise 3D convolutional layer

Type-Bound Procedures

procedure, public :: add_t_t => add_conv3d

Add two 3D convolutional layers

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_conv3d

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_conv

Get the attributes of the layer (for ONNX export)

procedure, public, pass(this) :: get_gradients

Get parameter gradients of layer

procedure, public, pass(this) :: get_num_params => get_num_params_conv

Get the number of parameters in the layer

procedure, public, pass(this) :: get_params

Get learnable parameters of layer

procedure, public, pass(this) :: init => init_conv

Initialise the layer

procedure, public, pass(this) :: nullify_graph => nullify_graph_base

Nullify the forward pass data of the layer to free memory

Read more…
generic, public :: operator(+) => add_t_t

Operator overloading for addition

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_conv

Print layer to unit

procedure, public, pass(this) :: read => read_conv3d

Read 3D convolutional layer from file

procedure, public, pass(this) :: reduce => reduce_conv3d

Merge another 3D convolutional layer into this one

procedure, public, pass(this) :: set_gradients

Set learnable parameters of layer

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_conv3d

Set hyperparameters for 3D convolutional layer

procedure, public, pass(this) :: set_params

Set learnable parameters of 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


Functions

public function read_conv3d_layer(unit, verbose) result(layer)

Read 3D convolutional layer from file and return layer

Arguments

Type IntentOptional Attributes Name
integer, intent(in) :: unit

Unit number

integer, intent(in), optional :: verbose

Verbosity level

Return Value class(base_layer_type), allocatable

Instance of the base layer

private function add_conv3d(a, b) result(output)

Add two 3D convolutional layers without whole-object allocatable copy

Arguments

Type IntentOptional Attributes Name
class(conv3d_layer_type), intent(in) :: a
class(learnable_layer_type), intent(in) :: b

Return Value class(learnable_layer_type), allocatable

private module function layer_setup(input_shape, num_filters, kernel_size, stride, dilation, padding, use_bias, activation, kernel_initialiser, bias_initialiser, verbose) result(layer)

Set up the 3D convolutional layer

Arguments

Type IntentOptional Attributes Name
integer, intent(in), optional, dimension(:) :: input_shape

Input shape

integer, intent(in), optional :: num_filters

Number of filters

integer, intent(in), optional, dimension(..) :: kernel_size

Kernel size

integer, intent(in), optional, dimension(..) :: stride

Stride

integer, intent(in), optional, dimension(..) :: dilation

Dilation

character(len=*), intent(in), optional :: padding

Padding method

logical, intent(in), optional :: use_bias

Use bias

class(*), intent(in), optional :: activation

Activation function

class(*), intent(in), optional :: kernel_initialiser

Activation function, kernel initialiser, and bias initialiser

class(*), intent(in), optional :: bias_initialiser

Activation function, kernel initialiser, and bias initialiser

integer, intent(in), optional :: verbose

Verbosity level

Return Value type(conv3d_layer_type)

Instance of the 3D convolutional layer


Subroutines

private subroutine build_from_onnx_conv3d(this, node, initialisers, value_info, verbose)

Read ONNX attributes for 3D convolutional layer

Arguments

Type IntentOptional Attributes Name
class(conv3d_layer_type), intent(inout) :: this

Instance of the 3D convolutional 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 information

integer, intent(in) :: verbose

Verbosity level

private subroutine finalise_conv3d(this)

Finalise 3D convolutional layer

Arguments

Type IntentOptional Attributes Name
type(conv3d_layer_type), intent(inout) :: this

Instance of the 3D convolutional layer

private subroutine forward_conv3d(this, input)

Forward propagation

Arguments

Type IntentOptional Attributes Name
class(conv3d_layer_type), intent(inout) :: this

Instance of the 3D convolutional layer

class(array_type), intent(in), dimension(:,:) :: input

Input values

private subroutine read_conv3d(this, unit, verbose)

Read 3D convolutional layer from file

Arguments

Type IntentOptional Attributes Name
class(conv3d_layer_type), intent(inout) :: this

Instance of the 3D convolutional layer

integer, intent(in) :: unit

Unit number

integer, intent(in), optional :: verbose

Verbosity level

private subroutine reduce_conv3d(this, input)

Merge two 3D convolutional layers via parameter summation

Arguments

Type IntentOptional Attributes Name
class(conv3d_layer_type), intent(inout) :: this
class(learnable_layer_type), intent(in) :: input

private subroutine set_hyperparams_conv3d(this, num_filters, kernel_size, stride, dilation, padding, use_bias, activation, kernel_initialiser, bias_initialiser, verbose)

Set hyperparameters for 3D convolutional layer

Arguments

Type IntentOptional Attributes Name
class(conv3d_layer_type), intent(inout) :: this

Instance of the 3D convolutional layer

integer, intent(in) :: num_filters

Number of filters

integer, intent(in), dimension(3) :: kernel_size

Kernel size, stride, dilation

integer, intent(in), dimension(3) :: stride

Kernel size, stride, dilation

integer, intent(in), dimension(3) :: dilation

Kernel size, stride, dilation

character(len=*), intent(in) :: padding

Padding

logical, intent(in) :: use_bias

Use bias

class(base_actv_type), intent(in), allocatable :: activation

Activation function

class(base_init_type), intent(in), allocatable :: kernel_initialiser

Kernel and bias initialisers

class(base_init_type), intent(in), allocatable :: bias_initialiser

Kernel and bias initialisers

integer, intent(in), optional :: verbose

Verbosity level