Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name = "Metalhead"
uuid = "dbeba491-748d-5e0e-a39e-b530a07fa0cc"
version = "0.7.2"
version = "0.7.3-DEV"

[deps]
Artifacts = "56f22d72-fd6d-98f1-02f0-08ddc0907c33"
Expand Down
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@
| [VGG](https://arxiv.org/abs/1409.1556) | [`VGG`](https://fluxml.ai/Metalhead.jl/dev/docstrings/Metalhead.VGG.html) | N |
| [ResNet](https://arxiv.org/abs/1512.03385) | [`ResNet`](https://fluxml.ai/Metalhead.jl/dev/docstrings/Metalhead.ResNet.html) | N |
| [GoogLeNet](https://arxiv.org/abs/1409.4842) | [`GoogLeNet`](https://fluxml.ai/Metalhead.jl/dev/docstrings/Metalhead.GoogLeNet.html) | N |
| [Inception-v3](https://arxiv.org/abs/1512.00567) | [`Inception3`](https://fluxml.ai/Metalhead.jl/dev/docstrings/Metalhead.Inception3.html) | N |
| [Inception-v3](https://arxiv.org/abs/1512.00567) | [`Inceptionv3`](https://fluxml.ai/Metalhead.jl/dev/docstrings/Metalhead.Inceptionv3.html) | N |
| [Inception-v4](https://arxiv.org/abs/1602.07261) | [`Inceptionv4`](https://fluxml.ai/Metalhead.jl/dev/docstrings/Metalhead.Inceptionv4.html) | N |
| [InceptionResNet-v2](https://arxiv.org/abs/1602.07261) | [`Inceptionv3`](https://fluxml.ai/Metalhead.jl/dev/docstrings/Metalhead.InceptionResNetv2.html) | N |
| [SqueezeNet](https://arxiv.org/abs/1602.07360) | [`SqueezeNet`](https://fluxml.ai/Metalhead.jl/dev/docstrings/Metalhead.SqueezeNet.html) | N |
| [DenseNet](https://arxiv.org/abs/1608.06993) | [`DenseNet`](https://fluxml.ai/Metalhead.jl/dev/docstrings/Metalhead.DenseNet.html) | N |
| [ResNeXt](https://arxiv.org/abs/1611.05431) | [`ResNeXt`](https://fluxml.ai/Metalhead.jl/dev/docstrings/Metalhead.ResNeXt.html) | N |
Expand Down
22 changes: 10 additions & 12 deletions src/Metalhead.jl
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
module Metalhead

using Flux
using Flux: outputsize, Zygote
using Flux: Zygote, outputsize
using Functors
using BSON
using Artifacts, LazyArtifacts
Expand Down Expand Up @@ -37,22 +37,20 @@ include("vit-based/vit.jl")

include("pretrain.jl")

export AlexNet,
VGG, VGG11, VGG13, VGG16, VGG19,
ResNet, ResNet18, ResNet34, ResNet50, ResNet101, ResNet152,
GoogLeNet, Inception3, SqueezeNet,
export AlexNet, VGG, VGG11, VGG13, VGG16, VGG19,
ResNet, ResNet18, ResNet34, ResNet50, ResNet101, ResNet152, ResNeXt,
DenseNet, DenseNet121, DenseNet161, DenseNet169, DenseNet201,
ResNeXt,
MobileNetv1, MobileNetv2, MobileNetv3,
GoogLeNet, Inception3, Inceptionv3, Inceptionv4, InceptionResNetv2, Xception,
SqueezeNet, MobileNetv1, MobileNetv2, MobileNetv3,
MLPMixer, ResMLP, gMLP,
ViT,
ConvNeXt, ConvMixer
ConvMixer, ConvNeXt

# use Flux._big_show to pretty print large models
for T in (:AlexNet, :VGG, :ResNet, :GoogLeNet, :Inception3, :SqueezeNet, :DenseNet,
:ResNeXt,
:MobileNetv1, :MobileNetv2, :MobileNetv3,
:MLPMixer, :ResMLP, :gMLP, :ViT, :ConvNeXt, :ConvMixer)
for T in (:AlexNet, :VGG, :ResNet, :ResNeXt, :DenseNet,
:GoogLeNet, :Inceptionv3, :Inceptionv4, :InceptionResNetv2, :Xception,
:SqueezeNet, :MobileNetv1, :MobileNetv2, :MobileNetv3,
:MLPMixer, :ResMLP, :gMLP, :ViT, :ConvMixer, :ConvNeXt)
@eval Base.show(io::IO, ::MIME"text/plain", model::$T) = _maybe_big_show(io, model)
end

Expand Down
20 changes: 5 additions & 15 deletions src/convnets/densenet.jl
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@ Create a Densenet bottleneck layer
"""
function dense_bottleneck(inplanes, outplanes)
inner_channels = 4 * outplanes
m = Chain(conv_bn((1, 1), inplanes, inner_channels; bias = false, rev = true)...,
conv_bn((3, 3), inner_channels, outplanes; pad = 1, bias = false,
rev = true)...)

return SkipConnection(m, cat_channels)
return SkipConnection(Chain(conv_bn((1, 1), inplanes, inner_channels; bias = false,
rev = true)...,
conv_bn((3, 3), inner_channels, outplanes; pad = 1,
bias = false, rev = true)...),
cat_channels)
end

"""
Expand Down Expand Up @@ -72,7 +72,6 @@ function densenet(inplanes, growth_rates; reduction = 0.5, nclasses = 1000)
layers = []
append!(layers, conv_bn((7, 7), 3, inplanes; stride = 2, pad = (3, 3), bias = false))
push!(layers, MaxPool((3, 3); stride = 2, pad = (1, 1)))

outplanes = 0
for (i, rates) in enumerate(growth_rates)
outplanes = inplanes + sum(rates)
Expand All @@ -82,7 +81,6 @@ function densenet(inplanes, growth_rates; reduction = 0.5, nclasses = 1000)
inplanes = floor(Int, outplanes * reduction)
end
push!(layers, BatchNorm(outplanes, relu))

return Chain(Chain(layers),
Chain(AdaptiveMeanPool((1, 1)),
MLUtils.flatten,
Expand Down Expand Up @@ -131,7 +129,6 @@ function DenseNet(nblocks::NTuple{N, <:Integer};
layers = densenet(nblocks; growth_rate = growth_rate,
reduction = reduction,
nclasses = nclasses)

return DenseNet(layers)
end

Expand Down Expand Up @@ -164,13 +161,6 @@ See also [`Metalhead.densenet`](#).
function DenseNet(config::Integer = 121; pretrain = false, nclasses = 1000)
@assert config in keys(densenet_config) "`config` must be one out of $(sort(collect(keys(densenet_config))))."
model = DenseNet(densenet_config[config]; nclasses = nclasses)

pretrain && loadpretrain!(model, string("DenseNet", config))
return model
end

# deprecations
@deprecate DenseNet121(; kw...) DenseNet(121; kw...)
@deprecate DenseNet161(; kw...) DenseNet(161; kw...)
@deprecate DenseNet169(; kw...) DenseNet(169; kw...)
@deprecate DenseNet201(; kw...) DenseNet(201; kw...)
Loading