From 6ca0828166a1a904a96e1c4bb1b0740d40b6ffa5 Mon Sep 17 00:00:00 2001 From: Ross Wightman Date: Thu, 28 Nov 2019 17:11:53 -0800 Subject: [PATCH] Update EfficientNet comments, MobileNetV3 non-TF create fns, fix factory arg checks, bump PyTorch version req to 1.2 --- requirements.txt | 4 ++-- timm/models/efficientnet.py | 47 +++++++++++++------------------------ timm/models/factory.py | 4 ++-- timm/models/mobilenetv3.py | 32 ++++++++++++++++++++++++- 4 files changed, 51 insertions(+), 36 deletions(-) diff --git a/requirements.txt b/requirements.txt index 88ce152f..f05f9812 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,3 +1,3 @@ -torch>=1.1.0 -torchvision>=0.3.0 +torch>=1.2.0 +torchvision>=0.4.0 pyyaml diff --git a/timm/models/efficientnet.py b/timm/models/efficientnet.py index a4f89055..9163a023 100644 --- a/timm/models/efficientnet.py +++ b/timm/models/efficientnet.py @@ -845,8 +845,7 @@ def spnasnet_100(pretrained=False, **kwargs): @register_model def efficientnet_b0(pretrained=False, **kwargs): """ EfficientNet-B0 """ - # NOTE for train, drop_rate should be 0.2 - #kwargs['drop_connect_rate'] = 0.2 # set when training, TODO add as cmd arg + # NOTE for train, drop_rate should be 0.2, drop_connect_rate should be 0.2 model = _gen_efficientnet( 'efficientnet_b0', channel_multiplier=1.0, depth_multiplier=1.0, pretrained=pretrained, **kwargs) return model @@ -855,8 +854,7 @@ def efficientnet_b0(pretrained=False, **kwargs): @register_model def efficientnet_b1(pretrained=False, **kwargs): """ EfficientNet-B1 """ - # NOTE for train, drop_rate should be 0.2 - #kwargs['drop_connect_rate'] = 0.2 # set when training, TODO add as cmd arg + # NOTE for train, drop_rate should be 0.2, drop_connect_rate should be 0.2 model = _gen_efficientnet( 'efficientnet_b1', channel_multiplier=1.0, depth_multiplier=1.1, pretrained=pretrained, **kwargs) return model @@ -865,8 +863,7 @@ def efficientnet_b1(pretrained=False, **kwargs): @register_model def efficientnet_b2(pretrained=False, **kwargs): """ EfficientNet-B2 """ - # NOTE for train, drop_rate should be 0.3 - #kwargs['drop_connect_rate'] = 0.2 # set when training, TODO add as cmd arg + # NOTE for train, drop_rate should be 0.3, drop_connect_rate should be 0.2 model = _gen_efficientnet( 'efficientnet_b2', channel_multiplier=1.1, depth_multiplier=1.2, pretrained=pretrained, **kwargs) return model @@ -875,8 +872,7 @@ def efficientnet_b2(pretrained=False, **kwargs): @register_model def efficientnet_b3(pretrained=False, **kwargs): """ EfficientNet-B3 """ - # NOTE for train, drop_rate should be 0.3 - #kwargs['drop_connect_rate'] = 0.2 # set when training, TODO add as cmd arg + # NOTE for train, drop_rate should be 0.3, drop_connect_rate should be 0.2 model = _gen_efficientnet( 'efficientnet_b3', channel_multiplier=1.2, depth_multiplier=1.4, pretrained=pretrained, **kwargs) return model @@ -885,8 +881,7 @@ def efficientnet_b3(pretrained=False, **kwargs): @register_model def efficientnet_b4(pretrained=False, **kwargs): """ EfficientNet-B4 """ - # NOTE for train, drop_rate should be 0.4 - #kwargs['drop_connect_rate'] = 0.2 # set when training, TODO add as cmd arg + # NOTE for train, drop_rate should be 0.4, drop_connect_rate should be 0.2 model = _gen_efficientnet( 'efficientnet_b4', channel_multiplier=1.4, depth_multiplier=1.8, pretrained=pretrained, **kwargs) return model @@ -895,8 +890,7 @@ def efficientnet_b4(pretrained=False, **kwargs): @register_model def efficientnet_b5(pretrained=False, **kwargs): """ EfficientNet-B5 """ - # NOTE for train, drop_rate should be 0.4 - #kwargs['drop_connect_rate'] = 0.2 # set when training, TODO add as cmd arg + # NOTE for train, drop_rate should be 0.4, drop_connect_rate should be 0.2 model = _gen_efficientnet( 'efficientnet_b5', channel_multiplier=1.6, depth_multiplier=2.2, pretrained=pretrained, **kwargs) return model @@ -905,8 +899,7 @@ def efficientnet_b5(pretrained=False, **kwargs): @register_model def efficientnet_b6(pretrained=False, **kwargs): """ EfficientNet-B6 """ - # NOTE for train, drop_rate should be 0.5 - #kwargs['drop_connect_rate'] = 0.2 # set when training, TODO add as cmd arg + # NOTE for train, drop_rate should be 0.5, drop_connect_rate should be 0.2 model = _gen_efficientnet( 'efficientnet_b6', channel_multiplier=1.8, depth_multiplier=2.6, pretrained=pretrained, **kwargs) return model @@ -915,8 +908,7 @@ def efficientnet_b6(pretrained=False, **kwargs): @register_model def efficientnet_b7(pretrained=False, **kwargs): """ EfficientNet-B7 """ - # NOTE for train, drop_rate should be 0.5 - #kwargs['drop_connect_rate'] = 0.2 # set when training, TODO add as cmd arg + # NOTE for train, drop_rate should be 0.5, drop_connect_rate should be 0.2 model = _gen_efficientnet( 'efficientnet_b7', channel_multiplier=2.0, depth_multiplier=3.1, pretrained=pretrained, **kwargs) return model @@ -949,8 +941,7 @@ def efficientnet_el(pretrained=False, **kwargs): @register_model def efficientnet_cc_b0_4e(pretrained=False, **kwargs): """ EfficientNet-CondConv-B0 w/ 8 Experts """ - # NOTE for train, drop_rate should be 0.2 - #kwargs['drop_connect_rate'] = 0.2 # set when training, TODO add as cmd arg + # NOTE for train, drop_rate should be 0.2, drop_connect_rate should be 0.2 model = _gen_efficientnet_condconv( 'efficientnet_cc_b0_4e', channel_multiplier=1.0, depth_multiplier=1.0, pretrained=pretrained, **kwargs) return model @@ -959,8 +950,7 @@ def efficientnet_cc_b0_4e(pretrained=False, **kwargs): @register_model def efficientnet_cc_b0_8e(pretrained=False, **kwargs): """ EfficientNet-CondConv-B0 w/ 8 Experts """ - # NOTE for train, drop_rate should be 0.2 - #kwargs['drop_connect_rate'] = 0.2 # set when training, TODO add as cmd arg + # NOTE for train, drop_rate should be 0.2, drop_connect_rate should be 0.2 model = _gen_efficientnet_condconv( 'efficientnet_cc_b0_8e', channel_multiplier=1.0, depth_multiplier=1.0, experts_multiplier=2, pretrained=pretrained, **kwargs) @@ -969,8 +959,7 @@ def efficientnet_cc_b0_8e(pretrained=False, **kwargs): @register_model def efficientnet_cc_b1_8e(pretrained=False, **kwargs): """ EfficientNet-CondConv-B1 w/ 8 Experts """ - # NOTE for train, drop_rate should be 0.2 - #kwargs['drop_connect_rate'] = 0.2 # set when training, TODO add as cmd arg + # NOTE for train, drop_rate should be 0.2, drop_connect_rate should be 0.2 model = _gen_efficientnet_condconv( 'efficientnet_cc_b1_8e', channel_multiplier=1.0, depth_multiplier=1.1, experts_multiplier=2, pretrained=pretrained, **kwargs) @@ -1008,7 +997,7 @@ def tf_efficientnet_b2(pretrained=False, **kwargs): @register_model -def tf_efficientnet_b3(pretrained=False, num_classes=1000, in_chans=3, **kwargs): +def tf_efficientnet_b3(pretrained=False, **kwargs): """ EfficientNet-B3. Tensorflow compatible variant """ kwargs['bn_eps'] = BN_EPS_TF_DEFAULT kwargs['pad_type'] = 'same' @@ -1090,7 +1079,7 @@ def tf_efficientnet_b2_ap(pretrained=False, **kwargs): @register_model -def tf_efficientnet_b3_ap(pretrained=False, num_classes=1000, in_chans=3, **kwargs): +def tf_efficientnet_b3_ap(pretrained=False, **kwargs): """ EfficientNet-B3. Tensorflow compatible variant """ kwargs['bn_eps'] = BN_EPS_TF_DEFAULT kwargs['pad_type'] = 'same' @@ -1186,8 +1175,7 @@ def tf_efficientnet_el(pretrained=False, **kwargs): @register_model def tf_efficientnet_cc_b0_4e(pretrained=False, **kwargs): """ EfficientNet-CondConv-B0 w/ 4 Experts. Tensorflow compatible variant """ - # NOTE for train, drop_rate should be 0.2 - #kwargs['drop_connect_rate'] = 0.2 # set when training, TODO add as cmd arg + # NOTE for train, drop_rate should be 0.2, drop_connect_rate should be 0.2 kwargs['bn_eps'] = BN_EPS_TF_DEFAULT kwargs['pad_type'] = 'same' model = _gen_efficientnet_condconv( @@ -1198,8 +1186,7 @@ def tf_efficientnet_cc_b0_4e(pretrained=False, **kwargs): @register_model def tf_efficientnet_cc_b0_8e(pretrained=False, **kwargs): """ EfficientNet-CondConv-B0 w/ 8 Experts. Tensorflow compatible variant """ - # NOTE for train, drop_rate should be 0.2 - #kwargs['drop_connect_rate'] = 0.2 # set when training, TODO add as cmd arg + # NOTE for train, drop_rate should be 0.2, drop_connect_rate should be 0.2 kwargs['bn_eps'] = BN_EPS_TF_DEFAULT kwargs['pad_type'] = 'same' model = _gen_efficientnet_condconv( @@ -1210,8 +1197,7 @@ def tf_efficientnet_cc_b0_8e(pretrained=False, **kwargs): @register_model def tf_efficientnet_cc_b1_8e(pretrained=False, **kwargs): """ EfficientNet-CondConv-B1 w/ 8 Experts. Tensorflow compatible variant """ - # NOTE for train, drop_rate should be 0.2 - #kwargs['drop_connect_rate'] = 0.2 # set when training, TODO add as cmd arg + # NOTE for train, drop_rate should be 0.2, drop_connect_rate should be 0.2 kwargs['bn_eps'] = BN_EPS_TF_DEFAULT kwargs['pad_type'] = 'same' model = _gen_efficientnet_condconv( @@ -1262,7 +1248,6 @@ def mixnet_xxl(pretrained=False, **kwargs): """Creates a MixNet Double Extra Large model. Not a paper spec, experimental def by RW w/ depth scaling. """ - # kwargs['drop_connect_rate'] = 0.2 model = _gen_mixnet_m( 'mixnet_xxl', channel_multiplier=2.4, depth_multiplier=1.3, pretrained=pretrained, **kwargs) return model diff --git a/timm/models/factory.py b/timm/models/factory.py index 3c051e75..7b9f7a07 100644 --- a/timm/models/factory.py +++ b/timm/models/factory.py @@ -25,8 +25,8 @@ def create_model( """ margs = dict(pretrained=pretrained, num_classes=num_classes, in_chans=in_chans) - # Only gen_efficientnet models have support for batchnorm params or drop_connect_rate passed as args - is_efficientnet = is_model_in_modules(model_name, ['gen_efficientnet']) + # Only EfficientNet and MobileNetV3 models have support for batchnorm params or drop_connect_rate passed as args + is_efficientnet = is_model_in_modules(model_name, ['efficientnet', 'mobilenetv3']) if not is_efficientnet: kwargs.pop('bn_tf', None) kwargs.pop('bn_momentum', None) diff --git a/timm/models/mobilenetv3.py b/timm/models/mobilenetv3.py index 13fd16e6..a89adea4 100644 --- a/timm/models/mobilenetv3.py +++ b/timm/models/mobilenetv3.py @@ -35,6 +35,8 @@ def _cfg(url='', **kwargs): default_cfgs = { 'mobilenetv3_large_075': _cfg(url=''), 'mobilenetv3_large_100': _cfg(url=''), + 'mobilenetv3_small_075': _cfg(url=''), + 'mobilenetv3_small_100': _cfg(url=''), 'mobilenetv3_rw': _cfg( url='https://github.com/rwightman/pytorch-image-models/releases/download/v0.1-weights/mobilenetv3_100-35495452.pth', interpolation='bicubic'), @@ -374,6 +376,35 @@ def _gen_mobilenet_v3(variant, channel_multiplier=1.0, pretrained=False, **kwarg return model +@register_model +def mobilenetv3_large_075(pretrained=False, **kwargs): + """ MobileNet V3 """ + model = _gen_mobilenet_v3('mobilenetv3_large_075', 0.75, pretrained=pretrained, **kwargs) + return model + + +@register_model +def mobilenetv3_large_100(pretrained=False, **kwargs): + """ MobileNet V3 """ + model = _gen_mobilenet_v3('mobilenetv3_large_100', 1.0, pretrained=pretrained, **kwargs) + return model + + +@register_model +def mobilenetv3_small_075(pretrained=False, **kwargs): + """ MobileNet V3 """ + model = _gen_mobilenet_v3('mobilenetv3_small_075', 0.75, pretrained=pretrained, **kwargs) + return model + + +@register_model +def mobilenetv3_small_100(pretrained=False, **kwargs): + print(kwargs) + """ MobileNet V3 """ + model = _gen_mobilenet_v3('mobilenetv3_small_100', 1.0, pretrained=pretrained, **kwargs) + return model + + @register_model def mobilenetv3_rw(pretrained=False, **kwargs): """ MobileNet V3 """ @@ -384,7 +415,6 @@ def mobilenetv3_rw(pretrained=False, **kwargs): return model - @register_model def tf_mobilenetv3_large_075(pretrained=False, **kwargs): """ MobileNet V3 """