predict_real Module Function

module function predict_real(this, input, verbose) result(output)

Predict the output for a 1D input

Arguments

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

Instance of network

real(kind=real32), intent(in), dimension(..) :: input

Input

integer, intent(in), optional :: verbose

Verbosity level

Return Value real(kind=real32), dimension(:,:), allocatable

Output


Source Code

  module function predict_real( &
       this, input, verbose &
  ) result(output)
    !! Predict the output for a 1D input
    implicit none

    ! Arguments
    class(network_type), intent(inout) :: this
    !! Instance of network
    real(real32), dimension(..), intent(in) :: input
    !! Input
    integer, optional, intent(in) :: verbose
    !! Verbosity level

    ! Local variables
    real(real32), dimension(:,:), allocatable :: output
    !! Output
    integer :: verbose_, batch_size
    !! Verbosity level
    logical, allocatable :: mode_store(:)
    !! Storage for inference mode booleans


    !---------------------------------------------------------------------------
    ! Initialise optional arguments
    !---------------------------------------------------------------------------
    if(present(verbose))then
       verbose_ = verbose
    else
       verbose_ = 0
    end if

    select rank(input)
    rank(2)
       batch_size = size(input,dim=2)
    rank(3)
       batch_size = size(input,dim=3)
    rank(4)
       batch_size = size(input,dim=4)
    rank(5)
       batch_size = size(input,dim=5)
    rank(6)
       batch_size = size(input,dim=6)
    rank default
       batch_size = size(input,dim=rank(input))
    end select


    !---------------------------------------------------------------------------
    ! Reset batch size for testing
    !---------------------------------------------------------------------------
    call this%set_batch_size(batch_size)


    !---------------------------------------------------------------------------
    ! Enable inference mode
    !---------------------------------------------------------------------------
    call this%set_inference_mode(mode_store)


    !---------------------------------------------------------------------------
    ! Predict
    !---------------------------------------------------------------------------
    call this%forward(get_sample(input, 1, batch_size, batch_size))

    output = this%model(this%leaf_vertices(1))%layer%output(1,1)%val


    !---------------------------------------------------------------------------
    ! Restore training/inference mode
    !---------------------------------------------------------------------------
    call this%restore_mode(mode_store)

  end function predict_real