Flux.jl/test/layers.jl

27 lines
564 B
Julia
Raw Normal View History

2017-10-23 08:12:53 +00:00
@testset "dropout" begin
x = [1.,2.,3.]
2017-10-23 14:23:29 +00:00
@test x === Dropout(0.1, testmode=true)(x)
@test x === Dropout(0, testmode=false)(x)
@test all(zeros(x) .== Dropout(1, testmode=false)(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