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

Issues with degenerate input for pooling layers #86

Closed
staticfloat opened this issue Jan 21, 2019 · 1 comment
Closed

Issues with degenerate input for pooling layers #86

staticfloat opened this issue Jan 21, 2019 · 1 comment

Comments

@staticfloat
Copy link
Contributor

Our pooling layers don't deal well with degenerate inputs (e.g. ones()). MWE:

using Flux
x = ones(10, 10, 1, 1)
xp = param(x)
y_hat = MaxPool((3,3), stride=(2,2))(xp)
Flux.back!(sum(y_hat))

Which results in:

julia> xp.grad
10×10×1×1 Array{Float64,4}:
[:, :, 1, 1] =
 1.0  1.0  2.0  1.0  2.0  1.0  2.0  1.0  1.0  0.0
 1.0  1.0  2.0  1.0  2.0  1.0  2.0  1.0  1.0  0.0
 2.0  2.0  4.0  2.0  4.0  2.0  4.0  2.0  2.0  0.0
 1.0  1.0  2.0  1.0  2.0  1.0  2.0  1.0  1.0  0.0
 2.0  2.0  4.0  2.0  4.0  2.0  4.0  2.0  2.0  0.0
 1.0  1.0  2.0  1.0  2.0  1.0  2.0  1.0  1.0  0.0
 2.0  2.0  4.0  2.0  4.0  2.0  4.0  2.0  2.0  0.0
 1.0  1.0  2.0  1.0  2.0  1.0  2.0  1.0  1.0  0.0
 1.0  1.0  2.0  1.0  2.0  1.0  2.0  1.0  1.0  0.0
 0.0  0.0  0.0  0.0  0.0  0.0  0.0  0.0  0.0  0.0

Compare with adding a bit of noise to eliminate the degeneracy:

xp = param(x .+ 0.01.*randn(size(x)...))
y_hat = MaxPool((3,3), stride=(2,2))(xp)
Flux.back!(sum(y_hat))

Which results in the proper output of prod(size(y_hat)) == sum(xp.grad) :

julia> xp.grad
10×10×1×1 Array{Float64,4}:
[:, :, 1, 1] =
 0.0  0.0  2.0  0.0  0.0  0.0  0.0  0.0  0.0  0.0
 0.0  0.0  0.0  0.0  0.0  1.0  0.0  0.0  0.0  0.0
 0.0  0.0  0.0  1.0  0.0  0.0  0.0  0.0  2.0  0.0
 0.0  0.0  0.0  0.0  1.0  0.0  0.0  0.0  0.0  0.0
 0.0  2.0  0.0  0.0  0.0  0.0  0.0  0.0  0.0  0.0
 0.0  0.0  0.0  0.0  1.0  0.0  0.0  0.0  1.0  0.0
 0.0  0.0  0.0  1.0  0.0  0.0  0.0  0.0  0.0  0.0
 0.0  0.0  0.0  0.0  0.0  0.0  0.0  0.0  0.0  0.0
 0.0  0.0  2.0  0.0  0.0  1.0  0.0  0.0  1.0  0.0
 0.0  0.0  0.0  0.0  0.0  0.0  0.0  0.0  0.0  0.0
@staticfloat
Copy link
Contributor Author

Fixed by #94

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant