Merge pull request #266 from jekbradbury/patch-1
Use broadcast for dropout
This commit is contained in:
commit
1105e3ac20
@ -31,15 +31,14 @@ function Dropout(p)
|
|||||||
Dropout{typeof(p)}(p, true)
|
Dropout{typeof(p)}(p, true)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
_dropout_kernel(y::T, p, q) where {T} = y > p ? T(1 / q) : T(0)
|
||||||
|
|
||||||
function (a::Dropout)(x)
|
function (a::Dropout)(x)
|
||||||
a.active || return x
|
a.active || return x
|
||||||
y = similar(x)
|
y = similar(x)
|
||||||
rand!(y)
|
rand!(y)
|
||||||
q = 1 - a.p
|
y .= _dropout_kernel.(y, a.p, 1 - a.p)
|
||||||
@inbounds for i=1:length(y)
|
return x .* y
|
||||||
y[i] = y[i] > a.p ? 1 / q : 0
|
|
||||||
end
|
|
||||||
return y .* x
|
|
||||||
end
|
end
|
||||||
|
|
||||||
_testmode!(a::Dropout, test) = (a.active = !test)
|
_testmode!(a::Dropout, test) = (a.active = !test)
|
||||||
|
Loading…
Reference in New Issue
Block a user