2018-09-04 13:35:20 +00:00
|
|
|
using Flux, Test
|
|
|
|
using Flux: maxpool, meanpool
|
2018-08-24 02:31:13 +00:00
|
|
|
|
2018-09-04 13:35:20 +00:00
|
|
|
@testset "Pooling" begin
|
2018-09-07 00:25:32 +00:00
|
|
|
x = randn(Float32, 10, 10, 3, 2)
|
2018-08-24 02:31:13 +00:00
|
|
|
mp = MaxPool((2, 2))
|
2018-09-04 13:30:02 +00:00
|
|
|
@test mp(x) == maxpool(x, (2,2))
|
2018-08-24 02:31:13 +00:00
|
|
|
mp = MeanPool((2, 2))
|
2018-09-04 13:30:02 +00:00
|
|
|
@test mp(x) == meanpool(x, (2,2))
|
2018-08-24 02:31:13 +00:00
|
|
|
end
|
|
|
|
|
2018-09-04 13:35:20 +00:00
|
|
|
@testset "CNN" begin
|
2018-09-07 00:25:32 +00:00
|
|
|
r = zeros(Float32, 28, 28, 1, 5)
|
2018-09-04 13:35:20 +00:00
|
|
|
m = Chain(
|
|
|
|
Conv((2, 2), 1=>16, relu),
|
|
|
|
MaxPool((2,2)),
|
|
|
|
Conv((2, 2), 16=>8, relu),
|
|
|
|
MaxPool((2,2)),
|
|
|
|
x -> reshape(x, :, size(x, 4)),
|
|
|
|
Dense(288, 10), softmax)
|
2018-08-24 02:31:13 +00:00
|
|
|
|
2018-09-04 13:35:20 +00:00
|
|
|
@test size(m(r)) == (10, 5)
|
2018-08-24 02:31:13 +00:00
|
|
|
end
|
2019-01-24 13:23:04 +00:00
|
|
|
|
|
|
|
@testset "Depthwise Conv" begin
|
|
|
|
r = zeros(Float32, 28, 28, 3, 5)
|
|
|
|
|
|
|
|
m1 = DepthwiseConv((2, 2), 3=>5)
|
|
|
|
|
|
|
|
@test size(m1(r), 3) == 15
|
|
|
|
|
|
|
|
m2 = DepthwiseConv((2, 2), 3)
|
|
|
|
|
|
|
|
@test size(m2(r), 3) == 3
|
|
|
|
end
|