@@ -6,19 +6,21 @@ Create an EfficientNet model ([reference](https://arxiv.org/abs/1905.11946v5)).
6
6
7
7
# Arguments
8
8
9
- - `scalings`: global width and depth scaling (given as a tuple)
10
- - `block_config`: configuration for each inverted residual block,
11
- given as a vector of tuples with elements:
12
- - `n`: number of block repetitions (will be scaled by global depth scaling)
13
- - `k`: kernel size
14
- - `s`: kernel stride
15
- - `e`: expansion ratio
16
- - `i`: block input channels (will be scaled by global width scaling)
17
- - `o`: block output channels (will be scaled by global width scaling)
18
- - `inchannels`: number of input channels
19
- - `nclasses`: number of output classes
20
- - `max_width`: maximum number of output channels before the fully connected
21
- classification blocks
9
+ - `scalings`: global width and depth scaling (given as a tuple)
10
+
11
+ - `block_config`: configuration for each inverted residual block,
12
+ given as a vector of tuples with elements:
13
+
14
+ + `n`: number of block repetitions (will be scaled by global depth scaling)
15
+ + `k`: kernel size
16
+ + `s`: kernel stride
17
+ + `e`: expansion ratio
18
+ + `i`: block input channels (will be scaled by global width scaling)
19
+ + `o`: block output channels (will be scaled by global width scaling)
20
+ - `inchannels`: number of input channels
21
+ - `nclasses`: number of output classes
22
+ - `max_width`: maximum number of output channels before the fully connected
23
+ classification blocks
22
24
"""
23
25
function efficientnet (scalings, block_config;
24
26
inchannels = 3 , nclasses = 1000 , max_width = 1280 )
64
66
# i: block input channels
65
67
# o: block output channels
66
68
const efficientnet_block_configs = [
67
- # (n, k, s, e, i, o)
68
- (1 , 3 , 1 , 1 , 32 , 16 ),
69
- (2 , 3 , 2 , 6 , 16 , 24 ),
70
- (2 , 5 , 2 , 6 , 24 , 40 ),
71
- (3 , 3 , 2 , 6 , 40 , 80 ),
72
- (3 , 5 , 1 , 6 , 80 , 112 ),
69
+ # (n, k, s, e, i, o)
70
+ (1 , 3 , 1 , 1 , 32 , 16 ),
71
+ (2 , 3 , 2 , 6 , 16 , 24 ),
72
+ (2 , 5 , 2 , 6 , 24 , 40 ),
73
+ (3 , 3 , 2 , 6 , 40 , 80 ),
74
+ (3 , 5 , 1 , 6 , 80 , 112 ),
73
75
(4 , 5 , 2 , 6 , 112 , 192 ),
74
- (1 , 3 , 1 , 6 , 192 , 320 )
76
+ (1 , 3 , 1 , 6 , 192 , 320 ),
75
77
]
76
78
77
79
# w: width scaling
78
80
# d: depth scaling
79
81
# r: image resolution
80
82
const efficientnet_global_configs = Dict (
81
- # ( r, ( w, d))
82
- :b0 => (224 , (1.0 , 1.0 )),
83
- :b1 => (240 , (1.0 , 1.1 )),
84
- :b2 => (260 , (1.1 , 1.2 )),
85
- :b3 => (300 , (1.2 , 1.4 )),
86
- :b4 => (380 , (1.4 , 1.8 )),
87
- :b5 => (456 , (1.6 , 2.2 )),
88
- :b6 => (528 , (1.8 , 2.6 )),
89
- :b7 => (600 , (2.0 , 3.1 )),
90
- :b8 => (672 , (2.2 , 3.6 ))
91
- )
83
+ # (r, (w, d))
84
+ :b0 => (224 , (1.0 , 1.0 )),
85
+ :b1 => (240 , (1.0 , 1.1 )),
86
+ :b2 => (260 , (1.1 , 1.2 )),
87
+ :b3 => (300 , (1.2 , 1.4 )),
88
+ :b4 => (380 , (1.4 , 1.8 )),
89
+ :b5 => (456 , (1.6 , 2.2 )),
90
+ :b6 => (528 , (1.8 , 2.6 )),
91
+ :b7 => (600 , (2.0 , 3.1 )),
92
+ :b8 => (672 , (2.2 , 3.6 )))
92
93
93
94
struct EfficientNet
94
- layers:: Any
95
+ layers:: Any
95
96
end
96
97
97
98
"""
@@ -103,27 +104,29 @@ See also [`efficientnet`](#).
103
104
104
105
# Arguments
105
106
106
- - `scalings`: global width and depth scaling (given as a tuple)
107
- - `block_config`: configuration for each inverted residual block,
108
- given as a vector of tuples with elements:
109
- - `n`: number of block repetitions (will be scaled by global depth scaling)
110
- - `k`: kernel size
111
- - `s`: kernel stride
112
- - `e`: expansion ratio
113
- - `i`: block input channels (will be scaled by global width scaling)
114
- - `o`: block output channels (will be scaled by global width scaling)
115
- - `inchannels`: number of input channels
116
- - `nclasses`: number of output classes
117
- - `max_width`: maximum number of output channels before the fully connected
118
- classification blocks
107
+ - `scalings`: global width and depth scaling (given as a tuple)
108
+
109
+ - `block_config`: configuration for each inverted residual block,
110
+ given as a vector of tuples with elements:
111
+
112
+ + `n`: number of block repetitions (will be scaled by global depth scaling)
113
+ + `k`: kernel size
114
+ + `s`: kernel stride
115
+ + `e`: expansion ratio
116
+ + `i`: block input channels (will be scaled by global width scaling)
117
+ + `o`: block output channels (will be scaled by global width scaling)
118
+ - `inchannels`: number of input channels
119
+ - `nclasses`: number of output classes
120
+ - `max_width`: maximum number of output channels before the fully connected
121
+ classification blocks
119
122
"""
120
123
function EfficientNet (scalings, block_config;
121
124
inchannels = 3 , nclasses = 1000 , max_width = 1280 )
122
- layers = efficientnet (scalings, block_config;
123
- inchannels = inchannels,
124
- nclasses = nclasses,
125
- max_width = max_width)
126
- return EfficientNet (layers)
125
+ layers = efficientnet (scalings, block_config;
126
+ inchannels = inchannels,
127
+ nclasses = nclasses,
128
+ max_width = max_width)
129
+ return EfficientNet (layers)
127
130
end
128
131
129
132
@functor EfficientNet
@@ -141,13 +144,13 @@ See also [`efficientnet`](#).
141
144
142
145
# Arguments
143
146
144
- - `name`: name of default configuration
145
- (can be `:b0`, `:b1`, `:b2`, `:b3`, `:b4`, `:b5`, `:b6`, `:b7`, `:b8`)
146
- - `pretrain`: set to `true` to load the pre-trained weights for ImageNet
147
+ - `name`: name of default configuration
148
+ (can be `:b0`, `:b1`, `:b2`, `:b3`, `:b4`, `:b5`, `:b6`, `:b7`, `:b8`)
149
+ - `pretrain`: set to `true` to load the pre-trained weights for ImageNet
147
150
"""
148
151
function EfficientNet (name:: Symbol ; pretrain = false )
149
152
@assert name in keys (efficientnet_global_configs)
150
- " `name` must be one of $(sort (collect (keys (efficientnet_global_configs)))) "
153
+ " `name` must be one of $(sort (collect (keys (efficientnet_global_configs)))) "
151
154
152
155
model = EfficientNet (efficientnet_global_configs[name][2 ], efficientnet_block_configs)
153
156
pretrain && loadpretrain! (model, string (" efficientnet-" , name))
0 commit comments