diff --git a/src/nf/nf_conv1d_layer_submodule.f90 b/src/nf/nf_conv1d_layer_submodule.f90 index 391a8bcc..8302070b 100644 --- a/src/nf/nf_conv1d_layer_submodule.f90 +++ b/src/nf/nf_conv1d_layer_submodule.f90 @@ -20,7 +20,6 @@ module function conv1d_layer_cons(filters, kernel_size, activation) result(res) end function conv1d_layer_cons module subroutine init(self, input_shape) - implicit none class(conv1d_layer), intent(in out) :: self integer, intent(in) :: input_shape(:) @@ -54,16 +53,11 @@ module subroutine init(self, input_shape) end subroutine init pure module subroutine forward(self, input) - implicit none class(conv1d_layer), intent(in out) :: self real, intent(in) :: input(:,:) - integer :: input_channels, input_width integer :: j, n integer :: iws, iwe - input_channels = size(input, dim=1) - input_width = size(input, dim=2) - ! Loop over output positions. do j = 1, self % width ! Compute the input window corresponding to output index j. @@ -85,14 +79,12 @@ pure module subroutine forward(self, input) end subroutine forward pure module subroutine backward(self, input, gradient) - implicit none class(conv1d_layer), intent(in out) :: self ! 'input' has shape: (channels, input_width) ! 'gradient' (dL/dy) has shape: (filters, output_width) real, intent(in) :: input(:,:) real, intent(in) :: gradient(:,:) - integer :: input_channels, input_width, output_width integer :: j, n, k integer :: iws, iwe @@ -101,11 +93,6 @@ pure module subroutine backward(self, input, gradient) real :: db_local(self % filters) real :: dw_local(self % filters, self % channels, self % kernel_size) - ! Determine dimensions. - input_channels = size(input, dim=1) - input_width = size(input, dim=2) - output_width = self % width ! Note: output_width = input_width - kernel_size + 1 - !--- Compute the local gradient gdz = (dL/dy) * sigma'(z) for each output. gdz = gradient * self % activation % eval_prime(self % z) @@ -120,7 +107,7 @@ pure module subroutine backward(self, input, gradient) ! In the forward pass the window for output index j was: ! iws = j, iwe = j + kernel_size - 1. do n = 1, self % filters - do j = 1, output_width + do j = 1, self % width iws = j iwe = j + self % kernel_size - 1 do k = 1, self % channels diff --git a/src/nf/nf_conv2d_layer_submodule.f90 b/src/nf/nf_conv2d_layer_submodule.f90 index f4ee450c..9e83494e 100644 --- a/src/nf/nf_conv2d_layer_submodule.f90 +++ b/src/nf/nf_conv2d_layer_submodule.f90 @@ -62,7 +62,6 @@ end subroutine init pure module subroutine forward(self, input) - implicit none class(conv2d_layer), intent(in out) :: self real, intent(in) :: input(:,:,:) integer :: input_width, input_height, input_channels @@ -113,7 +112,6 @@ end subroutine forward pure module subroutine backward(self, input, gradient) - implicit none class(conv2d_layer), intent(in out) :: self real, intent(in) :: input(:,:,:) real, intent(in) :: gradient(:,:,:) diff --git a/src/nf/nf_locally_connected2d_layer_submodule.f90 b/src/nf/nf_locally_connected2d_layer_submodule.f90 index 43de79d8..809762ce 100644 --- a/src/nf/nf_locally_connected2d_layer_submodule.f90 +++ b/src/nf/nf_locally_connected2d_layer_submodule.f90 @@ -8,7 +8,6 @@ contains module function locally_connected2d_layer_cons(filters, kernel_size, activation) result(res) - implicit none integer, intent(in) :: filters integer, intent(in) :: kernel_size class(activation_function), intent(in) :: activation @@ -21,7 +20,6 @@ module function locally_connected2d_layer_cons(filters, kernel_size, activation) end function locally_connected2d_layer_cons module subroutine init(self, input_shape) - implicit none class(locally_connected2d_layer), intent(in out) :: self integer, intent(in) :: input_shape(:) @@ -52,16 +50,11 @@ module subroutine init(self, input_shape) end subroutine init pure module subroutine forward(self, input) - implicit none class(locally_connected2d_layer), intent(in out) :: self real, intent(in) :: input(:,:) - integer :: input_channels, input_width integer :: j, n integer :: iws, iwe - input_channels = size(input, dim=1) - input_width = size(input, dim=2) - do j = 1, self % width iws = j iwe = j + self % kernel_size - 1 @@ -73,27 +66,21 @@ pure module subroutine forward(self, input) end subroutine forward pure module subroutine backward(self, input, gradient) - implicit none class(locally_connected2d_layer), intent(in out) :: self real, intent(in) :: input(:,:) real, intent(in) :: gradient(:,:) - integer :: input_channels, input_width, output_width integer :: j, n, k integer :: iws, iwe real :: gdz(self % filters, self % width) real :: db_local(self % filters, self % width) real :: dw_local(self % filters, self % width, self % channels, self % kernel_size) - input_channels = size(input, dim=1) - input_width = size(input, dim=2) - output_width = self % width - - do j = 1, output_width + do j = 1, self % width gdz(:, j) = gradient(:, j) * self % activation % eval_prime(self % z(:, j)) end do do n = 1, self % filters - do j = 1, output_width + do j = 1, self % width db_local(n, j) = gdz(n, j) end do end do @@ -102,7 +89,7 @@ pure module subroutine backward(self, input, gradient) self % gradient = 0.0 do n = 1, self % filters - do j = 1, output_width + do j = 1, self % width iws = j iwe = j + self % kernel_size - 1 do k = 1, self % channels diff --git a/src/nf/nf_maxpool1d_layer_submodule.f90 b/src/nf/nf_maxpool1d_layer_submodule.f90 index 336264f7..15d0c6e7 100644 --- a/src/nf/nf_maxpool1d_layer_submodule.f90 +++ b/src/nf/nf_maxpool1d_layer_submodule.f90 @@ -5,7 +5,6 @@ contains pure module function maxpool1d_layer_cons(pool_size, stride) result(res) - implicit none integer, intent(in) :: pool_size integer, intent(in) :: stride type(maxpool1d_layer) :: res @@ -15,7 +14,6 @@ end function maxpool1d_layer_cons module subroutine init(self, input_shape) - implicit none class(maxpool1d_layer), intent(in out) :: self integer, intent(in) :: input_shape(:) @@ -34,7 +32,6 @@ module subroutine init(self, input_shape) end subroutine init pure module subroutine forward(self, input) - implicit none class(maxpool1d_layer), intent(in out) :: self real, intent(in) :: input(:,:) integer :: input_width @@ -70,7 +67,6 @@ pure module subroutine forward(self, input) end subroutine forward pure module subroutine backward(self, input, gradient) - implicit none class(maxpool1d_layer), intent(in out) :: self real, intent(in) :: input(:,:) real, intent(in) :: gradient(:,:) diff --git a/src/nf/nf_maxpool2d_layer_submodule.f90 b/src/nf/nf_maxpool2d_layer_submodule.f90 index 397939c1..68c115df 100644 --- a/src/nf/nf_maxpool2d_layer_submodule.f90 +++ b/src/nf/nf_maxpool2d_layer_submodule.f90 @@ -5,7 +5,6 @@ contains pure module function maxpool2d_layer_cons(pool_size, stride) result(res) - implicit none integer, intent(in) :: pool_size integer, intent(in) :: stride type(maxpool2d_layer) :: res @@ -15,7 +14,6 @@ end function maxpool2d_layer_cons module subroutine init(self, input_shape) - implicit none class(maxpool2d_layer), intent(in out) :: self integer, intent(in) :: input_shape(:) @@ -39,7 +37,6 @@ end subroutine init pure module subroutine forward(self, input) - implicit none class(maxpool2d_layer), intent(in out) :: self real, intent(in) :: input(:,:,:) integer :: input_width, input_height @@ -86,7 +83,6 @@ end subroutine forward pure module subroutine backward(self, input, gradient) - implicit none class(maxpool2d_layer), intent(in out) :: self real, intent(in) :: input(:,:,:) real, intent(in) :: gradient(:,:,:)