athena__dropblock3d_layer Module

Module containing implementation of a 3D dropblock layer

This module implements DropBlock regularisation for 3D convolutional layers, dropping contiguous 3D regions (blocks) instead of individual elements. Extension of 2D DropBlock for volumetric/spatiotemporal data.

Mathematical operation (training): 1. Compute drop probability per spatial location: gamma = p * (feature_size^3) / (block_size^3 * valid_positions) 2. Sample Bernoulli mask M_i ~ Bernoulli(gamma) 3. Expand mask to block_size x block_size x block_size blocks 4. Apply and normalise: y = x * M * (count_elements / count_ones)

where block_size is the spatial extent of each dropped block in all 3 dims

Inference: acts as identity (no dropout applied)

Benefits: Spatial/temporal coherence for 3D CNNs, better for video/volumetric, removes spatiotemporal semantic information Typical: block_size=5-7, keep_prob=0.9 for 3D ResNets Reference: Ghiasi et al. (2018), NeurIPS - https://arxiv.org/abs/1810.12890



Interfaces

public interface dropblock3d_layer_type

Interface for setting up the 3D dropblock layer

  • private module function layer_setup(rate, block_size, input_shape, verbose) result(layer)

    Set up the 3D dropblock layer

    Arguments

    Type IntentOptional Attributes Name
    real(kind=real32), intent(in) :: rate

    Drop rate

    integer, intent(in) :: block_size

    Block size

    integer, intent(in), optional, dimension(:) :: input_shape

    Input shape

    integer, intent(in), optional :: verbose

    Verbosity level

    Return Value type(dropblock3d_layer_type)

    Instance of the 3D dropblock layer


Derived Types

type, public, extends(drop_layer_type) ::  dropblock3d_layer_type

Type for 3D dropblock layer with overloaded procedures

Components

Type Visibility Attributes Name Initial
integer, public :: block_size

Block size and half block size Block size is the width of the block to drop (typical = 5)

real(kind=real32), public :: gamma

Number of activation units to drop

type(graph_type), public, allocatable, dimension(:) :: graph

Graph structure of input data

integer, public :: half

Block size and half block size Block size is the width of the block to drop (typical = 5)

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

logical, public, allocatable, dimension(:,:,:) :: mask

Mask for dropblock

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

real(kind=real32), public :: rate = 0.1_real32

Dropout rate, rate = 1 - keep_prob -- typical = 0.05-0.25

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

Constructor

Interface for setting up the 3D dropblock layer

private module function layer_setup (rate, block_size, input_shape, verbose)

Set up the 3D dropblock layer

Type-Bound Procedures

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_dropblock3d

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) :: generate_mask => generate_bernoulli_mask

Generate Bernoulli mask

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_dropblock3d

Initialise 3D dropblock layer

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

Nullify the forward pass data of the layer to free memory

Read more…
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_dropblock3d

Print 3D dropblock layer to unit

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

Read 3D dropblock 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_dropblock3d

Set hyperparameters for 3D dropblock 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_dropblock3d_layer(unit, verbose) result(layer)

Read 3D dropblock layer from file and return layer

Arguments

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

File unit

integer, intent(in), optional :: verbose

Verbosity level

Return Value class(base_layer_type), allocatable

Instance of the 3D dropblock layer

private module function layer_setup(rate, block_size, input_shape, verbose) result(layer)

Set up the 3D dropblock layer

Arguments

Type IntentOptional Attributes Name
real(kind=real32), intent(in) :: rate

Drop rate

integer, intent(in) :: block_size

Block size

integer, intent(in), optional, dimension(:) :: input_shape

Input shape

integer, intent(in), optional :: verbose

Verbosity level

Return Value type(dropblock3d_layer_type)

Instance of the 3D dropblock layer


Subroutines

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

Read ONNX attributes for 3D dropblock layer

Arguments

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

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

private subroutine forward_dropblock3d(this, input)

Forward propagation

Arguments

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

Instance of the 3D dropblock layer

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

Input values

private subroutine generate_bernoulli_mask(this)

Generate Bernoulli mask Apply threshold to create binary mask

Arguments

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

Instance of the 3D dropblock layer

private subroutine init_dropblock3d(this, input_shape, verbose)

Initialise 3D dropblock layer

Arguments

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

Instance of the 3D dropblock layer

integer, intent(in), dimension(:) :: input_shape

Input shape

integer, intent(in), optional :: verbose

Verbosity level

private subroutine print_to_unit_dropblock3d(this, unit)

Print 3D dropblock layer to unit

Arguments

Type IntentOptional Attributes Name
class(dropblock3d_layer_type), intent(in) :: this

Instance of the 3D dropblock layer

integer, intent(in) :: unit

File unit

private subroutine read_dropblock3d(this, unit, verbose)

Read 3D dropblock layer from file

Arguments

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

Instance of the 3D dropblock layer

integer, intent(in) :: unit

File unit

integer, intent(in), optional :: verbose

Verbosity level

private subroutine set_hyperparams_dropblock3d(this, rate, block_size, verbose)

Set hyperparameters for 3D dropblock layer

Arguments

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

Instance of the 3D dropblock layer

real(kind=real32), intent(in) :: rate

Drop rate

integer, intent(in) :: block_size

Block size

integer, intent(in), optional :: verbose

Verbosity level