@@ -52,19 +52,22 @@ def _cfg(url='', **kwargs):
52
52
'mnasnet_100' : _cfg (
53
53
url = 'https://github.com/rwightman/pytorch-image-models/releases/download/v0.1-weights/mnasnet_b1-74cb7081.pth' ),
54
54
'mnasnet_140' : _cfg (url = '' ),
55
+
55
56
'semnasnet_050' : _cfg (url = '' ),
56
57
'semnasnet_075' : _cfg (url = '' ),
57
58
'semnasnet_100' : _cfg (
58
59
url = 'https://github.com/rwightman/pytorch-image-models/releases/download/v0.1-weights/mnasnet_a1-d9418771.pth' ),
59
60
'semnasnet_140' : _cfg (url = '' ),
60
61
'mnasnet_small' : _cfg (url = '' ),
62
+
61
63
'mobilenetv2_100' : _cfg (url = '' ),
62
64
'fbnetc_100' : _cfg (
63
65
url = 'https://github.com/rwightman/pytorch-image-models/releases/download/v0.1-weights/fbnetc_100-c345b898.pth' ,
64
66
interpolation = 'bilinear' ),
65
67
'spnasnet_100' : _cfg (
66
68
url = 'https://github.com/rwightman/pytorch-image-models/releases/download/v0.1-weights/spnasnet_100-048bc3f4.pth' ,
67
69
interpolation = 'bilinear' ),
70
+
68
71
'efficientnet_b0' : _cfg (
69
72
url = 'https://github.com/rwightman/pytorch-image-models/releases/download/v0.1-weights/efficientnet_b0_ra-3dd342df.pth' ),
70
73
'efficientnet_b1' : _cfg (
@@ -94,15 +97,32 @@ def _cfg(url='', **kwargs):
94
97
url = '' , input_size = (3 , 672 , 672 ), pool_size = (21 , 21 ), crop_pct = 0.954 ),
95
98
'efficientnet_l2' : _cfg (
96
99
url = '' , input_size = (3 , 800 , 800 ), pool_size = (25 , 25 ), crop_pct = 0.961 ),
100
+
97
101
'efficientnet_es' : _cfg (
98
102
url = 'https://github.com/rwightman/pytorch-image-models/releases/download/v0.1-weights/efficientnet_es_ra-f111e99c.pth' ),
99
103
'efficientnet_em' : _cfg (
100
104
url = '' , input_size = (3 , 240 , 240 ), pool_size = (8 , 8 ), crop_pct = 0.882 ),
101
105
'efficientnet_el' : _cfg (
102
106
url = '' , input_size = (3 , 300 , 300 ), pool_size = (10 , 10 ), crop_pct = 0.904 ),
107
+
103
108
'efficientnet_cc_b0_4e' : _cfg (url = '' ),
104
109
'efficientnet_cc_b0_8e' : _cfg (url = '' ),
105
110
'efficientnet_cc_b1_8e' : _cfg (url = '' , input_size = (3 , 240 , 240 ), pool_size = (8 , 8 ), crop_pct = 0.882 ),
111
+
112
+ 'efficientnet_lite0' : _cfg (
113
+ url = '' ),
114
+ 'efficientnet_lite1' : _cfg (
115
+ url = '' ,
116
+ input_size = (3 , 240 , 240 ), pool_size = (8 , 8 ), crop_pct = 0.882 ),
117
+ 'efficientnet_lite2' : _cfg (
118
+ url = '' ,
119
+ input_size = (3 , 260 , 260 ), pool_size = (9 , 9 ), crop_pct = 0.890 ),
120
+ 'efficientnet_lite3' : _cfg (
121
+ url = '' ,
122
+ input_size = (3 , 300 , 300 ), pool_size = (10 , 10 ), crop_pct = 0.904 ),
123
+ 'efficientnet_lite4' : _cfg (
124
+ url = '' , input_size = (3 , 380 , 380 ), pool_size = (12 , 12 ), crop_pct = 0.922 ),
125
+
106
126
'tf_efficientnet_b0' : _cfg (
107
127
url = 'https://github.com/rwightman/pytorch-image-models/releases/download/v0.1-weights/tf_efficientnet_b0_aa-827b6e33.pth' ,
108
128
input_size = (3 , 224 , 224 )),
@@ -130,6 +150,7 @@ def _cfg(url='', **kwargs):
130
150
'tf_efficientnet_b8' : _cfg (
131
151
url = 'https://github.com/rwightman/pytorch-image-models/releases/download/v0.1-weights/tf_efficientnet_b8_ra-572d5dd9.pth' ,
132
152
input_size = (3 , 672 , 672 ), pool_size = (21 , 21 ), crop_pct = 0.954 ),
153
+
133
154
'tf_efficientnet_b0_ap' : _cfg (
134
155
url = 'https://github.com/rwightman/pytorch-image-models/releases/download/v0.1-weights/tf_efficientnet_b0_ap-f262efe1.pth' ,
135
156
mean = IMAGENET_INCEPTION_MEAN , std = IMAGENET_INCEPTION_STD , input_size = (3 , 224 , 224 )),
@@ -165,6 +186,7 @@ def _cfg(url='', **kwargs):
165
186
url = 'https://github.com/rwightman/pytorch-image-models/releases/download/v0.1-weights/tf_efficientnet_b8_ap-00e169fa.pth' ,
166
187
mean = IMAGENET_INCEPTION_MEAN , std = IMAGENET_INCEPTION_STD ,
167
188
input_size = (3 , 672 , 672 ), pool_size = (21 , 21 ), crop_pct = 0.954 ),
189
+
168
190
'tf_efficientnet_b0_ns' : _cfg (
169
191
url = 'https://github.com/rwightman/pytorch-image-models/releases/download/v0.1-weights/tf_efficientnet_b0_ns-c0e6a31c.pth' ,
170
192
input_size = (3 , 224 , 224 )),
@@ -195,6 +217,7 @@ def _cfg(url='', **kwargs):
195
217
'tf_efficientnet_l2_ns' : _cfg (
196
218
url = 'https://github.com/rwightman/pytorch-image-models/releases/download/v0.1-weights/tf_efficientnet_l2_ns-df73bb44.pth' ,
197
219
input_size = (3 , 800 , 800 ), pool_size = (25 , 25 ), crop_pct = 0.96 ),
220
+
198
221
'tf_efficientnet_es' : _cfg (
199
222
url = 'https://github.com/rwightman/pytorch-image-models/releases/download/v0.1-weights/tf_efficientnet_es-ca1afbfe.pth' ,
200
223
mean = (0.5 , 0.5 , 0.5 ), std = (0.5 , 0.5 , 0.5 ),
@@ -207,6 +230,7 @@ def _cfg(url='', **kwargs):
207
230
url = 'https://github.com/rwightman/pytorch-image-models/releases/download/v0.1-weights/tf_efficientnet_el-5143854e.pth' ,
208
231
mean = (0.5 , 0.5 , 0.5 ), std = (0.5 , 0.5 , 0.5 ),
209
232
input_size = (3 , 300 , 300 ), pool_size = (10 , 10 ), crop_pct = 0.904 ),
233
+
210
234
'tf_efficientnet_cc_b0_4e' : _cfg (
211
235
url = 'https://github.com/rwightman/pytorch-image-models/releases/download/v0.1-weights/tf_efficientnet_cc_b0_4e-4362b6b2.pth' ,
212
236
mean = IMAGENET_INCEPTION_MEAN , std = IMAGENET_INCEPTION_STD ),
@@ -217,6 +241,33 @@ def _cfg(url='', **kwargs):
217
241
url = 'https://github.com/rwightman/pytorch-image-models/releases/download/v0.1-weights/tf_efficientnet_cc_b1_8e-f7c79ae1.pth' ,
218
242
mean = IMAGENET_INCEPTION_MEAN , std = IMAGENET_INCEPTION_STD ,
219
243
input_size = (3 , 240 , 240 ), pool_size = (8 , 8 ), crop_pct = 0.882 ),
244
+
245
+ 'tf_efficientnet_lite0' : _cfg (
246
+ url = 'https://github.com/rwightman/pytorch-image-models/releases/download/v0.1-weights/tf_efficientnet_lite0-0aa007d2.pth' ,
247
+ mean = (0.5 , 0.5 , 0.5 ), std = (0.5 , 0.5 , 0.5 ),
248
+ interpolation = 'bicubic' , # should be bilinear but bicubic better match for TF bilinear at low res
249
+ ),
250
+ 'tf_efficientnet_lite1' : _cfg (
251
+ url = 'https://github.com/rwightman/pytorch-image-models/releases/download/v0.1-weights/tf_efficientnet_lite1-bde8b488.pth' ,
252
+ mean = (0.5 , 0.5 , 0.5 ), std = (0.5 , 0.5 , 0.5 ),
253
+ input_size = (3 , 240 , 240 ), pool_size = (8 , 8 ), crop_pct = 0.882 ,
254
+ interpolation = 'bicubic' , # should be bilinear but bicubic better match for TF bilinear at low res
255
+ ),
256
+ 'tf_efficientnet_lite2' : _cfg (
257
+ url = 'https://github.com/rwightman/pytorch-image-models/releases/download/v0.1-weights/tf_efficientnet_lite2-dcccb7df.pth' ,
258
+ mean = (0.5 , 0.5 , 0.5 ), std = (0.5 , 0.5 , 0.5 ),
259
+ input_size = (3 , 260 , 260 ), pool_size = (9 , 9 ), crop_pct = 0.890 ,
260
+ interpolation = 'bicubic' , # should be bilinear but bicubic better match for TF bilinear at low res
261
+ ),
262
+ 'tf_efficientnet_lite3' : _cfg (
263
+ url = 'https://github.com/rwightman/pytorch-image-models/releases/download/v0.1-weights/tf_efficientnet_lite3-b733e338.pth' ,
264
+ mean = (0.5 , 0.5 , 0.5 ), std = (0.5 , 0.5 , 0.5 ),
265
+ input_size = (3 , 300 , 300 ), pool_size = (10 , 10 ), crop_pct = 0.904 , interpolation = 'bilinear' ),
266
+ 'tf_efficientnet_lite4' : _cfg (
267
+ url = 'https://github.com/rwightman/pytorch-image-models/releases/download/v0.1-weights/tf_efficientnet_lite4-741542c3.pth' ,
268
+ mean = (0.5 , 0.5 , 0.5 ), std = (0.5 , 0.5 , 0.5 ),
269
+ input_size = (3 , 380 , 380 ), pool_size = (12 , 12 ), crop_pct = 0.922 , interpolation = 'bilinear' ),
270
+
220
271
'mixnet_s' : _cfg (
221
272
url = 'https://github.com/rwightman/pytorch-image-models/releases/download/v0.1-weights/mixnet_s-a907afbc.pth' ),
222
273
'mixnet_m' : _cfg (
@@ -226,6 +277,7 @@ def _cfg(url='', **kwargs):
226
277
'mixnet_xl' : _cfg (
227
278
url = 'https://github.com/rwightman/pytorch-image-models/releases/download/v0.1-weights/mixnet_xl_ra-aac3c00c.pth' ),
228
279
'mixnet_xxl' : _cfg (),
280
+
229
281
'tf_mixnet_s' : _cfg (
230
282
url = 'https://github.com/rwightman/pytorch-image-models/releases/download/v0.1-weights/tf_mixnet_s-89d3354b.pth' ),
231
283
'tf_mixnet_m' : _cfg (
@@ -253,7 +305,7 @@ class EfficientNet(nn.Module):
253
305
254
306
def __init__ (self , block_args , num_classes = 1000 , num_features = 1280 , in_chans = 3 , stem_size = 32 ,
255
307
channel_multiplier = 1.0 , channel_divisor = 8 , channel_min = None ,
256
- output_stride = 32 , pad_type = '' , act_layer = nn .ReLU , drop_rate = 0. , drop_path_rate = 0. ,
308
+ output_stride = 32 , pad_type = '' , fix_stem = False , act_layer = nn .ReLU , drop_rate = 0. , drop_path_rate = 0. ,
257
309
se_kwargs = None , norm_layer = nn .BatchNorm2d , norm_kwargs = None , global_pool = 'avg' ):
258
310
super (EfficientNet , self ).__init__ ()
259
311
norm_kwargs = norm_kwargs or {}
@@ -264,7 +316,8 @@ def __init__(self, block_args, num_classes=1000, num_features=1280, in_chans=3,
264
316
self ._in_chs = in_chans
265
317
266
318
# Stem
267
- stem_size = round_channels (stem_size , channel_multiplier , channel_divisor , channel_min )
319
+ if not fix_stem :
320
+ stem_size = round_channels (stem_size , channel_multiplier , channel_divisor , channel_min )
268
321
self .conv_stem = create_conv2d (self ._in_chs , stem_size , 3 , stride = 2 , padding = pad_type )
269
322
self .bn1 = norm_layer (stem_size , ** norm_kwargs )
270
323
self .act1 = act_layer (inplace = True )
@@ -333,7 +386,7 @@ class EfficientNetFeatures(nn.Module):
333
386
334
387
def __init__ (self , block_args , out_indices = (0 , 1 , 2 , 3 , 4 ), feature_location = 'pre_pwl' ,
335
388
in_chans = 3 , stem_size = 32 , channel_multiplier = 1.0 , channel_divisor = 8 , channel_min = None ,
336
- output_stride = 32 , pad_type = '' , act_layer = nn .ReLU , drop_rate = 0. , drop_path_rate = 0. ,
389
+ output_stride = 32 , pad_type = '' , fix_stem = False , act_layer = nn .ReLU , drop_rate = 0. , drop_path_rate = 0. ,
337
390
se_kwargs = None , norm_layer = nn .BatchNorm2d , norm_kwargs = None ):
338
391
super (EfficientNetFeatures , self ).__init__ ()
339
392
norm_kwargs = norm_kwargs or {}
@@ -346,7 +399,8 @@ def __init__(self, block_args, out_indices=(0, 1, 2, 3, 4), feature_location='pr
346
399
self ._in_chs = in_chans
347
400
348
401
# Stem
349
- stem_size = round_channels (stem_size , channel_multiplier , channel_divisor , channel_min )
402
+ if not fix_stem :
403
+ stem_size = round_channels (stem_size , channel_multiplier , channel_divisor , channel_min )
350
404
self .conv_stem = create_conv2d (self ._in_chs , stem_size , 3 , stride = 2 , padding = pad_type )
351
405
self .bn1 = norm_layer (stem_size , ** norm_kwargs )
352
406
self .act1 = act_layer (inplace = True )
@@ -707,6 +761,47 @@ def _gen_efficientnet_condconv(
707
761
return model
708
762
709
763
764
+ def _gen_efficientnet_lite (variant , channel_multiplier = 1.0 , depth_multiplier = 1.0 , pretrained = False , ** kwargs ):
765
+ """Creates an EfficientNet-Lite model.
766
+
767
+ Ref impl: https://github.com/tensorflow/tpu/tree/master/models/official/efficientnet/lite
768
+ Paper: https://arxiv.org/abs/1905.11946
769
+
770
+ EfficientNet params
771
+ name: (channel_multiplier, depth_multiplier, resolution, dropout_rate)
772
+ 'efficientnet-lite0': (1.0, 1.0, 224, 0.2),
773
+ 'efficientnet-lite1': (1.0, 1.1, 240, 0.2),
774
+ 'efficientnet-lite2': (1.1, 1.2, 260, 0.3),
775
+ 'efficientnet-lite3': (1.2, 1.4, 280, 0.3),
776
+ 'efficientnet-lite4': (1.4, 1.8, 300, 0.3),
777
+
778
+ Args:
779
+ channel_multiplier: multiplier to number of channels per layer
780
+ depth_multiplier: multiplier to number of repeats per stage
781
+ """
782
+ arch_def = [
783
+ ['ds_r1_k3_s1_e1_c16' ],
784
+ ['ir_r2_k3_s2_e6_c24' ],
785
+ ['ir_r2_k5_s2_e6_c40' ],
786
+ ['ir_r3_k3_s2_e6_c80' ],
787
+ ['ir_r3_k5_s1_e6_c112' ],
788
+ ['ir_r4_k5_s2_e6_c192' ],
789
+ ['ir_r1_k3_s1_e6_c320' ],
790
+ ]
791
+ model_kwargs = dict (
792
+ block_args = decode_arch_def (arch_def , depth_multiplier , fix_first_last = True ),
793
+ num_features = 1280 ,
794
+ stem_size = 32 ,
795
+ fix_stem = True ,
796
+ channel_multiplier = channel_multiplier ,
797
+ act_layer = nn .ReLU6 ,
798
+ norm_kwargs = resolve_bn_args (kwargs ),
799
+ ** kwargs ,
800
+ )
801
+ model = _create_model (model_kwargs , default_cfgs [variant ], pretrained )
802
+ return model
803
+
804
+
710
805
def _gen_mixnet_s (variant , channel_multiplier = 1.0 , pretrained = False , ** kwargs ):
711
806
"""Creates a MixNet Small model.
712
807
@@ -1032,6 +1127,51 @@ def efficientnet_cc_b1_8e(pretrained=False, **kwargs):
1032
1127
return model
1033
1128
1034
1129
1130
+ @register_model
1131
+ def efficientnet_lite0 (pretrained = False , ** kwargs ):
1132
+ """ EfficientNet-Lite0 """
1133
+ # NOTE for train, drop_rate should be 0.2, drop_path_rate should be 0.2
1134
+ model = _gen_efficientnet_lite (
1135
+ 'efficientnet_lite0' , channel_multiplier = 1.0 , depth_multiplier = 1.0 , pretrained = pretrained , ** kwargs )
1136
+ return model
1137
+
1138
+
1139
+ @register_model
1140
+ def efficientnet_lite1 (pretrained = False , ** kwargs ):
1141
+ """ EfficientNet-Lite1 """
1142
+ # NOTE for train, drop_rate should be 0.2, drop_path_rate should be 0.2
1143
+ model = _gen_efficientnet_lite (
1144
+ 'efficientnet_lite1' , channel_multiplier = 1.0 , depth_multiplier = 1.1 , pretrained = pretrained , ** kwargs )
1145
+ return model
1146
+
1147
+
1148
+ @register_model
1149
+ def efficientnet_lite2 (pretrained = False , ** kwargs ):
1150
+ """ EfficientNet-Lite2 """
1151
+ # NOTE for train, drop_rate should be 0.3, drop_path_rate should be 0.2
1152
+ model = _gen_efficientnet_lite (
1153
+ 'efficientnet_lite2' , channel_multiplier = 1.1 , depth_multiplier = 1.2 , pretrained = pretrained , ** kwargs )
1154
+ return model
1155
+
1156
+
1157
+ @register_model
1158
+ def efficientnet_lite3 (pretrained = False , ** kwargs ):
1159
+ """ EfficientNet-Lite3 """
1160
+ # NOTE for train, drop_rate should be 0.3, drop_path_rate should be 0.2
1161
+ model = _gen_efficientnet_lite (
1162
+ 'efficientnet_lite3' , channel_multiplier = 1.2 , depth_multiplier = 1.4 , pretrained = pretrained , ** kwargs )
1163
+ return model
1164
+
1165
+
1166
+ @register_model
1167
+ def efficientnet_lite4 (pretrained = False , ** kwargs ):
1168
+ """ EfficientNet-Lite4 """
1169
+ # NOTE for train, drop_rate should be 0.4, drop_path_rate should be 0.2
1170
+ model = _gen_efficientnet_lite (
1171
+ 'efficientnet_lite4' , channel_multiplier = 1.4 , depth_multiplier = 1.8 , pretrained = pretrained , ** kwargs )
1172
+ return model
1173
+
1174
+
1035
1175
@register_model
1036
1176
def tf_efficientnet_b0 (pretrained = False , ** kwargs ):
1037
1177
""" EfficientNet-B0. Tensorflow compatible variant """
@@ -1386,6 +1526,61 @@ def tf_efficientnet_cc_b1_8e(pretrained=False, **kwargs):
1386
1526
return model
1387
1527
1388
1528
1529
+ @register_model
1530
+ def tf_efficientnet_lite0 (pretrained = False , ** kwargs ):
1531
+ """ EfficientNet-Lite0 """
1532
+ # NOTE for train, drop_rate should be 0.2, drop_path_rate should be 0.2
1533
+ kwargs ['bn_eps' ] = BN_EPS_TF_DEFAULT
1534
+ kwargs ['pad_type' ] = 'same'
1535
+ model = _gen_efficientnet_lite (
1536
+ 'tf_efficientnet_lite0' , channel_multiplier = 1.0 , depth_multiplier = 1.0 , pretrained = pretrained , ** kwargs )
1537
+ return model
1538
+
1539
+
1540
+ @register_model
1541
+ def tf_efficientnet_lite1 (pretrained = False , ** kwargs ):
1542
+ """ EfficientNet-Lite1 """
1543
+ # NOTE for train, drop_rate should be 0.2, drop_path_rate should be 0.2
1544
+ kwargs ['bn_eps' ] = BN_EPS_TF_DEFAULT
1545
+ kwargs ['pad_type' ] = 'same'
1546
+ model = _gen_efficientnet_lite (
1547
+ 'tf_efficientnet_lite1' , channel_multiplier = 1.0 , depth_multiplier = 1.1 , pretrained = pretrained , ** kwargs )
1548
+ return model
1549
+
1550
+
1551
+ @register_model
1552
+ def tf_efficientnet_lite2 (pretrained = False , ** kwargs ):
1553
+ """ EfficientNet-Lite2 """
1554
+ # NOTE for train, drop_rate should be 0.3, drop_path_rate should be 0.2
1555
+ kwargs ['bn_eps' ] = BN_EPS_TF_DEFAULT
1556
+ kwargs ['pad_type' ] = 'same'
1557
+ model = _gen_efficientnet_lite (
1558
+ 'tf_efficientnet_lite2' , channel_multiplier = 1.1 , depth_multiplier = 1.2 , pretrained = pretrained , ** kwargs )
1559
+ return model
1560
+
1561
+
1562
+ @register_model
1563
+ def tf_efficientnet_lite3 (pretrained = False , ** kwargs ):
1564
+ """ EfficientNet-Lite3 """
1565
+ # NOTE for train, drop_rate should be 0.3, drop_path_rate should be 0.2
1566
+ kwargs ['bn_eps' ] = BN_EPS_TF_DEFAULT
1567
+ kwargs ['pad_type' ] = 'same'
1568
+ model = _gen_efficientnet_lite (
1569
+ 'tf_efficientnet_lite3' , channel_multiplier = 1.2 , depth_multiplier = 1.4 , pretrained = pretrained , ** kwargs )
1570
+ return model
1571
+
1572
+
1573
+ @register_model
1574
+ def tf_efficientnet_lite4 (pretrained = False , ** kwargs ):
1575
+ """ EfficientNet-Lite4 """
1576
+ # NOTE for train, drop_rate should be 0.4, drop_path_rate should be 0.2
1577
+ kwargs ['bn_eps' ] = BN_EPS_TF_DEFAULT
1578
+ kwargs ['pad_type' ] = 'same'
1579
+ model = _gen_efficientnet_lite (
1580
+ 'tf_efficientnet_lite4' , channel_multiplier = 1.4 , depth_multiplier = 1.8 , pretrained = pretrained , ** kwargs )
1581
+ return model
1582
+
1583
+
1389
1584
@register_model
1390
1585
def mixnet_s (pretrained = False , ** kwargs ):
1391
1586
"""Creates a MixNet Small model.
0 commit comments