Skip to content

Commit 1e78c3c

Browse files
committed
Fix backbone
1 parent 91cd788 commit 1e78c3c

File tree

6 files changed

+24
-30
lines changed

6 files changed

+24
-30
lines changed

src/convnets/convmixer.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ function convmixer(planes, depth; inchannels = 3, kernel_size = (9, 9),
2121
preact = true, groups = planes, pad = SamePad()), +),
2222
conv_bn((1, 1), planes, planes, activation; preact = true)) for _ in 1:depth]
2323
head = Chain(AdaptiveMeanPool((1, 1)), MLUtils.flatten, Dense(planes, nclasses))
24-
return Chain(stem, Chain(blocks), head)
24+
return Chain(Chain(stem, Chain(blocks)), head)
2525
end
2626

2727
convmixer_config = Dict(:base => Dict(:planes => 1536, :depth => 20, :kernel_size => (9, 9),

src/convnets/densenet.jl

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,7 @@ Create a DenseNet transition sequence
2828
- `outplanes`: number of output feature maps
2929
"""
3030
transition(inplanes, outplanes) =
31-
Chain(conv_bn((1, 1), inplanes, outplanes; bias = false, rev = true),
32-
MeanPool((2, 2)))
31+
Chain(conv_bn((1, 1), inplanes, outplanes; bias = false, rev = true), MeanPool((2, 2)))
3332

3433
"""
3534
dense_block(inplanes, growth_rates)
@@ -68,8 +67,8 @@ function densenet(inplanes, growth_rates; reduction = 0.5, nclasses = 1000)
6867
for (i, rates) in enumerate(growth_rates)
6968
outplanes = inplanes + sum(rates)
7069
append!(layers, dense_block(inplanes, rates))
71-
(i != length(growth_rates)) &&
72-
append!(layers, transition(outplanes, floor(Int, outplanes * reduction)))
70+
(i != length(growth_rates)) &&
71+
push!(layers, transition(outplanes, floor(Int, outplanes * reduction)))
7372
inplanes = floor(Int, outplanes * reduction)
7473
end
7574
push!(layers, BatchNorm(outplanes, relu))

src/convnets/mobilenet.jl

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -31,12 +31,10 @@ function mobilenetv1(width_mult, config;
3131
for (dw, outch, stride, repeats) in config
3232
outch = Int(outch * width_mult)
3333
for _ in 1:repeats
34-
layer = if dw
35-
depthwise_sep_conv_bn((3, 3), inchannels, outch, activation; stride = stride, pad = 1)
36-
else
37-
conv_bn((3, 3), inchannels, outch, activation; stride = stride, pad = 1)
38-
end
39-
append!(layers, layer)
34+
layer = dw ? depthwise_sep_conv_bn((3, 3), inchannels, outch, activation;
35+
stride = stride, pad = 1) :
36+
conv_bn((3, 3), inchannels, outch, activation; stride = stride, pad = 1)
37+
push!(layers, layer)
4038
inchannels = outch
4139
end
4240
end
@@ -120,7 +118,7 @@ function mobilenetv2(width_mult, configs; max_width = 1280, nclasses = 1000)
120118
# building first layer
121119
inplanes = _round_channels(32 * width_mult, width_mult == 0.1 ? 4 : 8)
122120
layers = []
123-
append!(layers, conv_bn((3, 3), 3, inplanes, stride = 2))
121+
push!(layers, conv_bn((3, 3), 3, inplanes, stride = 2))
124122

125123
# building inverted residual blocks
126124
for (t, c, n, s, a) in configs
@@ -136,7 +134,7 @@ function mobilenetv2(width_mult, configs; max_width = 1280, nclasses = 1000)
136134
outplanes = (width_mult > 1) ? _round_channels(max_width * width_mult, width_mult == 0.1 ? 4 : 8) :
137135
max_width
138136

139-
return Chain(Chain(layers), conv_bn((1, 1), inplanes, outplanes, relu6, bias = false),
137+
return Chain(Chain(Chain(layers), conv_bn((1, 1), inplanes, outplanes, relu6, bias = false)),
140138
Chain(AdaptiveMeanPool((1, 1)), MLUtils.flatten, Dense(outplanes, nclasses)))
141139
end
142140

@@ -185,7 +183,7 @@ end
185183
(m::MobileNetv2)(x) = m.layers(x)
186184

187185
backbone(m::MobileNetv2) = m.layers[1]
188-
classifier(m::MobileNetv2) = m.layers[2:end]
186+
classifier(m::MobileNetv2) = m.layers[2]
189187

190188
# MobileNetv3
191189

@@ -213,7 +211,7 @@ function mobilenetv3(width_mult, configs; max_width = 1024, nclasses = 1000)
213211
# building first layer
214212
inplanes = _round_channels(16 * width_mult, 8)
215213
layers = []
216-
append!(layers, conv_bn((3, 3), 3, inplanes, hardswish; stride = 2))
214+
push!(layers, conv_bn((3, 3), 3, inplanes, hardswish; stride = 2))
217215
explanes = 0
218216
# building inverted residual blocks
219217
for (k, t, c, r, a, s) in configs
@@ -232,7 +230,7 @@ function mobilenetv3(width_mult, configs; max_width = 1024, nclasses = 1000)
232230
Dropout(0.2),
233231
Dense(output_channel, nclasses))
234232

235-
return Chain(Chain(layers), conv_bn((1, 1), inplanes, explanes, hardswish, bias = false),
233+
return Chain(Chain(Chain(layers), conv_bn((1, 1), inplanes, explanes, hardswish, bias = false)),
236234
Chain(AdaptiveMeanPool((1, 1)), MLUtils.flatten, classifier))
237235
end
238236

@@ -308,4 +306,4 @@ end
308306
(m::MobileNetv3)(x) = m.layers(x)
309307

310308
backbone(m::MobileNetv3) = m.layers[1]
311-
classifier(m::MobileNetv3) = m.layers[2:end]
309+
classifier(m::MobileNetv3) = m.layers[2]

src/convnets/resnet.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ function resnet(block, residuals::AbstractVector{<:NTuple{2, Any}}, connection =
8282
inplanes = 64
8383
baseplanes = 64
8484
layers = []
85-
append!(layers, conv_bn((7, 7), 3, inplanes; stride = 2, pad = 3, bias = false))
85+
push!(layers, conv_bn((7, 7), 3, inplanes; stride = 2, pad = 3, bias = false))
8686
push!(layers, MaxPool((3, 3), stride = (2, 2), pad = (1, 1)))
8787
for (i, nrepeats) in enumerate(block_config)
8888
# output planes within a block

src/convnets/resnext.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ function resnext(cardinality, width, widen_factor = 2, connection = (x, y) -> @.
4040
inplanes = 64
4141
baseplanes = 128
4242
layers = []
43-
append!(layers, conv_bn((7, 7), 3, inplanes; stride = 2, pad = (3, 3)))
43+
push!(layers, conv_bn((7, 7), 3, inplanes; stride = 2, pad = (3, 3)))
4444
push!(layers, MaxPool((3, 3), stride = (2, 2), pad = (1, 1)))
4545
for (i, nrepeats) in enumerate(block_config)
4646
# output planes within a block

src/convnets/vgg.jl

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ function vgg_block(ifilters, ofilters, depth, batchnorm)
1616
layers = []
1717
for _ in 1:depth
1818
if batchnorm
19-
append!(layers, conv_bn(k, ifilters, ofilters; pad = p, bias = false))
19+
push!(layers, conv_bn(k, ifilters, ofilters; pad = p, bias = false))
2020
else
2121
push!(layers, Conv(k, ifilters => ofilters, relu, pad = p))
2222
end
@@ -62,15 +62,12 @@ Create VGG classifier (fully connected) layers
6262
- `dropout`: the dropout level between each fully connected layer
6363
"""
6464
function vgg_classifier_layers(imsize, nclasses, fcsize, dropout)
65-
layers = []
66-
push!(layers, MLUtils.flatten)
67-
push!(layers, Dense(Int(prod(imsize)), fcsize, relu))
68-
push!(layers, Dropout(dropout))
69-
push!(layers, Dense(fcsize, fcsize, relu))
70-
push!(layers, Dropout(dropout))
71-
push!(layers, Dense(fcsize, nclasses))
72-
73-
return layers
65+
return Chain(MLUtils.flatten,
66+
Dense(Int(prod(imsize)), fcsize, relu),
67+
Dropout(dropout),
68+
Dense(fcsize, fcsize, relu),
69+
Dropout(dropout),
70+
Dense(fcsize, nclasses))
7471
end
7572

7673
"""
@@ -94,7 +91,7 @@ function vgg(imsize; config, inchannels, batchnorm = false, nclasses, fcsize, dr
9491
conv = vgg_convolutional_layers(config, batchnorm, inchannels)
9592
imsize = outputsize(conv, (imsize..., inchannels); padbatch = true)[1:3]
9693
class = vgg_classifier_layers(imsize, nclasses, fcsize, dropout)
97-
return Chain(Chain(conv), Chain(class))
94+
return Chain(Chain(conv), class)
9895
end
9996

10097
const vgg_conv_config = Dict(:A => [(64,1), (128,1), (256,2), (512,2), (512,2)],

0 commit comments

Comments
 (0)