get_attributes_batch Module Function

module function get_attributes_batch(this) result(attributes)

Get the attributes of a batch normalisation layer (for ONNX export)

Arguments

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

Instance of the layer

Return Value type(onnx_attribute_type), allocatable, dimension(:)

Attributes of the layer


Source Code

  module function get_attributes_batch(this) result(attributes)
    !! Get the attributes of a batch normalisation layer (for ONNX export)
    implicit none

    ! Arguments
    class(batch_layer_type), intent(in) :: this
    !! Instance of the layer
    type(onnx_attribute_type), allocatable, dimension(:) :: attributes
    !! Attributes of the layer

    ! Local variables
    character(256) :: buffer, fmt
    !! Buffer for formatting

    ! Allocate attributes array
    allocate(attributes(4))
    attributes(1)%name = "epsilon"
    write(buffer,'("(",F0.6,")")') this%epsilon
    attributes(1)%val = trim(adjustl(buffer))
    attributes(1)%type = "float"

    attributes(2)%name = "momentum"
    write(buffer,'("(",F0.6,")")') this%momentum
    attributes(2)%val = trim(adjustl(buffer))
    attributes(2)%type = "float"

    attributes(3)%name = "scale"
    write(fmt,'("(",I0,"(1X,F0.6))")') this%num_channels
    write(buffer,fmt) this%params(1)%val(1:this%num_channels,1)
    attributes(3)%val = trim(adjustl(buffer))
    attributes(3)%type = "float"

    attributes(4)%name = "B"
    write(fmt,'("(",I0,"(1X,F0.6))")') this%num_channels
    write(buffer,fmt) this%params(1)%val(this%num_channels+1:2*this%num_channels,1)
    attributes(4)%val = trim(adjustl(buffer))
    attributes(4)%type = "float"

  end function get_attributes_batch