Skip to content

Layer normalisation does not work for images #406

Closed
@skariel

Description

@skariel

The layer uses the normalise (stateless) function as defined here. This function calculates mean and std on dims=1 but for images we need dims=(1,2,3) leaving out only the batch dimension. The following function should work:

function normalise(x)
    d = ndims(x) == 4 ? [1,2,3] : [1,]
    mu = Flux.mean(x, dims=d)
    sd = Flux.std(x, dims=d, mean=mu)
    return (x.-mu)./sd
end

also the type of x has to change in the function signature to allow for images, currently x::AbstractVecOrMat fails for e.g. rand(Float32, 84,84,1,1) since it allows only 1d or 2d arrays.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions