Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Layer normalisation for images #592

Merged
merged 2 commits into from
Feb 5, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions src/layers/stateless.jl
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,12 @@ but it is more numerically stable.
logitbinarycrossentropy(logŷ, y) = (1 - y)*logŷ - logσ(logŷ)

"""
normalise(x::AbstractVecOrMat)
normalise(x::AbstractArray, dims::Int=1)

Normalise each column of `x` to mean 0 and standard deviation 1.
Normalises x to mean 0 and standard deviation 1, across the dimensions given by dims. Defaults to normalising over columns.
"""
function normalise(x::AbstractVecOrMat)
μ′ = mean(x, dims = 1)
σ′ = std(x, dims = 1, mean = μ′, corrected=false)
function normalise(x::AbstractArray, dims::Int=1)
μ′ = mean(x, dims = dims)
σ′ = std(x, dims = dims, mean = μ′, corrected=false)
return (x .- μ′) ./ σ′
end