build_from_onnx_reshape Subroutine

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

Build reshape layer from ONNX node and initialiser

Type Bound

reshape_layer_type

Arguments

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

Instance of the reshape layer

type(onnx_node_type), intent(in) :: node

ONNX node

type(onnx_initialiser_type), intent(in), dimension(:) :: initialisers

ONNX initialisers

type(onnx_tensor_type), intent(in), dimension(:) :: value_info

ONNX value infos

integer, intent(in) :: verbose

Verbosity level


Source Code

  subroutine build_from_onnx_reshape(this, node, initialisers, value_info, verbose)
    !! Build reshape layer from ONNX node and initialiser
    implicit none

    ! Arguments
    class(reshape_layer_type), intent(inout) :: this
    !! Instance of the reshape layer
    type(onnx_node_type), intent(in) :: node
    !! ONNX node
    type(onnx_initialiser_type), dimension(:), intent(in) :: initialisers
    !! ONNX initialisers
    type(onnx_tensor_type), dimension(:), intent(in) :: value_info
    !! ONNX value infos
    integer, intent(in) :: verbose
    !! Verbosity level

    ! Local variables
    integer, dimension(:), allocatable :: output_shape
    !! Output shape

    ! Check size of initialisers is zero or one (shape can be an initialiser)
    if(size(initialisers).gt.1)then
       write(0,*) "WARNING: Multiple initialisers found for ONNX RESHAPE layer"
    end if

    ! Extract output shape from value_info (excluding batch dimension)
    if(allocated(value_info(1)%dims))then
       if(size(value_info(1)%dims).gt.1)then
          output_shape = value_info(1)%dims(2:)
       else
          allocate(output_shape(1))
          output_shape(1) = value_info(1)%dims(1)
       end if
    else
       call stop_program("ONNX RESHAPE layer requires output shape in value_info")
       return
    end if

    call this%set_hyperparams( &
         output_shape = output_shape, &
         verbose = verbose &
    )

  end subroutine build_from_onnx_reshape