Skip to content

Commit 51858eb

Browse files
committed
Renaming ir_ to invres_
1 parent da5d3a7 commit 51858eb

File tree

9 files changed

+56
-53
lines changed

9 files changed

+56
-53
lines changed

src/convnets/builders/irmodel.jl renamed to src/convnets/builders/invresmodel.jl

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
1-
function build_irmodel(scalings::NTuple{2, Real}, block_configs::AbstractVector{<:Tuple};
2-
inplanes::Integer = 32, connection = +, activation = relu,
3-
norm_layer = BatchNorm, divisor::Integer = 8, tail_conv::Bool = true,
4-
expanded_classifier::Bool = false, stochastic_depth_prob = nothing,
5-
headplanes::Integer, dropout_prob = nothing, inchannels::Integer = 3,
6-
nclasses::Integer = 1000, kwargs...)
1+
function build_invresmodel(scalings::NTuple{2, Real},
2+
block_configs::AbstractVector{<:Tuple};
3+
inplanes::Integer = 32, connection = +, activation = relu,
4+
norm_layer = BatchNorm, divisor::Integer = 8,
5+
tail_conv::Bool = true, expanded_classifier::Bool = false,
6+
stochastic_depth_prob = nothing, headplanes::Integer,
7+
dropout_prob = nothing, inchannels::Integer = 3,
8+
nclasses::Integer = 1000, kwargs...)
79
width_mult, _ = scalings
810
# building first layer
911
inplanes = _round_channels(inplanes * width_mult, divisor)
@@ -36,6 +38,7 @@ function build_irmodel(scalings::NTuple{2, Real}, block_configs::AbstractVector{
3638
end
3739
return Chain(Chain(layers...), classifier)
3840
end
39-
function build_irmodel(width_mult::Real, block_configs::AbstractVector{<:Tuple}; kwargs...)
40-
return build_irmodel((width_mult, 1), block_configs; kwargs...)
41+
function build_invresmodel(width_mult::Real, block_configs::AbstractVector{<:Tuple};
42+
kwargs...)
43+
return build_invresmodel((width_mult, 1), block_configs; kwargs...)
4144
end

src/convnets/builders/mbconv.jl

Lines changed: 20 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,19 @@
11
"""
2-
irblockbuilder(::typeof(irblockfn), block_configs::AbstractVector{<:Tuple},
2+
invresbuilder(::typeof(irblockfn), block_configs::AbstractVector{<:Tuple},
33
inplanes::Integer, stage_idx::Integer, scalings::NTuple{2, Real};
44
stochastic_depth_prob = nothing, norm_layer = BatchNorm,
55
divisor::Integer = 8, kwargs...)
66
7-
Constructs a collection of inverted residual blocks for a given stage. Note that
8-
this function is not intended to be called directly, but rather by the [`mbconv_stage_builder`](@ref)
9-
function. This function must only be extended if the user wishes to extend a custom inverted
10-
residual block type.
7+
Creates a block builder for `irblockfn` within a given stage.
8+
Note that this function is not intended to be called directly, but instead passed to
9+
[`mbconv_stage_builder`](@ref) which will return a builder over all stages.
10+
Users wanting to provide a custom inverted residual block type can extend this
11+
function by defining `invresbuilder(::typeof(my_block), ...)`.
1112
"""
12-
function irblockbuilder(::typeof(dwsep_conv_norm), block_configs::AbstractVector{<:Tuple},
13-
inplanes::Integer, stage_idx::Integer, scalings::NTuple{2, Real};
14-
stochastic_depth_prob = nothing, norm_layer = BatchNorm,
15-
divisor::Integer = 8, kwargs...)
13+
function invresbuilder(::typeof(dwsep_conv_norm), block_configs::AbstractVector{<:Tuple},
14+
inplanes::Integer, stage_idx::Integer, scalings::NTuple{2, Real};
15+
stochastic_depth_prob = nothing, norm_layer = BatchNorm,
16+
divisor::Integer = 8, kwargs...)
1617
width_mult, depth_mult = scalings
1718
block_fn, k, outplanes, stride, nrepeats, activation = block_configs[stage_idx]
1819
outplanes = _round_channels(outplanes * width_mult, divisor)
@@ -29,10 +30,10 @@ function irblockbuilder(::typeof(dwsep_conv_norm), block_configs::AbstractVector
2930
return get_layers, ceil(Int, nrepeats * depth_mult)
3031
end
3132

32-
function irblockbuilder(::typeof(mbconv), block_configs::AbstractVector{<:Tuple},
33-
inplanes::Integer, stage_idx::Integer, scalings::NTuple{2, Real};
34-
stochastic_depth_prob = nothing, norm_layer = BatchNorm,
35-
divisor::Integer = 8, se_from_explanes::Bool = false, kwargs...)
33+
function invresbuilder(::typeof(mbconv), block_configs::AbstractVector{<:Tuple},
34+
inplanes::Integer, stage_idx::Integer, scalings::NTuple{2, Real};
35+
stochastic_depth_prob = nothing, norm_layer = BatchNorm,
36+
divisor::Integer = 8, se_from_explanes::Bool = false, kwargs...)
3637
width_mult, depth_mult = scalings
3738
block_repeats = [ceil(Int, block_configs[idx][end - 2] * depth_mult)
3839
for idx in eachindex(block_configs)]
@@ -64,10 +65,10 @@ function irblockbuilder(::typeof(mbconv), block_configs::AbstractVector{<:Tuple}
6465
return get_layers, block_repeats[stage_idx]
6566
end
6667

67-
function irblockbuilder(::typeof(fused_mbconv), block_configs::AbstractVector{<:Tuple},
68-
inplanes::Integer, stage_idx::Integer, scalings::NTuple{2, Real};
69-
stochastic_depth_prob = nothing, norm_layer = BatchNorm,
70-
divisor::Integer = 8, kwargs...)
68+
function invresbuilder(::typeof(fused_mbconv), block_configs::AbstractVector{<:Tuple},
69+
inplanes::Integer, stage_idx::Integer, scalings::NTuple{2, Real};
70+
stochastic_depth_prob = nothing, norm_layer = BatchNorm,
71+
divisor::Integer = 8, kwargs...)
7172
width_mult, depth_mult = scalings
7273
block_repeats = [ceil(Int, block_configs[idx][end - 1] * depth_mult)
7374
for idx in eachindex(block_configs)]
@@ -90,7 +91,7 @@ end
9091

9192
function mbconv_stage_builder(block_configs::AbstractVector{<:Tuple}, inplanes::Integer,
9293
scalings::NTuple{2, Real}; kwargs...)
93-
bxs = [irblockbuilder(block_configs[idx][1], block_configs, inplanes, idx, scalings;
94-
kwargs...) for idx in eachindex(block_configs)]
94+
bxs = [invresbuilder(block_configs[idx][1], block_configs, inplanes, idx, scalings;
95+
kwargs...) for idx in eachindex(block_configs)]
9596
return (stage_idx, block_idx) -> first.(bxs)[stage_idx](block_idx), last.(bxs)
9697
end

src/convnets/convnext.jl

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,13 @@ Creates a single block of ConvNeXt.
1212
"""
1313
function convnextblock(planes::Integer, stochastic_depth_prob = 0.0,
1414
layerscale_init = 1.0f-6)
15-
layers = SkipConnection(Chain(DepthwiseConv((7, 7), planes => planes; pad = 3),
16-
swapdims((3, 1, 2, 4)),
17-
LayerNorm(planes; ϵ = 1.0f-6),
18-
mlp_block(planes, 4 * planes),
19-
LayerScale(planes, layerscale_init),
20-
swapdims((2, 3, 1, 4)),
21-
StochasticDepth(stochastic_depth_prob)), +)
22-
return layers
15+
return SkipConnection(Chain(DepthwiseConv((7, 7), planes => planes; pad = 3),
16+
swapdims((3, 1, 2, 4)),
17+
LayerNorm(planes; ϵ = 1.0f-6),
18+
mlp_block(planes, 4 * planes),
19+
LayerScale(planes, layerscale_init),
20+
swapdims((2, 3, 1, 4)),
21+
StochasticDepth(stochastic_depth_prob)), +)
2322
end
2423

2524
"""

src/convnets/efficientnets/efficientnet.jl

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -53,10 +53,10 @@ function efficientnet(config::Symbol; norm_layer = BatchNorm, stochastic_depth_p
5353
nclasses::Integer = 1000)
5454
_checkconfig(config, keys(EFFICIENTNET_GLOBAL_CONFIGS))
5555
scalings = EFFICIENTNET_GLOBAL_CONFIGS[config][2]
56-
return build_irmodel(scalings, EFFICIENTNET_BLOCK_CONFIGS; inplanes = 32,
57-
norm_layer, stochastic_depth_prob, activation = swish,
58-
headplanes = EFFICIENTNET_BLOCK_CONFIGS[end][3] * 4,
59-
dropout_prob, inchannels, nclasses)
56+
return build_invresmodel(scalings, EFFICIENTNET_BLOCK_CONFIGS; inplanes = 32,
57+
norm_layer, stochastic_depth_prob, activation = swish,
58+
headplanes = EFFICIENTNET_BLOCK_CONFIGS[end][3] * 4,
59+
dropout_prob, inchannels, nclasses)
6060
end
6161

6262
"""

src/convnets/efficientnets/efficientnetv2.jl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,9 +57,9 @@ function efficientnetv2(config::Symbol; norm_layer = BatchNorm, stochastic_depth
5757
nclasses::Integer = 1000)
5858
_checkconfig(config, keys(EFFNETV2_CONFIGS))
5959
block_configs = EFFNETV2_CONFIGS[config]
60-
return build_irmodel((1, 1), block_configs; activation = swish, norm_layer,
61-
inplanes = block_configs[1][3], headplanes = 1280,
62-
stochastic_depth_prob, dropout_prob, inchannels, nclasses)
60+
return build_invresmodel((1, 1), block_configs; activation = swish, norm_layer,
61+
inplanes = block_configs[1][3], headplanes = 1280,
62+
stochastic_depth_prob, dropout_prob, inchannels, nclasses)
6363
end
6464

6565
"""

src/convnets/mobilenets/mnasnet.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,8 +63,8 @@ function mnasnet(config::Symbol; width_mult::Real = 1, max_width::Integer = 1280
6363
# momentum used for BatchNorm is as per Tensorflow implementation
6464
norm_layer = (args...; kwargs...) -> BatchNorm(args...; momentum = 0.0003f0, kwargs...)
6565
inplanes, block_configs = MNASNET_CONFIGS[config]
66-
return build_irmodel(width_mult, block_configs; inplanes, norm_layer,
67-
headplanes = max_width, dropout_prob, inchannels, nclasses)
66+
return build_invresmodel(width_mult, block_configs; inplanes, norm_layer,
67+
headplanes = max_width, dropout_prob, inchannels, nclasses)
6868
end
6969

7070
"""

src/convnets/mobilenets/mobilenetv1.jl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,9 @@ Create a MobileNetv1 model. ([reference](https://arxiv.org/abs/1704.04861v1)).
3131
"""
3232
function mobilenetv1(width_mult::Real = 1; inplanes::Integer = 32, dropout_prob = nothing,
3333
inchannels::Integer = 3, nclasses::Integer = 1000)
34-
return build_irmodel(width_mult, MOBILENETV1_CONFIGS; inplanes, inchannels,
35-
activation = relu6, connection = nothing, tail_conv = false,
36-
headplanes = 1024, dropout_prob, nclasses)
34+
return build_invresmodel(width_mult, MOBILENETV1_CONFIGS; inplanes, inchannels,
35+
activation = relu6, connection = nothing, tail_conv = false,
36+
headplanes = 1024, dropout_prob, nclasses)
3737
end
3838

3939
"""

src/convnets/mobilenets/mobilenetv2.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,8 @@ Create a MobileNetv2 model. ([reference](https://arxiv.org/abs/1801.04381v1)).
3838
function mobilenetv2(width_mult::Real = 1; max_width::Integer = 1280,
3939
inplanes::Integer = 32, dropout_prob = 0.2,
4040
inchannels::Integer = 3, nclasses::Integer = 1000)
41-
return build_irmodel(width_mult, MOBILENETV2_CONFIGS; activation = relu6, inplanes,
42-
headplanes = max_width, dropout_prob, inchannels, nclasses)
41+
return build_invresmodel(width_mult, MOBILENETV2_CONFIGS; activation = relu6, inplanes,
42+
headplanes = max_width, dropout_prob, inchannels, nclasses)
4343
end
4444

4545
"""

src/convnets/mobilenets/mobilenetv3.jl

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -54,10 +54,10 @@ function mobilenetv3(config::Symbol; width_mult::Real = 1, dropout_prob = 0.2,
5454
inchannels::Integer = 3, nclasses::Integer = 1000)
5555
_checkconfig(config, [:small, :large])
5656
max_width, block_configs = MOBILENETV3_CONFIGS[config]
57-
return build_irmodel(width_mult, block_configs; inplanes = 16,
58-
headplanes = max_width, activation = relu,
59-
se_from_explanes = true, se_round_fn = _round_channels,
60-
expanded_classifier = true, dropout_prob, inchannels, nclasses)
57+
return build_invresmodel(width_mult, block_configs; inplanes = 16,
58+
headplanes = max_width, activation = relu,
59+
se_from_explanes = true, se_round_fn = _round_channels,
60+
expanded_classifier = true, dropout_prob, inchannels, nclasses)
6161
end
6262

6363
"""

0 commit comments

Comments
 (0)