Skip to content

Commit 992f6a6

Browse files
committed
_round_channels all the way
And `max_width` doesn't get width scaled
1 parent f76fadb commit 992f6a6

File tree

4 files changed

+8
-9
lines changed

4 files changed

+8
-9
lines changed

src/convnets/builders/mbconv.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
function dwsepconv_builder(block_configs, inplanes::Integer, stage_idx::Integer,
22
width_mult::Real; norm_layer = BatchNorm, kwargs...)
33
block_fn, k, outplanes, stride, nrepeats, activation = block_configs[stage_idx]
4-
outplanes = floor(Int, outplanes * width_mult)
4+
outplanes = _round_channels(outplanes * width_mult)
55
if stage_idx != 1
6-
inplanes = floor(Int, block_configs[stage_idx - 1][3] * width_mult)
6+
inplanes = _round_channels(block_configs[stage_idx - 1][3] * width_mult)
77
end
88
function get_layers(block_idx::Integer)
99
inplanes = block_idx == 1 ? inplanes : outplanes

src/convnets/mobilenets/mnasnet.jl

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,9 @@ function mnasnet(block_configs::AbstractVector{<:Tuple}; width_mult::Real = 1,
3636
append!(layers, cnn_stages(get_layers, block_repeats, +))
3737
# building last layers
3838
outplanes = _round_channels(block_configs[end][3] * width_mult)
39-
headplanes = _round_channels(max_width * max(1, width_mult))
4039
append!(layers,
41-
conv_norm((1, 1), outplanes, headplanes, relu; norm_layer))
42-
return Chain(Chain(layers...), create_classifier(headplanes, nclasses; dropout_rate))
40+
conv_norm((1, 1), outplanes, max_width, relu; norm_layer))
41+
return Chain(Chain(layers...), create_classifier(max_width, nclasses; dropout_rate))
4342
end
4443

4544
# Layer configurations for MNasNet
@@ -115,7 +114,7 @@ function MNASNet(config::Symbol; width_mult::Real = 1, pretrain::Bool = false,
115114
inplanes, block_configs = MNASNET_CONFIGS[config]
116115
layers = mnasnet(block_configs; width_mult, inplanes, inchannels, nclasses)
117116
if pretrain
118-
load_pretrained!(layers, "mnasnet$(width_mult)")
117+
loadpretrain!(layers, "mnasnet$(width_mult)")
119118
end
120119
return MNASNet(layers)
121120
end

src/convnets/mobilenets/mobilenetv1.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,13 @@ function mobilenetv1(config::AbstractVector{<:Tuple}; width_mult::Real = 1,
2727
nclasses::Integer = 1000)
2828
layers = []
2929
# stem of the model
30-
inplanes = floor(Int, inplanes * width_mult)
30+
inplanes = _round_channels(inplanes * width_mult)
3131
append!(layers,
3232
conv_norm((3, 3), inchannels, inplanes, activation; stride = 2, pad = 1))
3333
# building inverted residual blocks
3434
get_layers, block_repeats = mbconv_stack_builder(config, inplanes; width_mult)
3535
append!(layers, cnn_stages(get_layers, block_repeats))
36-
outplanes = floor(Int, config[end][3] * width_mult)
36+
outplanes = _round_channels(config[end][3] * width_mult)
3737
return Chain(Chain(layers...), create_classifier(outplanes, nclasses; dropout_rate))
3838
end
3939

src/convnets/mobilenets/mobilenetv2.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ function mobilenetv2(block_configs::AbstractVector{<:Tuple}; width_mult::Real =
4444
end
4545

4646
# Layer configurations for MobileNetv2
47-
# f: block function - we use `dwsep_conv_bn` for the first block and `mbconv` for the rest
47+
# f: block function - we use `mbconv` for all blocks
4848
# k: kernel size
4949
# c: output channels
5050
# e: expansion factor

0 commit comments

Comments
 (0)