add_conv3d Function

private function add_conv3d(a, b) result(output)

Add two 3D convolutional layers without whole-object allocatable copy

Type Bound

conv3d_layer_type

Arguments

Type IntentOptional Attributes Name
class(conv3d_layer_type), intent(in) :: a
class(learnable_layer_type), intent(in) :: b

Return Value class(learnable_layer_type), allocatable


Source Code

  function add_conv3d(a, b) result(output)
    !! Add two 3D convolutional layers without whole-object allocatable copy
    implicit none

    class(conv3d_layer_type), intent(in) :: a
    class(learnable_layer_type), intent(in) :: b
    class(learnable_layer_type), allocatable :: output

    type(conv3d_layer_type) :: layer
    character(len=20) :: padding
    real(real32), allocatable :: params(:), gradients(:)

    select type(b)
    type is (conv3d_layer_type)
       padding = 'valid'
       if(allocated(a%pad_layer)) padding = a%pad_layer%method

       call layer%set_hyperparams( &
            num_filters = a%num_filters, &
            kernel_size = a%knl, stride = a%stp, dilation = a%dil, &
            padding = padding, &
            use_bias = a%use_bias, &
            activation = a%activation, &
            kernel_initialiser = a%kernel_init, &
            bias_initialiser = a%bias_init &
       )

       if(allocated(a%input_shape)) call layer%init(a%input_shape)

       params = a%get_params() + b%get_params()
       call layer%set_params(params)

       gradients = a%get_gradients() + b%get_gradients()
       call layer%set_gradients(gradients)

       layer%id = a%id
       layer%inference = a%inference
       layer%use_graph_input = a%use_graph_input
       layer%use_graph_output = a%use_graph_output
       layer%subtype = a%subtype

       allocate(output, source=layer)
    class default
       call stop_program("add_conv3d: incompatible layer type")
    end select

  end function add_conv3d