Skip to content

Commit 59cc7e1

Browse files
committed
Fix bug in dropout scaling
Co-authored-by: Ricardo Orsi <@ricor07>
1 parent 1dfe6b3 commit 59cc7e1

File tree

2 files changed

+2
-2
lines changed

2 files changed

+2
-2
lines changed

src/nf/nf_dropout_layer_submodule.f90

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ module subroutine forward(self, input)
4545
end where
4646

4747
! Scale factor to preserve the input sum
48-
self % scale = sum(input) / sum(self % output) ! scale == 1/P(keep)
48+
self % scale = sum(input) / sum(input * self % mask)
4949

5050
! Apply dropout mask
5151
self % output = input * self % mask * self % scale

test/test_dropout_layer.f90

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ program test_dropout_layer
8181
do n = 1, 10000
8282
output_data = net % predict(input_data)
8383
! Check that sum of output matches sum of input within small tolerance
84-
if (abs(sum(output_data) - sum(input_data)) > 1e-5) then
84+
if (abs(sum(output_data) - sum(input_data)) > 1e-6) then
8585
ok = .false.
8686
exit
8787
end if

0 commit comments

Comments
 (0)