4
4
drop_block = identity, drop_path = identity,
5
5
attn_fn = planes -> identity)
6
6
7
- Creates a basic ResNet block.
7
+ Creates a basic residual block (see [reference](https://arxiv.org/abs/1512.03385v1)) .
8
8
9
9
# Arguments
10
10
11
11
- `inplanes`: number of input feature maps
12
12
- `planes`: number of feature maps for the block
13
13
- `stride`: the stride of the block
14
- - `reduction_factor`: the reduction factor that the input feature maps are reduced by before the first
15
- convolution.
14
+ - `reduction_factor`: the factor by which the input feature maps
15
+ are reduced before the first convolution.
16
16
- `activation`: the activation function to use.
17
17
- `norm_layer`: the normalization layer to use.
18
- - `drop_block`: the drop block layer. This is usually initialised in the `_make_blocks`
19
- function and passed in.
20
- - `drop_path`: the drop path layer. This is usually initialised in the `_make_blocks`
21
- function and passed in.
18
+ - `drop_block`: the drop block layer
19
+ - `drop_path`: the drop path layer
22
20
- `attn_fn`: the attention function to use. See [`squeeze_excite`](#) for an example.
23
21
"""
24
22
function basicblock (inplanes:: Integer , planes:: Integer ; stride:: Integer = 1 ,
@@ -36,7 +34,6 @@ function basicblock(inplanes::Integer, planes::Integer; stride::Integer = 1,
36
34
drop_path]
37
35
return Chain (filter! (!= (identity), layers)... )
38
36
end
39
- expansion_factor (:: typeof (basicblock)) = 1
40
37
41
38
"""
42
39
bottleneck(inplanes, planes; stride = 1, cardinality = 1, base_width = 64,
@@ -45,7 +42,7 @@ expansion_factor(::typeof(basicblock)) = 1
45
42
drop_block = identity, drop_path = identity,
46
43
attn_fn = planes -> identity)
47
44
48
- Creates a bottleneck ResNet block.
45
+ Creates a bottleneck residual block (see [reference](https://arxiv.org/abs/1512.03385v1)) .
49
46
50
47
# Arguments
51
48
@@ -58,10 +55,8 @@ Creates a bottleneck ResNet block.
58
55
convolution.
59
56
- `activation`: the activation function to use.
60
57
- `norm_layer`: the normalization layer to use.
61
- - `drop_block`: the drop block layer. This is usually initialised in the `_make_blocks`
62
- function and passed in.
63
- - `drop_path`: the drop path layer. This is usually initialised in the `_make_blocks`
64
- function and passed in.
58
+ - `drop_block`: the drop block layer
59
+ - `drop_path`: the drop path layer
65
60
- `attn_fn`: the attention function to use. See [`squeeze_excite`](#) for an example.
66
61
"""
67
62
function bottleneck (inplanes:: Integer , planes:: Integer ; stride:: Integer ,
@@ -83,7 +78,6 @@ function bottleneck(inplanes::Integer, planes::Integer; stride::Integer,
83
78
attn_fn (outplanes), drop_path]
84
79
return Chain (filter! (!= (identity), layers)... )
85
80
end
86
- expansion_factor (:: typeof (bottleneck)) = 4
87
81
88
82
# Downsample layer using convolutions.
89
83
function downsample_conv (inplanes:: Integer , outplanes:: Integer ; stride:: Integer = 1 ,
@@ -124,7 +118,7 @@ const shortcut_dict = Dict(:A => (downsample_identity, downsample_identity),
124
118
:D => (downsample_pool, downsample_identity))
125
119
126
120
# Stride for each block in the ResNet model
127
- function get_stride (block_idx :: Integer , stage_idx :: Integer )
121
+ function resnet_stride (stage_idx :: Integer , block_idx :: Integer )
128
122
return (stage_idx == 1 || block_idx != 1 ) ? 1 : 2
129
123
end
130
124
@@ -159,8 +153,7 @@ on how to use this function.
159
153
shows peformance improvements over the `:deep` stem in some cases.
160
154
161
155
- `inchannels`: The number of channels in the input.
162
- - `replace_pool`: Whether to replace the default 3x3 max pooling layer with a
163
- 3x3 convolution with stride 2 and a normalisation layer.
156
+ - `replace_pool`: Set to true to replace the max pooling layers with a 3x3 convolution + normalization with a stride of two.
164
157
- `norm_layer`: The normalisation layer used in the stem.
165
158
- `activation`: The activation function used in the stem.
166
159
"""
270
263
function resnet_stages (get_layers, block_repeats:: Vector{<:Integer} , connection)
271
264
# Construct each stage
272
265
stages = []
273
- for (stage_idx, ( num_blocks) ) in enumerate (block_repeats)
266
+ for (stage_idx, num_blocks) in enumerate (block_repeats)
274
267
# Construct the blocks for each stage
275
268
blocks = [Parallel (connection, get_layers (stage_idx, block_idx)... )
276
269
for block_idx in range (1 , num_blocks)]
@@ -307,6 +300,7 @@ function resnet(block_type::Symbol, block_repeats::Vector{<:Integer};
307
300
stride_fn = get_stride, planes_fn = resnet_planes,
308
301
downsample_tuple = downsample_opt)
309
302
else
303
+ # TODO : write better message when we have link to dev docs for resnet
310
304
throw (ArgumentError (" Unknown block type $block_type " ))
311
305
end
312
306
classifier_fn = nfeatures -> create_classifier (nfeatures, nclasses; dropout_rate,
@@ -318,7 +312,7 @@ function resnet(block_fn, block_repeats, downsample_opt::Symbol = :B; kwargs...)
318
312
return resnet (block_fn, block_repeats, shortcut_dict[downsample_opt]; kwargs... )
319
313
end
320
314
321
- function resnet (img_dims, stem, connection, get_layers, block_repeats:: Vector{<:Integer} ,
315
+ function resnet (img_dims, stem, get_layers, block_repeats:: Vector{<:Integer} , connection ,
322
316
classifier_fn)
323
317
# Build stages of the ResNet
324
318
stage_blocks = resnet_stages (get_layers, block_repeats, connection)
0 commit comments