2626from models .conv2d_same import sconv2d
2727from data import IMAGENET_DEFAULT_MEAN , IMAGENET_DEFAULT_STD
2828
29- __all__ = ['GenMobileNet' , 'mnasnet_050' , 'mnasnet_075' , 'mnasnet_100' , 'mnasnet_140' ,
30- 'semnasnet_050' , 'semnasnet_075' , 'semnasnet_100' , 'semnasnet_140' , 'mnasnet_small' ,
31- 'mobilenetv1_100' , 'mobilenetv2_100' , 'mobilenetv3_050' , 'mobilenetv3_075' , 'mobilenetv3_100' ,
32- 'chamnetv1_100' , 'chamnetv2_100' , 'fbnetc_100' , 'spnasnet_100' ]
29+ _models = [
30+ 'mnasnet_050' , 'mnasnet_075' , 'mnasnet_100' , 'mnasnet_140' , 'semnasnet_050' , 'semnasnet_075' ,
31+ 'semnasnet_100' , 'semnasnet_140' , 'mnasnet_small' , 'mobilenetv1_100' , 'mobilenetv2_100' ,
32+ 'mobilenetv3_050' , 'mobilenetv3_075' , 'mobilenetv3_100' , 'chamnetv1_100' , 'chamnetv2_100' ,
33+ 'fbnetc_100' , 'spnasnet_100' , 'tflite_mnasnet_100' , 'tflite_semnasnet_100' ]
34+ __all__ = ['GenMobileNet' , 'genmobilenet_model_names' ] + _models
3335
3436
3537def _cfg (url = '' , ** kwargs ):
@@ -67,7 +69,7 @@ def _cfg(url='', **kwargs):
6769 'spnasnet_100' : _cfg (url = 'https://www.dropbox.com/s/iieopt18rytkgaa/spnasnet_100-048bc3f4.pth?dl=1' ),
6870}
6971
70- _DEBUG = True
72+ _DEBUG = False
7173
7274# Default args for PyTorch BN impl
7375_BN_MOMENTUM_PT_DEFAULT = 0.1
@@ -266,7 +268,7 @@ class _BlockBuilder:
266268 def __init__ (self , depth_multiplier = 1.0 , depth_divisor = 8 , min_depth = None ,
267269 act_fn = None , se_gate_fn = torch .sigmoid , se_reduce_mid = False ,
268270 bn_momentum = _BN_MOMENTUM_PT_DEFAULT , bn_eps = _BN_EPS_PT_DEFAULT ,
269- folded_bn = False , padding_same = False ):
271+ folded_bn = False , padding_same = False , verbose = False ):
270272 self .depth_multiplier = depth_multiplier
271273 self .depth_divisor = depth_divisor
272274 self .min_depth = min_depth
@@ -277,6 +279,7 @@ def __init__(self, depth_multiplier=1.0, depth_divisor=8, min_depth=None,
277279 self .bn_eps = bn_eps
278280 self .folded_bn = folded_bn
279281 self .padding_same = padding_same
282+ self .verbose = verbose
280283 self .in_chs = None
281284
282285 def _round_channels (self , chs ):
@@ -293,7 +296,7 @@ def _make_block(self, ba):
293296 # block act fn overrides the model default
294297 ba ['act_fn' ] = ba ['act_fn' ] if ba ['act_fn' ] is not None else self .act_fn
295298 assert ba ['act_fn' ] is not None
296- if _DEBUG :
299+ if self . verbose :
297300 print ('args:' , ba )
298301 # could replace this if with lambdas or functools binding if variety increases
299302 if bt == 'ir' :
@@ -315,7 +318,7 @@ def _make_stack(self, stack_args):
315318 blocks = []
316319 # each stack (stage) contains a list of block arguments
317320 for block_idx , ba in enumerate (stack_args ):
318- if _DEBUG :
321+ if self . verbose :
319322 print ('block' , block_idx , end = ', ' )
320323 if block_idx >= 1 :
321324 # only the first block in any stack/stage can have a stride > 1
@@ -334,18 +337,18 @@ def __call__(self, in_chs, arch_def):
334337 List of block stacks (each stack wrapped in nn.Sequential)
335338 """
336339 arch_args = _decode_arch_def (arch_def ) # convert and expand string defs to arg dicts
337- if _DEBUG :
340+ if self . verbose :
338341 print ('Building model trunk with %d stacks (stages)...' % len (arch_args ))
339342 self .in_chs = in_chs
340343 blocks = []
341344 # outer list of arch_args defines the stacks ('stages' by some conventions)
342345 for stack_idx , stack in enumerate (arch_args ):
343- if _DEBUG :
346+ if self . verbose :
344347 print ('stack' , stack_idx )
345348 assert isinstance (stack , list )
346349 stack = self ._make_stack (stack )
347350 blocks .append (stack )
348- if _DEBUG :
351+ if self . verbose :
349352 print ()
350353 return blocks
351354
@@ -631,7 +634,7 @@ def __init__(self, block_args, num_classes=1000, in_chans=3, stem_size=32, num_f
631634 builder = _BlockBuilder (
632635 depth_multiplier , depth_divisor , min_depth ,
633636 act_fn , se_gate_fn , se_reduce_mid ,
634- bn_momentum , bn_eps , folded_bn , padding_same )
637+ bn_momentum , bn_eps , folded_bn , padding_same , verbose = _DEBUG )
635638 self .blocks = nn .Sequential (* builder (in_chs , block_args ))
636639 in_chs = builder .in_chs
637640
@@ -1265,3 +1268,7 @@ def spnasnet_100(num_classes, in_chans=3, pretrained=False, **kwargs):
12651268 if pretrained :
12661269 load_pretrained (model , default_cfg , num_classes , in_chans )
12671270 return model
1271+
1272+
1273+ def genmobilenet_model_names ():
1274+ return set (_models )
0 commit comments