2017-10-26 10:46:12 +00:00
|
|
|
using Flux: testmode!
|
|
|
|
|
|
|
|
@testset "Dropout" begin
|
2017-10-23 08:12:53 +00:00
|
|
|
x = [1.,2.,3.]
|
2017-10-26 10:46:12 +00:00
|
|
|
@test x == testmode!(Dropout(0.1))(x)
|
|
|
|
@test x == Dropout(0)(x)
|
|
|
|
@test zeros(x) == Dropout(1)(x)
|
2017-10-23 08:12:53 +00:00
|
|
|
|
|
|
|
x = rand(100)
|
|
|
|
m = Dropout(0.9)
|
|
|
|
y = m(x)
|
|
|
|
@test count(a->a==0, y) > 50
|
2017-10-23 14:23:29 +00:00
|
|
|
testmode!(m)
|
2017-10-23 08:12:53 +00:00
|
|
|
y = m(x)
|
|
|
|
@test count(a->a==0, y) == 0
|
2017-10-23 14:23:29 +00:00
|
|
|
testmode!(m, false)
|
|
|
|
y = m(x)
|
|
|
|
@test count(a->a==0, y) > 50
|
2017-10-23 08:12:53 +00:00
|
|
|
|
|
|
|
x = rand(100)
|
|
|
|
m = Chain(Dense(100,100),
|
|
|
|
Dropout(0.9))
|
|
|
|
y = m(x)
|
2017-10-23 09:41:08 +00:00
|
|
|
@test count(a->a == 0, y) > 50
|
2017-10-23 14:23:29 +00:00
|
|
|
testmode!(m)
|
2017-10-23 08:12:53 +00:00
|
|
|
y = m(x)
|
2017-10-23 09:41:08 +00:00
|
|
|
@test count(a->a == 0, y) == 0
|
2017-10-23 08:12:53 +00:00
|
|
|
end
|