From b132c59a67faf8288f7a81752dc6bc7629ad04d3 Mon Sep 17 00:00:00 2001 From: Kyle Daruwalla Date: Sat, 18 Jun 2022 23:21:56 +0530 Subject: [PATCH 01/16] Add initial efficient net --- src/convnets/efficientnet.jl | 98 ++++++++++++++++++++++++++++++++++++ 1 file changed, 98 insertions(+) create mode 100644 src/convnets/efficientnet.jl diff --git a/src/convnets/efficientnet.jl b/src/convnets/efficientnet.jl new file mode 100644 index 000000000..bff4c05c3 --- /dev/null +++ b/src/convnets/efficientnet.jl @@ -0,0 +1,98 @@ +function efficientnet(scalings, block_config; + inchannels = 3, nclasses = 1000, max_width = 1280) + wscale, dscale = scalings + out_channels = _round_channels(32, 8) + stem = Chain(Conv((3, 3), inchannels => out_channels; + bias = false, stride = 2, pad = SamePad()), + BatchNorm(out_channels, swish)) + + blocks = [] + for (n, k, s, e, i, o) in block_config + in_channels = round_filter(i, 8) + out_channels = round_filter(o, 8) + repeat = dscale ≈ 1 ? n : ceil(Int64, dscale * n) + + push!(blocks, + invertedresidual(k, in_channels, in_channels * e, out_channels, swish; + stride = s, reduction = 4)) + for _ in 1:(repeat - 1) + push!(blocks, + invertedresidual(k, out_channels, out_channels * e, out_channels, swish; + stride = 1, reduction = 4)) + end + end + blocks = Chain(blocks...) + + head_out_channels = _round_channels(max_width, 8) + head = Chain(Conv((1, 1), out_channels => head_out_channels; + bias = false, pad = SamePad()), + BatchNorm(head_out_channels, swish)) + + top = Dense(head_out_channels, nclasses) + + return Chain(Chain(stem, blocks, head), + Chain(AdaptiveMeanPool((1, 1)), MLUtils.flatten, top)) +end + +# n: # of block repetitions +# k: kernel size k x k +# s: stride +# e: expantion ratio +# i: block input channels +# o: block output channels +const efficientnet_block_configs = [ +# (n, k, s, e, i, o) + (1, 3, 1, 1, 32, 16), + (2, 3, 2, 6, 16, 24), + (2, 5, 2, 6, 24, 40), + (3, 3, 2, 6, 40, 80), + (3, 5, 1, 6, 80, 112), + (4, 5, 2, 6, 112, 192), + (1, 3, 1, 6, 192, 320) +] + +# w: width scaling +# d: depth scaling +# r: image resolution +const efficientnet_global_configs = Dict( +# ( r, ( w, d)) + :b0 => (224, (1.0, 1.0)), + :b1 => (240, (1.0, 1.1)), + :b2 => (260, (1.1, 1.2)), + :b3 => (300, (1.2, 1.4)), + :b4 => (380, (1.4, 1.8)), + :b5 => (456, (1.6, 2.2)), + :b6 => (528, (1.8, 2.6)), + :b7 => (600, (2.0, 3.1)), + :b8 => (672, (2.2, 3.6)) +) + +struct EfficientNet + layers::Any +end + +function EfficientNet(scalings, block_config; + inchannels = 3, nclasses = 1000, max_width = 1280) + layers = efficientnet(scalings, block_config; + inchannels = inchannels, + nclasses = nclasses, + max_width = max_width) + return EfficientNet(layers) +end + +@functor EfficientNet + +(m::EfficientNet)(x) = m.layers(x) + +backbone(m::EfficientNet) = m.layers[1] +classifier(m::EfficientNet) = m.layers[2] + +function EfficientNet(name::Symbol; pretrain = false) + @assert name in keys(efficientnet_global_configs) + "`name` must be one of $(sort(collect(keys(efficientnet_global_configs))))" + + model = EfficientNet(efficientnet_global_configs[name]..., efficientnet_block_configs) + pretrain && loadpretrain!(model, string("efficientnet-", name)) + + return model +end From 50ca201bc67980aa8cc0994bf669a9ae283f888f Mon Sep 17 00:00:00 2001 From: Kyle Daruwalla Date: Sun, 19 Jun 2022 09:02:08 +0530 Subject: [PATCH 02/16] Clean up implementation and add docstrings --- src/convnets/efficientnet.jl | 59 +++++++++++++++++++++++++++++++++++- 1 file changed, 58 insertions(+), 1 deletion(-) diff --git a/src/convnets/efficientnet.jl b/src/convnets/efficientnet.jl index bff4c05c3..4e28072dd 100644 --- a/src/convnets/efficientnet.jl +++ b/src/convnets/efficientnet.jl @@ -1,3 +1,25 @@ +""" + efficientnet(scalings, block_config; + inchannels = 3, nclasses = 1000, max_width = 1280) + +Create an EfficientNet model ([reference](https://arxiv.org/abs/1905.11946v5)). + +# Arguments + +- `scalings`: global width and depth scaling (given as a tuple) +- `block_config`: configuration for each inverted residual block, + given as a vector of tuples with elements: + - `n`: number of block repetitions (will be scaled by global depth scaling) + - `k`: kernel size + - `s`: kernel stride + - `e`: expansion ratio + - `i`: block input channels + - `o`: block output channels (will be scaled by global width scaling) +- `inchannels`: number of input channels +- `nclasses`: number of output classes +- `max_width`: maximum number of output channels before the fully connected + classification blocks +""" function efficientnet(scalings, block_config; inchannels = 3, nclasses = 1000, max_width = 1280) wscale, dscale = scalings @@ -9,7 +31,7 @@ function efficientnet(scalings, block_config; blocks = [] for (n, k, s, e, i, o) in block_config in_channels = round_filter(i, 8) - out_channels = round_filter(o, 8) + out_channels = round_filter(wscale ≈ 1 ? o : ceil(Int64, wscale * o), 8) repeat = dscale ≈ 1 ? n : ceil(Int64, dscale * n) push!(blocks, @@ -71,6 +93,29 @@ struct EfficientNet layers::Any end +""" + EfficientNet(scalings, block_config; + inchannels = 3, nclasses = 1000, max_width = 1280) + +Create an EfficientNet model ([reference](https://arxiv.org/abs/1905.11946v5)). +See also [`efficientnet`](#). + +# Arguments + +- `scalings`: global width and depth scaling (given as a tuple) +- `block_config`: configuration for each inverted residual block, + given as a vector of tuples with elements: + - `n`: number of block repetitions (will be scaled by global depth scaling) + - `k`: kernel size + - `s`: kernel stride + - `e`: expansion ratio + - `i`: block input channels + - `o`: block output channels (will be scaled by global width scaling) +- `inchannels`: number of input channels +- `nclasses`: number of output classes +- `max_width`: maximum number of output channels before the fully connected + classification blocks +""" function EfficientNet(scalings, block_config; inchannels = 3, nclasses = 1000, max_width = 1280) layers = efficientnet(scalings, block_config; @@ -87,6 +132,18 @@ end backbone(m::EfficientNet) = m.layers[1] classifier(m::EfficientNet) = m.layers[2] +""" + EfficientNet(name::Symbol; pretrain = false) + +Create an EfficientNet model ([reference](https://arxiv.org/abs/1905.11946v5)). +See also [`efficientnet`](#). + +# Arguments + +- `name`: name of default configuration + (can be `:b0`, `:b1`, `:b2`, `:b3`, `:b4`, `:b5`, `:b6`, `:b7`, `:b8`) +- `pretrain`: set to `true` to load the pre-trained weights for ImageNet +""" function EfficientNet(name::Symbol; pretrain = false) @assert name in keys(efficientnet_global_configs) "`name` must be one of $(sort(collect(keys(efficientnet_global_configs))))" From 0ccfc7802dae975f13022a4dc83af7641773749b Mon Sep 17 00:00:00 2001 From: Kyle Daruwalla Date: Sun, 19 Jun 2022 09:05:33 +0530 Subject: [PATCH 03/16] Add tests and docs --- README.md | 1 + test/convnets.jl | 18 ++++++++++++++++++ 2 files changed, 19 insertions(+) diff --git a/README.md b/README.md index fb8b215f5..c4e909b45 100644 --- a/README.md +++ b/README.md @@ -28,6 +28,7 @@ | [MobileNetv1](https://arxiv.org/abs/1704.04861) | [`MobileNetv1`](https://fluxml.ai/Metalhead.jl/dev/docstrings/Metalhead.MobileNetv1.html) | N | | [MobileNetv2](https://arxiv.org/abs/1801.04381) | [`MobileNetv2`](https://fluxml.ai/Metalhead.jl/dev/docstrings/Metalhead.MobileNetv2.html) | N | | [MobileNetv3](https://arxiv.org/abs/1905.02244) | [`MobileNetv3`](https://fluxml.ai/Metalhead.jl/dev/docstrings/Metalhead.MobileNetv3.html) | N | +| [EfficientNet](https://arxiv.org/abs/1905.11946) | [`EfficientNet`](https://fluxml.ai/Metalhead.jl/dev/docstrings/Metalhead.EfficientNet.html) | N | | [MLPMixer](https://arxiv.org/pdf/2105.01601) | [`MLPMixer`](https://fluxml.ai/Metalhead.jl/dev/docstrings/Metalhead.MLPMixer.html) | N | | [ResMLP](https://arxiv.org/abs/2105.03404) | [`ResMLP`](https://fluxml.ai/Metalhead.jl/dev/docstrings/Metalhead.ResMLP.html) | N | | [gMLP](https://arxiv.org/abs/2105.08050) | [`gMLP`](https://fluxml.ai/Metalhead.jl/dev/docstrings/Metalhead.gMLP.html) | N | diff --git a/test/convnets.jl b/test/convnets.jl index 4949e34e6..7e02b73d0 100644 --- a/test/convnets.jl +++ b/test/convnets.jl @@ -70,6 +70,24 @@ end GC.safepoint() GC.gc() +@testset "EfficientNet" begin + @testset "EfficientNet($name)" for name in [:b0, :b1, :b2, :b3, :b4, :b5, :b6, :b7, :b8] + m = EfficientNet(name) + @test size(m(x_256)) == (1000, 1) + if (EfficientNet, name) in PRETRAINED_MODELS + @test (EfficientNet(name, pretrain = true); true) + else + @test_throws ArgumentError EfficientNet(name, pretrain = true) + end + @test gradtest(m, x_256) + GC.safepoint() + GC.gc() + end +end + +GC.safepoint() +GC.gc() + @testset "GoogLeNet" begin m = GoogLeNet() @test size(m(x_224)) == (1000, 1) From e1dee6c5dfc2823b1e2ed9e57700061430e3c13c Mon Sep 17 00:00:00 2001 From: Kyle Daruwalla Date: Sun, 19 Jun 2022 10:10:17 +0530 Subject: [PATCH 04/16] Don't forget to export! --- src/Metalhead.jl | 2 +- src/convnets/efficientnet.jl | 5 ++--- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/src/Metalhead.jl b/src/Metalhead.jl index b489b2fca..05a08c0a2 100644 --- a/src/Metalhead.jl +++ b/src/Metalhead.jl @@ -42,7 +42,7 @@ export AlexNet, VGG, VGG11, VGG13, VGG16, VGG19, ResNet, ResNet18, ResNet34, ResNet50, ResNet101, ResNet152, ResNeXt, DenseNet, DenseNet121, DenseNet161, DenseNet169, DenseNet201, GoogLeNet, Inception3, Inceptionv3, Inceptionv4, InceptionResNetv2, Xception, - SqueezeNet, MobileNetv1, MobileNetv2, MobileNetv3, + SqueezeNet, MobileNetv1, MobileNetv2, MobileNetv3, EfficientNet, MLPMixer, ResMLP, gMLP, ViT, ConvMixer, ConvNeXt diff --git a/src/convnets/efficientnet.jl b/src/convnets/efficientnet.jl index 4e28072dd..95933912d 100644 --- a/src/convnets/efficientnet.jl +++ b/src/convnets/efficientnet.jl @@ -24,9 +24,8 @@ function efficientnet(scalings, block_config; inchannels = 3, nclasses = 1000, max_width = 1280) wscale, dscale = scalings out_channels = _round_channels(32, 8) - stem = Chain(Conv((3, 3), inchannels => out_channels; - bias = false, stride = 2, pad = SamePad()), - BatchNorm(out_channels, swish)) + stem = conv_bn((3, 3), inchannels, out_channels, swish; + bias = false, stride = 2, pad = SamePad()) blocks = [] for (n, k, s, e, i, o) in block_config From d7e2e19da3ad0bced34c8501dd0df3587a9c12b9 Mon Sep 17 00:00:00 2001 From: Kyle Daruwalla Date: Sun, 19 Jun 2022 13:20:48 +0530 Subject: [PATCH 05/16] Also don't forget to include --- src/Metalhead.jl | 1 + 1 file changed, 1 insertion(+) diff --git a/src/Metalhead.jl b/src/Metalhead.jl index 05a08c0a2..f391c0c66 100644 --- a/src/Metalhead.jl +++ b/src/Metalhead.jl @@ -27,6 +27,7 @@ include("convnets/resnext.jl") include("convnets/densenet.jl") include("convnets/squeezenet.jl") include("convnets/mobilenet.jl") +include("convnets/efficientnet.jl") include("convnets/convnext.jl") include("convnets/convmixer.jl") From a83efd9666090b8da270f97288f25a4ec99a28d3 Mon Sep 17 00:00:00 2001 From: Kyle Daruwalla Date: Sun, 19 Jun 2022 21:56:01 +0530 Subject: [PATCH 06/16] No need to use image resolution scaling (implicitly done) --- src/convnets/efficientnet.jl | 2 +- test/convnets.jl | 6 ++++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/src/convnets/efficientnet.jl b/src/convnets/efficientnet.jl index 95933912d..265a386ea 100644 --- a/src/convnets/efficientnet.jl +++ b/src/convnets/efficientnet.jl @@ -147,7 +147,7 @@ function EfficientNet(name::Symbol; pretrain = false) @assert name in keys(efficientnet_global_configs) "`name` must be one of $(sort(collect(keys(efficientnet_global_configs))))" - model = EfficientNet(efficientnet_global_configs[name]..., efficientnet_block_configs) + model = EfficientNet(efficientnet_global_configs[name][2], efficientnet_block_configs) pretrain && loadpretrain!(model, string("efficientnet-", name)) return model diff --git a/test/convnets.jl b/test/convnets.jl index 7e02b73d0..3b58d7122 100644 --- a/test/convnets.jl +++ b/test/convnets.jl @@ -72,14 +72,16 @@ GC.gc() @testset "EfficientNet" begin @testset "EfficientNet($name)" for name in [:b0, :b1, :b2, :b3, :b4, :b5, :b6, :b7, :b8] + xsz = Metalhead.efficientnet_global_configs[name][1] + x = rand(Float32, xsz...) m = EfficientNet(name) - @test size(m(x_256)) == (1000, 1) + @test size(m(x)) == (1000, 1) if (EfficientNet, name) in PRETRAINED_MODELS @test (EfficientNet(name, pretrain = true); true) else @test_throws ArgumentError EfficientNet(name, pretrain = true) end - @test gradtest(m, x_256) + @test gradtest(m, x) GC.safepoint() GC.gc() end From 5e5a56ea3dd3629d15666b9b24f898cf9f7bc9ee Mon Sep 17 00:00:00 2001 From: Kyle Daruwalla Date: Sun, 19 Jun 2022 21:57:32 +0530 Subject: [PATCH 07/16] Use acctest for efficient net --- test/convnets.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/convnets.jl b/test/convnets.jl index 3b58d7122..1638684b9 100644 --- a/test/convnets.jl +++ b/test/convnets.jl @@ -77,7 +77,7 @@ GC.gc() m = EfficientNet(name) @test size(m(x)) == (1000, 1) if (EfficientNet, name) in PRETRAINED_MODELS - @test (EfficientNet(name, pretrain = true); true) + @test acctest(EfficientNet(name, pretrain = true)) else @test_throws ArgumentError EfficientNet(name, pretrain = true) end From 7e2e1e49414ac5bf37e3b6dc2d74652ecd56e519 Mon Sep 17 00:00:00 2001 From: Kyle Daruwalla Date: Sun, 19 Jun 2022 23:41:28 +0530 Subject: [PATCH 08/16] Fix a copy paste error for _round_channels --- src/convnets/efficientnet.jl | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/convnets/efficientnet.jl b/src/convnets/efficientnet.jl index 265a386ea..87b165adc 100644 --- a/src/convnets/efficientnet.jl +++ b/src/convnets/efficientnet.jl @@ -29,8 +29,8 @@ function efficientnet(scalings, block_config; blocks = [] for (n, k, s, e, i, o) in block_config - in_channels = round_filter(i, 8) - out_channels = round_filter(wscale ≈ 1 ? o : ceil(Int64, wscale * o), 8) + in_channels = _round_channels(i, 8) + out_channels = _round_channels(wscale ≈ 1 ? o : ceil(Int64, wscale * o), 8) repeat = dscale ≈ 1 ? n : ceil(Int64, dscale * n) push!(blocks, From 19a18bfb78abc83c71573290ca0d485c5cf5bdec Mon Sep 17 00:00:00 2001 From: Kyle Daruwalla Date: Mon, 20 Jun 2022 08:44:26 +0530 Subject: [PATCH 09/16] Splat conv_bn --- src/convnets/efficientnet.jl | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/src/convnets/efficientnet.jl b/src/convnets/efficientnet.jl index 87b165adc..6b8960487 100644 --- a/src/convnets/efficientnet.jl +++ b/src/convnets/efficientnet.jl @@ -45,14 +45,13 @@ function efficientnet(scalings, block_config; blocks = Chain(blocks...) head_out_channels = _round_channels(max_width, 8) - head = Chain(Conv((1, 1), out_channels => head_out_channels; - bias = false, pad = SamePad()), - BatchNorm(head_out_channels, swish)) + head = conv_bn((1, 1), out_channels, head_out_channels, swish; + bias = false, pad = SamePad()) top = Dense(head_out_channels, nclasses) - return Chain(Chain(stem, blocks, head), - Chain(AdaptiveMeanPool((1, 1)), MLUtils.flatten, top)) + return Chain(Chain(stem..., blocks, head...), + Chain(AdaptiveMeanPool((1, 1)), MLUtils.flatten, top)) end # n: # of block repetitions From 61d886b05efd8d70dc0a97b1790bd82bafbbc2cb Mon Sep 17 00:00:00 2001 From: Kyle Daruwalla Date: Mon, 20 Jun 2022 19:33:45 +0530 Subject: [PATCH 10/16] Fix size error in test setup --- test/convnets.jl | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/test/convnets.jl b/test/convnets.jl index 1638684b9..654f83160 100644 --- a/test/convnets.jl +++ b/test/convnets.jl @@ -72,8 +72,9 @@ GC.gc() @testset "EfficientNet" begin @testset "EfficientNet($name)" for name in [:b0, :b1, :b2, :b3, :b4, :b5, :b6, :b7, :b8] - xsz = Metalhead.efficientnet_global_configs[name][1] - x = rand(Float32, xsz...) + # preferred image resolution scaling + r = Metalhead.efficientnet_global_configs[name][1] + x = rand(Float32, r, r, 3, 1) m = EfficientNet(name) @test size(m(x)) == (1000, 1) if (EfficientNet, name) in PRETRAINED_MODELS From aa1d37d4d30e17590b9622a19c7e10c181fb0148 Mon Sep 17 00:00:00 2001 From: Kyle Daruwalla Date: Wed, 22 Jun 2022 08:03:27 -0400 Subject: [PATCH 11/16] Account for width scaling in input channel size --- src/convnets/efficientnet.jl | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/src/convnets/efficientnet.jl b/src/convnets/efficientnet.jl index 6b8960487..be32dfda9 100644 --- a/src/convnets/efficientnet.jl +++ b/src/convnets/efficientnet.jl @@ -23,20 +23,23 @@ Create an EfficientNet model ([reference](https://arxiv.org/abs/1905.11946v5)). function efficientnet(scalings, block_config; inchannels = 3, nclasses = 1000, max_width = 1280) wscale, dscale = scalings - out_channels = _round_channels(32, 8) + scalew(w) = wscale ≈ 1 ? w : ceil(Int64, wscale * w) + scaled(d) = dscale ≈ 1 ? d : ceil(Int64, dscale * d) + + out_channels = _round_channels(scalew(32), 8) stem = conv_bn((3, 3), inchannels, out_channels, swish; bias = false, stride = 2, pad = SamePad()) blocks = [] for (n, k, s, e, i, o) in block_config - in_channels = _round_channels(i, 8) - out_channels = _round_channels(wscale ≈ 1 ? o : ceil(Int64, wscale * o), 8) - repeat = dscale ≈ 1 ? n : ceil(Int64, dscale * n) + in_channels = _round_channels(scalew(i), 8) + out_channels = _round_channels(scalew(o), 8) + repeats = scaled(n) push!(blocks, invertedresidual(k, in_channels, in_channels * e, out_channels, swish; stride = s, reduction = 4)) - for _ in 1:(repeat - 1) + for _ in 1:(repeats - 1) push!(blocks, invertedresidual(k, out_channels, out_channels * e, out_channels, swish; stride = 1, reduction = 4)) From 01ab049fcf45dd967abc3e3932129a9dcf61854b Mon Sep 17 00:00:00 2001 From: Kyle Daruwalla Date: Wed, 22 Jun 2022 09:01:39 -0400 Subject: [PATCH 12/16] Only test smaller variants on efficient net --- test/convnets.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/convnets.jl b/test/convnets.jl index 654f83160..4606ee459 100644 --- a/test/convnets.jl +++ b/test/convnets.jl @@ -71,7 +71,7 @@ GC.safepoint() GC.gc() @testset "EfficientNet" begin - @testset "EfficientNet($name)" for name in [:b0, :b1, :b2, :b3, :b4, :b5, :b6, :b7, :b8] + @testset "EfficientNet($name)" for name in [:b0, :b1, :b2] #, :b3, :b4, :b5, :b6, :b7, :b8] # preferred image resolution scaling r = Metalhead.efficientnet_global_configs[name][1] x = rand(Float32, r, r, 3, 1) From ea1b92e9c0c298a2b3e7cce9528fb950d2f45c6e Mon Sep 17 00:00:00 2001 From: Kyle Daruwalla Date: Wed, 22 Jun 2022 12:15:49 -0400 Subject: [PATCH 13/16] Adjust testing and use `Chain(::Vector)` --- src/convnets/efficientnet.jl | 2 +- test/other.jl | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/convnets/efficientnet.jl b/src/convnets/efficientnet.jl index be32dfda9..9fe4a5fad 100644 --- a/src/convnets/efficientnet.jl +++ b/src/convnets/efficientnet.jl @@ -53,7 +53,7 @@ function efficientnet(scalings, block_config; top = Dense(head_out_channels, nclasses) - return Chain(Chain(stem..., blocks, head...), + return Chain(Chain([stem..., blocks, head...]), Chain(AdaptiveMeanPool((1, 1)), MLUtils.flatten, top)) end diff --git a/test/other.jl b/test/other.jl index 769539720..3c1752f3a 100644 --- a/test/other.jl +++ b/test/other.jl @@ -1,5 +1,5 @@ @testset "MLPMixer" begin - @testset for mode in [:small, :base, :large] # :huge] + @testset for mode in [:small, :base] # :large, # :huge] @testset for drop_path_rate in [0.0, 0.5] m = MLPMixer(mode; drop_path_rate) @test size(m(x_224)) == (1000, 1) @@ -11,7 +11,7 @@ end @testset "ResMLP" begin - @testset for mode in [:small, :base, :large] # :huge] + @testset for mode in [:small, :base] # :large, # :huge] @testset for drop_path_rate in [0.0, 0.5] m = ResMLP(mode; drop_path_rate) @test size(m(x_224)) == (1000, 1) @@ -23,7 +23,7 @@ end end @testset "gMLP" begin - @testset for mode in [:small, :base, :large] # :huge] + @testset for mode in [:small, :base] # :large, # :huge] @testset for drop_path_rate in [0.0, 0.5] m = gMLP(mode; drop_path_rate) @test size(m(x_224)) == (1000, 1) From b9e238c6bdb928e5230869e55f76c6a71118a502 Mon Sep 17 00:00:00 2001 From: Kyle Daruwalla Date: Wed, 22 Jun 2022 13:34:59 -0400 Subject: [PATCH 14/16] Update test/convnets.jl --- test/convnets.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/convnets.jl b/test/convnets.jl index 4606ee459..654f83160 100644 --- a/test/convnets.jl +++ b/test/convnets.jl @@ -71,7 +71,7 @@ GC.safepoint() GC.gc() @testset "EfficientNet" begin - @testset "EfficientNet($name)" for name in [:b0, :b1, :b2] #, :b3, :b4, :b5, :b6, :b7, :b8] + @testset "EfficientNet($name)" for name in [:b0, :b1, :b2, :b3, :b4, :b5, :b6, :b7, :b8] # preferred image resolution scaling r = Metalhead.efficientnet_global_configs[name][1] x = rand(Float32, r, r, 3, 1) From 7a32bb0e9d728a5fea467415e7a9f4a67f2331a9 Mon Sep 17 00:00:00 2001 From: Kyle Daruwalla Date: Thu, 23 Jun 2022 07:15:41 -0400 Subject: [PATCH 15/16] Adjust ConvNeXt and ConvMixer --- test/convnets.jl | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/convnets.jl b/test/convnets.jl index 654f83160..09f04472d 100644 --- a/test/convnets.jl +++ b/test/convnets.jl @@ -236,7 +236,7 @@ GC.safepoint() GC.gc() @testset "ConvNeXt" verbose = true begin - @testset for mode in [:small, :base, :large] # :tiny, #, :xlarge] + @testset for mode in [:small, :base] #, :large # :tiny, #, :xlarge] @testset for drop_path_rate in [0.0, 0.5] m = ConvNeXt(mode; drop_path_rate) @test size(m(x_224)) == (1000, 1) @@ -251,7 +251,7 @@ GC.safepoint() GC.gc() @testset "ConvMixer" verbose = true begin - @testset for mode in [:small, :base, :large] + @testset for mode in [:small, :base] #, :large] m = ConvMixer(mode) @test size(m(x_224)) == (1000, 1) From a3f44c8fd79498f92c1b03d19aa70d291b7ecaf4 Mon Sep 17 00:00:00 2001 From: Kyle Daruwalla Date: Thu, 23 Jun 2022 07:17:07 -0400 Subject: [PATCH 16/16] Test less for EfficientNet too --- src/convnets/efficientnet.jl | 4 ++-- test/convnets.jl | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/convnets/efficientnet.jl b/src/convnets/efficientnet.jl index 9fe4a5fad..1465eb238 100644 --- a/src/convnets/efficientnet.jl +++ b/src/convnets/efficientnet.jl @@ -13,7 +13,7 @@ Create an EfficientNet model ([reference](https://arxiv.org/abs/1905.11946v5)). - `k`: kernel size - `s`: kernel stride - `e`: expansion ratio - - `i`: block input channels + - `i`: block input channels (will be scaled by global width scaling) - `o`: block output channels (will be scaled by global width scaling) - `inchannels`: number of input channels - `nclasses`: number of output classes @@ -110,7 +110,7 @@ See also [`efficientnet`](#). - `k`: kernel size - `s`: kernel stride - `e`: expansion ratio - - `i`: block input channels + - `i`: block input channels (will be scaled by global width scaling) - `o`: block output channels (will be scaled by global width scaling) - `inchannels`: number of input channels - `nclasses`: number of output classes diff --git a/test/convnets.jl b/test/convnets.jl index 09f04472d..9d1645865 100644 --- a/test/convnets.jl +++ b/test/convnets.jl @@ -71,7 +71,7 @@ GC.safepoint() GC.gc() @testset "EfficientNet" begin - @testset "EfficientNet($name)" for name in [:b0, :b1, :b2, :b3, :b4, :b5, :b6, :b7, :b8] + @testset "EfficientNet($name)" for name in [:b0, :b1, :b2, :b3, :b4] #, :b5, :b6, :b7, :b8] # preferred image resolution scaling r = Metalhead.efficientnet_global_configs[name][1] x = rand(Float32, r, r, 3, 1)