build_from_onnx_dropblock2d Subroutine

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

Read ONNX attributes for 2D dropblock layer

Arguments

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

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


Source Code

  subroutine build_from_onnx_dropblock2d( &
       this, node, initialisers, value_info, verbose &
  )
    !! Read ONNX attributes for 2D dropblock layer
    implicit none

    ! Arguments
    class(dropblock2d_layer_type), intent(inout) :: this
    !! Instance of the 2D dropblock layer
    type(onnx_node_type), intent(in) :: node
    !! ONNX node information
    type(onnx_initialiser_type), dimension(:), intent(in) :: initialisers
    !! ONNX initialiser information
    type(onnx_tensor_type), dimension(:), intent(in) :: value_info
    !! ONNX value info
    integer, intent(in) :: verbose
    !! Verbosity level

    ! Local variables
    integer :: i
    !! Loop index
    real(real32) :: rate
    !! Dropout rate
    integer :: block_size
    !! Block size
    character(256) :: val
    !! Attribute value

    ! Set default values
    rate = 0.1_real32
    block_size = 7

    ! Parse ONNX attributes
    do i = 1, size(node%attributes)
       val = node%attributes(i)%val
       select case(trim(adjustl(node%attributes(i)%name)))
       case("drop_prob")
          read(val,*) rate
       case("block_size")
          read(val,*) block_size
       case default
          ! Do nothing
          write(0,*) "WARNING: Unrecognised attribute in ONNX &
               &DROPBLOCK2D layer: ", trim(adjustl(node%attributes(i)%name))
       end select
    end do

    ! Check size of initialisers is zero
    if(size(initialisers).ne.0)then
       write(0,*) "WARNING: initialisers not used for ONNX DROPBLOCK2D layer"
    end if

    call this%set_hyperparams( &
         rate = rate, &
         block_size = block_size, &
         verbose = verbose &
    )

  end subroutine build_from_onnx_dropblock2d