Skip to content

Commit 11f840d

Browse files
Merge pull request #99 from thebhatman/patch-1
Changed output size calculation to support kernel size such as (x,y)
2 parents 2bd7e8a + 7e19660 commit 11f840d

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

src/impl/conv.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ img_size(c::ConvDims{I,K,C,S,P,D,F}) where {I, K, C, S, P, D, F} = I
1818
# Calculate the output dimensions of this convolution
1919
function output_size(c::ConvDims{I,K,C,S,P,D,F}) where {I, K, C, S, P, D, F}
2020
O_w = div(I[1] + P[1] + P[2] - (K[1] - 1) * D[1] - 1, S[1]) + 1
21-
O_h = div(I[2] + P[3] + P[4] - (K[1] - 1) * D[1] - 1, S[1]) + 1
21+
O_h = div(I[2] + P[3] + P[4] - (K[2] - 1) * D[2] - 1, S[2]) + 1
2222
return (O_w, O_h)
2323
end
2424
kernel_size(c::ConvDims{I,K,C,S,P,D,F}) where {I, K, C, S, P, D, F} = K

test/conv.jl

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,19 @@ using NNlib: conv, crosscor, ∇conv_filter, ∇conv_data, ∇maxpool, maxpool,
33
@testset "conv2d" begin
44
x = reshape(Float64[1:20;], 5, 4, 1, 1)
55
w = reshape(Float64[1:4;], 2, 2, 1, 1)
6+
w1 = reshape(Float64[1:6;], 2, 3, 1, 1)
7+
w2 = reshape(Float64[1:6;], 3, 2, 1, 1)
8+
9+
@test dropdims(conv(x, w1), dims = (3,4)) == [
10+
95.0 200.0;
11+
116.0 221.0;
12+
137.0 242.0;
13+
158.0 263.0]
14+
15+
@test dropdims(conv(x, w2), dims = (3,4)) == [
16+
68.0 173.0 278.0;
17+
89.0 194.0 299.0;
18+
110.0 215.0 320.0]
619

720
@test dropdims(conv(x, w), dims = (3,4)) == [
821
29 79 129;

0 commit comments

Comments
 (0)