From 2698bb5807c6c6ccae21e6d053bcccb6009d1468 Mon Sep 17 00:00:00 2001 From: Nabanita Dash Date: Fri, 19 Jun 2020 20:34:20 +0530 Subject: [PATCH 01/15] add adaptive pool --- docs/src/models/layers.md | 2 ++ src/Flux.jl | 7 +++-- src/layers/conv.jl | 59 +++++++++++++++++++++++++++++++++++++++ test/layers/conv.jl | 4 +++ 4 files changed, 69 insertions(+), 3 deletions(-) diff --git a/docs/src/models/layers.md b/docs/src/models/layers.md index d228cad8bd..87178536ae 100644 --- a/docs/src/models/layers.md +++ b/docs/src/models/layers.md @@ -13,8 +13,10 @@ These layers are used to build convolutional neural networks (CNNs). ```@docs Conv +AdaptiveMaxPool MaxPool GlobalMaxPool +AdaptiveMeanPool MeanPool GlobalMeanPool DepthwiseConv diff --git a/src/Flux.jl b/src/Flux.jl index c28a7d3637..e40f9ea7ce 100644 --- a/src/Flux.jl +++ b/src/Flux.jl @@ -12,9 +12,10 @@ using Zygote: Params, @adjoint, gradient, pullback, @nograd export gradient export Chain, Dense, Maxout, RNN, LSTM, GRU, SamePad, Conv, CrossCor, ConvTranspose, - GlobalMaxPool, GlobalMeanPool, MaxPool, MeanPool, flatten, - DepthwiseConv, Dropout, AlphaDropout, LayerNorm, BatchNorm, InstanceNorm, GroupNorm, - SkipConnection, params, fmap, cpu, gpu, f32, f64, testmode!, trainmode! + AdaptiveMaxPool, AdaptiveMeanPool, GlobalMaxPool, GlobalMeanPool, MaxPool, + MeanPool, flatten, DepthwiseConv, Dropout, AlphaDropout, LayerNorm, BatchNorm, + InstanceNorm, GroupNorm, SkipConnection, params, fmap, cpu, gpu, f32, f64, + testmode!, trainmode! include("optimise/Optimise.jl") using .Optimise diff --git a/src/layers/conv.jl b/src/layers/conv.jl index 3410ce653a..9f877c46ca 100644 --- a/src/layers/conv.jl +++ b/src/layers/conv.jl @@ -480,6 +480,65 @@ end outdims(l::CrossCor, isize) = output_size(DenseConvDims(_paddims(isize, size(l.weight)), size(l.weight); stride = l.stride, padding = l.pad, dilation = l.dilation)) +""" + AdaptiveMaxPool(out) +Adaptive max pooling layer. `out` is the size of the dimension of the output. +The output dimension is fixed irrespective of the size of the input. The stride, +kernel and padding is internally calculated using the input and output dimensions. +""" +struct AdaptiveMaxPool{S, O} + out::NTuple{O, Int} + AdaptiveMaxPool(out::NTuple{O, Int}) where O = new{O + 2, O}(out) +end + +function (a::AdaptiveMaxPool{S})(x::AbstractArray{T, S}) where {S, T} + in_size = size(x) + #Output_size + out_size = a.out + #Stride + stride = in_size ./ out_size + #Kernel_size + k = in_size .- (out_size .- 1) .* stride + #Padding + pad = 0 + pdims = PoolDims(x, k; padding=pad, stride=stride) + return maxpool(x, pdims) +end + +function Base.show(io::IO, a::AdaptiveMaxPool) + print(io, "AdaptiveMaxPool(", a.out, ")") +end + +""" + AdaptiveMeanPool(out) +Adaptive mean pooling layer. `out` is the size of the dimension of the output. +The output dimension is fixed irrespective of the size of the input. The stride, +kernel and padding is internally calculated using the input and output dimensions. +""" +struct AdaptiveMeanPool{S, O} + out::NTuple{O, Int} + AdaptiveMeanPool(out::NTuple{O, Int}) where O = new{O + 2, O}(out) +end + +function (a::AdaptiveMeanPool{S})(x::AbstractArray{T, S}) where {S, T} + #Input_size + in_size = size(x) + #Output_size + out_size = a.out + #Stride + stride = in_size ./ out_size + #Kernel_size + k = in_size .- (out_size .- 1) .* stride + #Padding + pad = 0 + pdims = PoolDims(x, k; padding=pad, stride=stride) + return meanpool(x, pdims) +end + +function Base.show(io::IO, a::AdaptiveMeanPool) + print(io, "AdaptiveMeanPool(", a.out, ")") +end + """ GlobalMaxPool() diff --git a/test/layers/conv.jl b/test/layers/conv.jl index 8c825bfda2..a7bb56c93c 100644 --- a/test/layers/conv.jl +++ b/test/layers/conv.jl @@ -4,6 +4,10 @@ using Flux: gradient @testset "Pooling" begin x = randn(Float32, 10, 10, 3, 2) + amp = AdaptiveMaxPool((5,5)) + @test amp(x) == maxpool(x, PoolDims(x, 2)) + amp = AdaptiveMeanPool((5,5)) + @test amp(x) == meanpool(x, PoolDims(x, 2)) gmp = GlobalMaxPool() @test size(gmp(x)) == (1, 1, 3, 2) gmp = GlobalMeanPool() From 66a0af4428ad13e7a5343016473f7a69315d4067 Mon Sep 17 00:00:00 2001 From: Nabanita Dash Date: Fri, 19 Jun 2020 21:04:56 +0530 Subject: [PATCH 02/15] changes as per review --- src/layers/conv.jl | 27 ++++++++++++++------------- 1 file changed, 14 insertions(+), 13 deletions(-) diff --git a/src/layers/conv.jl b/src/layers/conv.jl index 9f877c46ca..0f222e260b 100644 --- a/src/layers/conv.jl +++ b/src/layers/conv.jl @@ -492,13 +492,14 @@ struct AdaptiveMaxPool{S, O} end function (a::AdaptiveMaxPool{S})(x::AbstractArray{T, S}) where {S, T} - in_size = size(x) - #Output_size - out_size = a.out + #Input size + insize = size(x) + #Output size + outsize = a.out #Stride - stride = in_size ./ out_size - #Kernel_size - k = in_size .- (out_size .- 1) .* stride + stride = insize[1:end-2] ./ out_size + #Kernel size + k = insize .- (outsize .- 1) .* stride #Padding pad = 0 pdims = PoolDims(x, k; padding=pad, stride=stride) @@ -521,14 +522,14 @@ struct AdaptiveMeanPool{S, O} end function (a::AdaptiveMeanPool{S})(x::AbstractArray{T, S}) where {S, T} - #Input_size - in_size = size(x) - #Output_size - out_size = a.out + #Input size + insize = size(x) + #Outputsize + outsize = a.out #Stride - stride = in_size ./ out_size - #Kernel_size - k = in_size .- (out_size .- 1) .* stride + stride = insize[1:end-2] ./ outsize + #Kernel size + k = insize .- (outsize .- 1) .* stride #Padding pad = 0 pdims = PoolDims(x, k; padding=pad, stride=stride) From 51de13c10f68cc345e852bfac364102bf69e8b04 Mon Sep 17 00:00:00 2001 From: Nabanita Dash Date: Fri, 19 Jun 2020 21:16:12 +0530 Subject: [PATCH 03/15] Update conv.jl --- src/layers/conv.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/layers/conv.jl b/src/layers/conv.jl index 0f222e260b..59e7e5ccbb 100644 --- a/src/layers/conv.jl +++ b/src/layers/conv.jl @@ -497,7 +497,7 @@ function (a::AdaptiveMaxPool{S})(x::AbstractArray{T, S}) where {S, T} #Output size outsize = a.out #Stride - stride = insize[1:end-2] ./ out_size + stride = insize[1:end-2] ./ outsize #Kernel size k = insize .- (outsize .- 1) .* stride #Padding From b31fa6e1a56e8008f35ca36ba73f736429529e91 Mon Sep 17 00:00:00 2001 From: Nabanita Dash Date: Fri, 19 Jun 2020 21:48:53 +0530 Subject: [PATCH 04/15] Update conv.jl --- src/layers/conv.jl | 30 ++++++++++++------------------ 1 file changed, 12 insertions(+), 18 deletions(-) diff --git a/src/layers/conv.jl b/src/layers/conv.jl index 59e7e5ccbb..03035cd63d 100644 --- a/src/layers/conv.jl +++ b/src/layers/conv.jl @@ -482,9 +482,10 @@ outdims(l::CrossCor, isize) = """ AdaptiveMaxPool(out) + Adaptive max pooling layer. `out` is the size of the dimension of the output. -The output dimension is fixed irrespective of the size of the input. The stride, -kernel and padding is internally calculated using the input and output dimensions. + +The output dimension is fixed irrespective of the size of the input. """ struct AdaptiveMaxPool{S, O} out::NTuple{O, Int} @@ -492,15 +493,11 @@ struct AdaptiveMaxPool{S, O} end function (a::AdaptiveMaxPool{S})(x::AbstractArray{T, S}) where {S, T} - #Input size - insize = size(x) - #Output size + sz = size(x) + insize = sz[1:end-2] outsize = a.out - #Stride - stride = insize[1:end-2] ./ outsize - #Kernel size + stride = insize ./ outsize k = insize .- (outsize .- 1) .* stride - #Padding pad = 0 pdims = PoolDims(x, k; padding=pad, stride=stride) return maxpool(x, pdims) @@ -512,9 +509,10 @@ end """ AdaptiveMeanPool(out) + Adaptive mean pooling layer. `out` is the size of the dimension of the output. -The output dimension is fixed irrespective of the size of the input. The stride, -kernel and padding is internally calculated using the input and output dimensions. + +The output dimension is fixed irrespective of the size of the input. """ struct AdaptiveMeanPool{S, O} out::NTuple{O, Int} @@ -522,15 +520,11 @@ struct AdaptiveMeanPool{S, O} end function (a::AdaptiveMeanPool{S})(x::AbstractArray{T, S}) where {S, T} - #Input size - insize = size(x) - #Outputsize + sz = size(x) + insize = sz[1:end-2] outsize = a.out - #Stride - stride = insize[1:end-2] ./ outsize - #Kernel size + stride = insize ./ outsize k = insize .- (outsize .- 1) .* stride - #Padding pad = 0 pdims = PoolDims(x, k; padding=pad, stride=stride) return meanpool(x, pdims) From 1b81c080ff739f94aa2d2c51520afa734e58aa9c Mon Sep 17 00:00:00 2001 From: Nabanita Dash Date: Fri, 19 Jun 2020 21:50:59 +0530 Subject: [PATCH 05/15] Update conv.jl --- src/layers/conv.jl | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/src/layers/conv.jl b/src/layers/conv.jl index 03035cd63d..492e0c6879 100644 --- a/src/layers/conv.jl +++ b/src/layers/conv.jl @@ -483,9 +483,7 @@ outdims(l::CrossCor, isize) = """ AdaptiveMaxPool(out) -Adaptive max pooling layer. `out` is the size of the dimension of the output. - -The output dimension is fixed irrespective of the size of the input. +Adaptive max pooling layer. `out` is the desired output size (batch and channel dimension excluded). """ struct AdaptiveMaxPool{S, O} out::NTuple{O, Int} @@ -510,9 +508,7 @@ end """ AdaptiveMeanPool(out) -Adaptive mean pooling layer. `out` is the size of the dimension of the output. - -The output dimension is fixed irrespective of the size of the input. +Adaptive mean pooling layer. `out` is the desired output size (batch and channel dimension excluded). """ struct AdaptiveMeanPool{S, O} out::NTuple{O, Int} From 00a895aae963c624d2f52ba9954f29ff7f2ad515 Mon Sep 17 00:00:00 2001 From: Nabanita Dash Date: Fri, 19 Jun 2020 21:58:12 +0530 Subject: [PATCH 06/15] Update conv.jl --- src/layers/conv.jl | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/src/layers/conv.jl b/src/layers/conv.jl index 492e0c6879..d3f9b7b180 100644 --- a/src/layers/conv.jl +++ b/src/layers/conv.jl @@ -491,8 +491,7 @@ struct AdaptiveMaxPool{S, O} end function (a::AdaptiveMaxPool{S})(x::AbstractArray{T, S}) where {S, T} - sz = size(x) - insize = sz[1:end-2] + insize = size(x)[1:end-2] outsize = a.out stride = insize ./ outsize k = insize .- (outsize .- 1) .* stride @@ -516,8 +515,7 @@ struct AdaptiveMeanPool{S, O} end function (a::AdaptiveMeanPool{S})(x::AbstractArray{T, S}) where {S, T} - sz = size(x) - insize = sz[1:end-2] + insize = size(x)[1:end-2] outsize = a.out stride = insize ./ outsize k = insize .- (outsize .- 1) .* stride From 947e91ecbeac3d77386c01391952eca2457f49bb Mon Sep 17 00:00:00 2001 From: Nabanita Dash Date: Sat, 20 Jun 2020 10:58:04 +0530 Subject: [PATCH 07/15] changed k to Int --- src/layers/conv.jl | 36 ++++++++++++++++++------------------ 1 file changed, 18 insertions(+), 18 deletions(-) diff --git a/src/layers/conv.jl b/src/layers/conv.jl index d3f9b7b180..c899307dee 100644 --- a/src/layers/conv.jl +++ b/src/layers/conv.jl @@ -486,18 +486,18 @@ outdims(l::CrossCor, isize) = Adaptive max pooling layer. `out` is the desired output size (batch and channel dimension excluded). """ struct AdaptiveMaxPool{S, O} - out::NTuple{O, Int} - AdaptiveMaxPool(out::NTuple{O, Int}) where O = new{O + 2, O}(out) + out::NTuple{O, Int} + AdaptiveMaxPool(out::NTuple{O, Int}) where O = new{O + 2, O}(out) end function (a::AdaptiveMaxPool{S})(x::AbstractArray{T, S}) where {S, T} - insize = size(x)[1:end-2] - outsize = a.out - stride = insize ./ outsize - k = insize .- (outsize .- 1) .* stride - pad = 0 - pdims = PoolDims(x, k; padding=pad, stride=stride) - return maxpool(x, pdims) + insize = size(x)[1:end-2] + outsize = a.out + stride = insize ./ outsize + k = Int.(insize .- (outsize .- 1) .* stride) + pad = 0 + pdims = PoolDims(x, k; padding=pad, stride=stride) + return maxpool(x, pdims) end function Base.show(io::IO, a::AdaptiveMaxPool) @@ -510,18 +510,18 @@ end Adaptive mean pooling layer. `out` is the desired output size (batch and channel dimension excluded). """ struct AdaptiveMeanPool{S, O} - out::NTuple{O, Int} - AdaptiveMeanPool(out::NTuple{O, Int}) where O = new{O + 2, O}(out) + out::NTuple{O, Int} + AdaptiveMeanPool(out::NTuple{O, Int}) where O = new{O + 2, O}(out) end function (a::AdaptiveMeanPool{S})(x::AbstractArray{T, S}) where {S, T} - insize = size(x)[1:end-2] - outsize = a.out - stride = insize ./ outsize - k = insize .- (outsize .- 1) .* stride - pad = 0 - pdims = PoolDims(x, k; padding=pad, stride=stride) - return meanpool(x, pdims) + insize = size(x)[1:end-2] + outsize = a.out + stride = insize ./ outsize + k = Int.(insize .- (outsize .- 1) .* stride) + pad = 0 + pdims = PoolDims(x, k; padding=pad, stride=stride) + return meanpool(x, pdims) end function Base.show(io::IO, a::AdaptiveMeanPool) From e7685099036bb76b7846e433ec95499a4844c01c Mon Sep 17 00:00:00 2001 From: Nabanita Dash Date: Sat, 20 Jun 2020 11:59:18 +0530 Subject: [PATCH 08/15] Update conv.jl --- src/layers/conv.jl | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/layers/conv.jl b/src/layers/conv.jl index c899307dee..b96e922477 100644 --- a/src/layers/conv.jl +++ b/src/layers/conv.jl @@ -493,7 +493,7 @@ end function (a::AdaptiveMaxPool{S})(x::AbstractArray{T, S}) where {S, T} insize = size(x)[1:end-2] outsize = a.out - stride = insize ./ outsize + stride = Int.(insize ./ outsize) k = Int.(insize .- (outsize .- 1) .* stride) pad = 0 pdims = PoolDims(x, k; padding=pad, stride=stride) @@ -517,7 +517,7 @@ end function (a::AdaptiveMeanPool{S})(x::AbstractArray{T, S}) where {S, T} insize = size(x)[1:end-2] outsize = a.out - stride = insize ./ outsize + stride = Int.(insize ./ outsize) k = Int.(insize .- (outsize .- 1) .* stride) pad = 0 pdims = PoolDims(x, k; padding=pad, stride=stride) From bd63b08c1e7476b1b846a09e70c73d5a93182f8f Mon Sep 17 00:00:00 2001 From: Nabanita Dash Date: Sun, 21 Jun 2020 11:17:35 +0530 Subject: [PATCH 09/15] added some tests --- test/layers/conv.jl | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/test/layers/conv.jl b/test/layers/conv.jl index a7bb56c93c..1acebffcb3 100644 --- a/test/layers/conv.jl +++ b/test/layers/conv.jl @@ -4,10 +4,15 @@ using Flux: gradient @testset "Pooling" begin x = randn(Float32, 10, 10, 3, 2) - amp = AdaptiveMaxPool((5,5)) - @test amp(x) == maxpool(x, PoolDims(x, 2)) - amp = AdaptiveMeanPool((5,5)) - @test amp(x) == meanpool(x, PoolDims(x, 2)) + y = randn(float32, 20, 20, 3, 2) + ampx = AdaptiveMaxPool((5,5)) + @test ampx(x) == maxpool(x, PoolDims(x, 2)) + ampx = AdaptiveMeanPool((5,5)) + @test ampx(x) == meanpool(x, PoolDims(x, 2)) + ampy = AdaptiveMaxPool((10, 5)) + @test ampy(y) == maxpool(y, PoolDims(y, (2, 4))) + ampy = AdaptiveMeanPool((10, 5)) + @test ampy(y) == meanpool(y, PoolDims(y, (2, 4))) gmp = GlobalMaxPool() @test size(gmp(x)) == (1, 1, 3, 2) gmp = GlobalMeanPool() From c326f30cf711edd4aecfb2881790181f40d1f7b9 Mon Sep 17 00:00:00 2001 From: Nabanita Dash Date: Sun, 21 Jun 2020 11:29:27 +0530 Subject: [PATCH 10/15] Update conv.jl --- test/layers/conv.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/layers/conv.jl b/test/layers/conv.jl index 1acebffcb3..4a468c84d3 100644 --- a/test/layers/conv.jl +++ b/test/layers/conv.jl @@ -4,7 +4,7 @@ using Flux: gradient @testset "Pooling" begin x = randn(Float32, 10, 10, 3, 2) - y = randn(float32, 20, 20, 3, 2) + y = randn(Float32, 20, 20, 3, 2) ampx = AdaptiveMaxPool((5,5)) @test ampx(x) == maxpool(x, PoolDims(x, 2)) ampx = AdaptiveMeanPool((5,5)) From c10b39ea2c12cba449439731bf000e58d95cc43d Mon Sep 17 00:00:00 2001 From: Nabanita Dash Date: Mon, 22 Jun 2020 11:31:25 +0530 Subject: [PATCH 11/15] update news.md --- NEWS.md | 1 + 1 file changed, 1 insertion(+) diff --git a/NEWS.md b/NEWS.md index 587d909f87..46f410eb0c 100644 --- a/NEWS.md +++ b/NEWS.md @@ -2,6 +2,7 @@ * Change to `DataLoader`'s constructor [https://github.com/FluxML/Flux.jl/pull/1152] * Use `DataLoader` with `NamedTuple`s, so that tensors can be accessed by name [https://github.com/FluxML/Flux.jl/pull/1221]. * Error if Dense layers weights and biases are not arrays [https://github.com/FluxML/Flux.jl/pull/1218]. +* Add `Adaptive Pooling` in Flux layers [https://github.com/FluxML/Flux.jl/pull/1239]. # v0.10.5 * Add option for [same padding](https://github.com/FluxML/Flux.jl/pull/901) to conv and pooling layers by setting `pad=SamePad()`. From 1ac34771527c8280a234c0738970b2eaf6124c40 Mon Sep 17 00:00:00 2001 From: Nabanita Dash Date: Sun, 28 Jun 2020 11:32:04 +0530 Subject: [PATCH 12/15] added gpu tests --- test/cuda/layers.jl | 3 +++ 1 file changed, 3 insertions(+) diff --git a/test/cuda/layers.jl b/test/cuda/layers.jl index e48a464280..b51320ff4c 100644 --- a/test/cuda/layers.jl +++ b/test/cuda/layers.jl @@ -52,6 +52,9 @@ gradtest("Conv", conv_layers, r, (2,2), 1=>3) pooling_layers = [MaxPool, MeanPool] gradtest("Pooling", pooling_layers, r, (2,2)) +adaptive_pooling_layers = [AdaptiveMaxPool, AdaptiveMeanPool] +gradtest("AdaptivePooling", adaptive_pooling_layers, r, (7,7)) + dropout_layers = [Dropout, AlphaDropout] gradtest("Dropout", dropout_layers, r, 0.5f0) From 9c2c21df1fd514e09d51eade72d98b64af275419 Mon Sep 17 00:00:00 2001 From: Nabanita Dash Date: Sun, 28 Jun 2020 11:36:50 +0530 Subject: [PATCH 13/15] =?UTF-8?q?changed=20from=20/=20to=20=C3=B7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/layers/conv.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/layers/conv.jl b/src/layers/conv.jl index b96e922477..10585829d2 100644 --- a/src/layers/conv.jl +++ b/src/layers/conv.jl @@ -493,7 +493,7 @@ end function (a::AdaptiveMaxPool{S})(x::AbstractArray{T, S}) where {S, T} insize = size(x)[1:end-2] outsize = a.out - stride = Int.(insize ./ outsize) + stride = insize .÷ outsize k = Int.(insize .- (outsize .- 1) .* stride) pad = 0 pdims = PoolDims(x, k; padding=pad, stride=stride) From bf718048b5862337a54de11f8835c7791efc59e0 Mon Sep 17 00:00:00 2001 From: Nabanita Dash Date: Sun, 28 Jun 2020 18:34:25 +0530 Subject: [PATCH 14/15] =?UTF-8?q?changed=20from=20/=20to=20=C3=B7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/layers/conv.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/layers/conv.jl b/src/layers/conv.jl index 10585829d2..ea2f6b84b2 100644 --- a/src/layers/conv.jl +++ b/src/layers/conv.jl @@ -517,7 +517,7 @@ end function (a::AdaptiveMeanPool{S})(x::AbstractArray{T, S}) where {S, T} insize = size(x)[1:end-2] outsize = a.out - stride = Int.(insize ./ outsize) + stride = insize .÷ outsize k = Int.(insize .- (outsize .- 1) .* stride) pad = 0 pdims = PoolDims(x, k; padding=pad, stride=stride) From 72f5d14e68e1f0d092bef78993b67c3d07c04213 Mon Sep 17 00:00:00 2001 From: Nabanita Dash Date: Tue, 30 Jun 2020 08:40:41 +0530 Subject: [PATCH 15/15] fix changes --- src/layers/conv.jl | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/layers/conv.jl b/src/layers/conv.jl index ea2f6b84b2..3a5bb990fb 100644 --- a/src/layers/conv.jl +++ b/src/layers/conv.jl @@ -494,7 +494,7 @@ function (a::AdaptiveMaxPool{S})(x::AbstractArray{T, S}) where {S, T} insize = size(x)[1:end-2] outsize = a.out stride = insize .÷ outsize - k = Int.(insize .- (outsize .- 1) .* stride) + k = insize .- (outsize .- 1) .* stride pad = 0 pdims = PoolDims(x, k; padding=pad, stride=stride) return maxpool(x, pdims) @@ -518,7 +518,7 @@ function (a::AdaptiveMeanPool{S})(x::AbstractArray{T, S}) where {S, T} insize = size(x)[1:end-2] outsize = a.out stride = insize .÷ outsize - k = Int.(insize .- (outsize .- 1) .* stride) + k = insize .- (outsize .- 1) .* stride pad = 0 pdims = PoolDims(x, k; padding=pad, stride=stride) return meanpool(x, pdims)