diff --git a/hubconf.py b/hubconf.py index 84ae3a3edff1089ce6c524c2b790038813e07ccf..eb114bc20d0b7954ec5b8fd3206cfffe5ef0407b 100644 --- a/hubconf.py +++ b/hubconf.py @@ -43,8 +43,8 @@ class _SysPathG(object): with _SysPathG( os.path.join( - os.path.dirname(os.path.abspath(__file__)), 'ppcls', 'modeling')): - import architectures + os.path.dirname(os.path.abspath(__file__)), 'ppcls', 'arch')): + import backbone def _load_pretrained_parameters(model, name): url = 'https://paddle-imagenet-models-name.bj.bcebos.com/dygraph/{}_pretrained.pdparams'.format( @@ -63,7 +63,7 @@ with _SysPathG( Returns: model: nn.Layer. Specific `AlexNet` model depends on args. """ - model = architectures.AlexNet(**kwargs) + model = backbone.AlexNet(**kwargs) if pretrained: model = _load_pretrained_parameters(model, 'AlexNet') @@ -80,7 +80,7 @@ with _SysPathG( Returns: model: nn.Layer. Specific `VGG11` model depends on args. """ - model = architectures.VGG11(**kwargs) + model = backbone.VGG11(**kwargs) if pretrained: model = _load_pretrained_parameters(model, 'VGG11') @@ -97,7 +97,7 @@ with _SysPathG( Returns: model: nn.Layer. Specific `VGG13` model depends on args. """ - model = architectures.VGG13(**kwargs) + model = backbone.VGG13(**kwargs) if pretrained: model = _load_pretrained_parameters(model, 'VGG13') @@ -114,7 +114,7 @@ with _SysPathG( Returns: model: nn.Layer. Specific `VGG16` model depends on args. """ - model = architectures.VGG16(**kwargs) + model = backbone.VGG16(**kwargs) if pretrained: model = _load_pretrained_parameters(model, 'VGG16') @@ -131,7 +131,7 @@ with _SysPathG( Returns: model: nn.Layer. Specific `VGG19` model depends on args. """ - model = architectures.VGG19(**kwargs) + model = backbone.VGG19(**kwargs) if pretrained: model = _load_pretrained_parameters(model, 'VGG19') @@ -149,7 +149,7 @@ with _SysPathG( Returns: model: nn.Layer. Specific `ResNet18` model depends on args. """ - model = architectures.ResNet18(**kwargs) + model = backbone.ResNet18(**kwargs) if pretrained: model = _load_pretrained_parameters(model, 'ResNet18') @@ -167,7 +167,7 @@ with _SysPathG( Returns: model: nn.Layer. Specific `ResNet34` model depends on args. """ - model = architectures.ResNet34(**kwargs) + model = backbone.ResNet34(**kwargs) if pretrained: model = _load_pretrained_parameters(model, 'ResNet34') @@ -185,7 +185,7 @@ with _SysPathG( Returns: model: nn.Layer. Specific `ResNet50` model depends on args. """ - model = architectures.ResNet50(**kwargs) + model = backbone.ResNet50(**kwargs) if pretrained: model = _load_pretrained_parameters(model, 'ResNet50') @@ -203,7 +203,7 @@ with _SysPathG( Returns: model: nn.Layer. Specific `ResNet101` model depends on args. """ - model = architectures.ResNet101(**kwargs) + model = backbone.ResNet101(**kwargs) if pretrained: model = _load_pretrained_parameters(model, 'ResNet101') @@ -221,7 +221,7 @@ with _SysPathG( Returns: model: nn.Layer. Specific `ResNet152` model depends on args. """ - model = architectures.ResNet152(**kwargs) + model = backbone.ResNet152(**kwargs) if pretrained: model = _load_pretrained_parameters(model, 'ResNet152') @@ -237,7 +237,7 @@ with _SysPathG( Returns: model: nn.Layer. Specific `SqueezeNet1_0` model depends on args. """ - model = architectures.SqueezeNet1_0(**kwargs) + model = backbone.SqueezeNet1_0(**kwargs) if pretrained: model = _load_pretrained_parameters(model, 'SqueezeNet1_0') @@ -253,7 +253,7 @@ with _SysPathG( Returns: model: nn.Layer. Specific `SqueezeNet1_1` model depends on args. """ - model = architectures.SqueezeNet1_1(**kwargs) + model = backbone.SqueezeNet1_1(**kwargs) if pretrained: model = _load_pretrained_parameters(model, 'SqueezeNet1_1') @@ -271,7 +271,7 @@ with _SysPathG( Returns: model: nn.Layer. Specific `DenseNet121` model depends on args. """ - model = architectures.DenseNet121(**kwargs) + model = backbone.DenseNet121(**kwargs) if pretrained: model = _load_pretrained_parameters(model, 'DenseNet121') @@ -289,7 +289,7 @@ with _SysPathG( Returns: model: nn.Layer. Specific `DenseNet161` model depends on args. """ - model = architectures.DenseNet161(**kwargs) + model = backbone.DenseNet161(**kwargs) if pretrained: model = _load_pretrained_parameters(model, 'DenseNet161') @@ -307,7 +307,7 @@ with _SysPathG( Returns: model: nn.Layer. Specific `DenseNet169` model depends on args. """ - model = architectures.DenseNet169(**kwargs) + model = backbone.DenseNet169(**kwargs) if pretrained: model = _load_pretrained_parameters(model, 'DenseNet169') @@ -325,7 +325,7 @@ with _SysPathG( Returns: model: nn.Layer. Specific `DenseNet201` model depends on args. """ - model = architectures.DenseNet201(**kwargs) + model = backbone.DenseNet201(**kwargs) if pretrained: model = _load_pretrained_parameters(model, 'DenseNet201') @@ -343,7 +343,7 @@ with _SysPathG( Returns: model: nn.Layer. Specific `DenseNet264` model depends on args. """ - model = architectures.DenseNet264(**kwargs) + model = backbone.DenseNet264(**kwargs) if pretrained: model = _load_pretrained_parameters(model, 'DenseNet264') @@ -359,7 +359,7 @@ with _SysPathG( Returns: model: nn.Layer. Specific `InceptionV3` model depends on args. """ - model = architectures.InceptionV3(**kwargs) + model = backbone.InceptionV3(**kwargs) if pretrained: model = _load_pretrained_parameters(model, 'InceptionV3') @@ -375,7 +375,7 @@ with _SysPathG( Returns: model: nn.Layer. Specific `InceptionV4` model depends on args. """ - model = architectures.InceptionV4(**kwargs) + model = backbone.InceptionV4(**kwargs) if pretrained: model = _load_pretrained_parameters(model, 'InceptionV4') @@ -391,7 +391,7 @@ with _SysPathG( Returns: model: nn.Layer. Specific `GoogLeNet` model depends on args. """ - model = architectures.GoogLeNet(**kwargs) + model = backbone.GoogLeNet(**kwargs) if pretrained: model = _load_pretrained_parameters(model, 'GoogLeNet') @@ -407,7 +407,7 @@ with _SysPathG( Returns: model: nn.Layer. Specific `ShuffleNetV2_x0_25` model depends on args. """ - model = architectures.ShuffleNetV2_x0_25(**kwargs) + model = backbone.ShuffleNetV2_x0_25(**kwargs) if pretrained: model = _load_pretrained_parameters(model, 'ShuffleNetV2_x0_25') @@ -423,7 +423,7 @@ with _SysPathG( Returns: model: nn.Layer. Specific `MobileNetV1` model depends on args. """ - model = architectures.MobileNetV1(**kwargs) + model = backbone.MobileNetV1(**kwargs) if pretrained: model = _load_pretrained_parameters(model, 'MobileNetV1') @@ -439,7 +439,7 @@ with _SysPathG( Returns: model: nn.Layer. Specific `MobileNetV1_x0_25` model depends on args. """ - model = architectures.MobileNetV1_x0_25(**kwargs) + model = backbone.MobileNetV1_x0_25(**kwargs) if pretrained: model = _load_pretrained_parameters(model, 'MobileNetV1_x0_25') @@ -455,7 +455,7 @@ with _SysPathG( Returns: model: nn.Layer. Specific `MobileNetV1_x0_5` model depends on args. """ - model = architectures.MobileNetV1_x0_5(**kwargs) + model = backbone.MobileNetV1_x0_5(**kwargs) if pretrained: model = _load_pretrained_parameters(model, 'MobileNetV1_x0_5') @@ -471,7 +471,7 @@ with _SysPathG( Returns: model: nn.Layer. Specific `MobileNetV1_x0_75` model depends on args. """ - model = architectures.MobileNetV1_x0_75(**kwargs) + model = backbone.MobileNetV1_x0_75(**kwargs) if pretrained: model = _load_pretrained_parameters(model, 'MobileNetV1_x0_75') @@ -487,7 +487,7 @@ with _SysPathG( Returns: model: nn.Layer. Specific `MobileNetV2_x0_25` model depends on args. """ - model = architectures.MobileNetV2_x0_25(**kwargs) + model = backbone.MobileNetV2_x0_25(**kwargs) if pretrained: model = _load_pretrained_parameters(model, 'MobileNetV2_x0_25') @@ -503,7 +503,7 @@ with _SysPathG( Returns: model: nn.Layer. Specific `MobileNetV2_x0_5` model depends on args. """ - model = architectures.MobileNetV2_x0_5(**kwargs) + model = backbone.MobileNetV2_x0_5(**kwargs) if pretrained: model = _load_pretrained_parameters(model, 'MobileNetV2_x0_5') @@ -519,7 +519,7 @@ with _SysPathG( Returns: model: nn.Layer. Specific `MobileNetV2_x0_75` model depends on args. """ - model = architectures.MobileNetV2_x0_75(**kwargs) + model = backbone.MobileNetV2_x0_75(**kwargs) if pretrained: model = _load_pretrained_parameters(model, 'MobileNetV2_x0_75') @@ -535,7 +535,7 @@ with _SysPathG( Returns: model: nn.Layer. Specific `MobileNetV2_x1_5` model depends on args. """ - model = architectures.MobileNetV2_x1_5(**kwargs) + model = backbone.MobileNetV2_x1_5(**kwargs) if pretrained: model = _load_pretrained_parameters(model, 'MobileNetV2_x1_5') @@ -551,7 +551,7 @@ with _SysPathG( Returns: model: nn.Layer. Specific `MobileNetV2_x2_0` model depends on args. """ - model = architectures.MobileNetV2_x2_0(**kwargs) + model = backbone.MobileNetV2_x2_0(**kwargs) if pretrained: model = _load_pretrained_parameters(model, 'MobileNetV2_x2_0') @@ -567,7 +567,7 @@ with _SysPathG( Returns: model: nn.Layer. Specific `MobileNetV3_large_x0_35` model depends on args. """ - model = architectures.MobileNetV3_large_x0_35(**kwargs) + model = backbone.MobileNetV3_large_x0_35(**kwargs) if pretrained: model = _load_pretrained_parameters(model, 'MobileNetV3_large_x0_35') @@ -584,7 +584,7 @@ with _SysPathG( Returns: model: nn.Layer. Specific `MobileNetV3_large_x0_5` model depends on args. """ - model = architectures.MobileNetV3_large_x0_5(**kwargs) + model = backbone.MobileNetV3_large_x0_5(**kwargs) if pretrained: model = _load_pretrained_parameters(model, 'MobileNetV3_large_x0_5') @@ -601,7 +601,7 @@ with _SysPathG( Returns: model: nn.Layer. Specific `MobileNetV3_large_x0_75` model depends on args. """ - model = architectures.MobileNetV3_large_x0_75(**kwargs) + model = backbone.MobileNetV3_large_x0_75(**kwargs) if pretrained: model = _load_pretrained_parameters(model, 'MobileNetV3_large_x0_75') @@ -618,7 +618,7 @@ with _SysPathG( Returns: model: nn.Layer. Specific `MobileNetV3_large_x1_0` model depends on args. """ - model = architectures.MobileNetV3_large_x1_0(**kwargs) + model = backbone.MobileNetV3_large_x1_0(**kwargs) if pretrained: model = _load_pretrained_parameters(model, 'MobileNetV3_large_x1_0') @@ -635,7 +635,7 @@ with _SysPathG( Returns: model: nn.Layer. Specific `MobileNetV3_large_x1_25` model depends on args. """ - model = architectures.MobileNetV3_large_x1_25(**kwargs) + model = backbone.MobileNetV3_large_x1_25(**kwargs) if pretrained: model = _load_pretrained_parameters(model, 'MobileNetV3_large_x1_25') @@ -652,7 +652,7 @@ with _SysPathG( Returns: model: nn.Layer. Specific `MobileNetV3_small_x0_35` model depends on args. """ - model = architectures.MobileNetV3_small_x0_35(**kwargs) + model = backbone.MobileNetV3_small_x0_35(**kwargs) if pretrained: model = _load_pretrained_parameters(model, 'MobileNetV3_small_x0_35') @@ -669,7 +669,7 @@ with _SysPathG( Returns: model: nn.Layer. Specific `MobileNetV3_small_x0_5` model depends on args. """ - model = architectures.MobileNetV3_small_x0_5(**kwargs) + model = backbone.MobileNetV3_small_x0_5(**kwargs) if pretrained: model = _load_pretrained_parameters(model, 'MobileNetV3_small_x0_5') @@ -686,7 +686,7 @@ with _SysPathG( Returns: model: nn.Layer. Specific `MobileNetV3_small_x0_75` model depends on args. """ - model = architectures.MobileNetV3_small_x0_75(**kwargs) + model = backbone.MobileNetV3_small_x0_75(**kwargs) if pretrained: model = _load_pretrained_parameters(model, 'MobileNetV3_small_x0_75') @@ -703,7 +703,7 @@ with _SysPathG( Returns: model: nn.Layer. Specific `MobileNetV3_small_x1_0` model depends on args. """ - model = architectures.MobileNetV3_small_x1_0(**kwargs) + model = backbone.MobileNetV3_small_x1_0(**kwargs) if pretrained: model = _load_pretrained_parameters(model, 'MobileNetV3_small_x1_0') @@ -720,7 +720,7 @@ with _SysPathG( Returns: model: nn.Layer. Specific `MobileNetV3_small_x1_25` model depends on args. """ - model = architectures.MobileNetV3_small_x1_25(**kwargs) + model = backbone.MobileNetV3_small_x1_25(**kwargs) if pretrained: model = _load_pretrained_parameters(model, 'MobileNetV3_small_x1_25') @@ -737,7 +737,7 @@ with _SysPathG( Returns: model: nn.Layer. Specific `ResNeXt101_32x4d` model depends on args. """ - model = architectures.ResNeXt101_32x4d(**kwargs) + model = backbone.ResNeXt101_32x4d(**kwargs) if pretrained: model = _load_pretrained_parameters(model, 'ResNeXt101_32x4d') @@ -753,7 +753,7 @@ with _SysPathG( Returns: model: nn.Layer. Specific `ResNeXt101_64x4d` model depends on args. """ - model = architectures.ResNeXt101_64x4d(**kwargs) + model = backbone.ResNeXt101_64x4d(**kwargs) if pretrained: model = _load_pretrained_parameters(model, 'ResNeXt101_64x4d') @@ -769,7 +769,7 @@ with _SysPathG( Returns: model: nn.Layer. Specific `ResNeXt152_32x4d` model depends on args. """ - model = architectures.ResNeXt152_32x4d(**kwargs) + model = backbone.ResNeXt152_32x4d(**kwargs) if pretrained: model = _load_pretrained_parameters(model, 'ResNeXt152_32x4d') @@ -785,7 +785,7 @@ with _SysPathG( Returns: model: nn.Layer. Specific `ResNeXt152_64x4d` model depends on args. """ - model = architectures.ResNeXt152_64x4d(**kwargs) + model = backbone.ResNeXt152_64x4d(**kwargs) if pretrained: model = _load_pretrained_parameters(model, 'ResNeXt152_64x4d') @@ -801,7 +801,7 @@ with _SysPathG( Returns: model: nn.Layer. Specific `ResNeXt50_32x4d` model depends on args. """ - model = architectures.ResNeXt50_32x4d(**kwargs) + model = backbone.ResNeXt50_32x4d(**kwargs) if pretrained: model = _load_pretrained_parameters(model, 'ResNeXt50_32x4d') @@ -817,8 +817,24 @@ with _SysPathG( Returns: model: nn.Layer. Specific `ResNeXt50_64x4d` model depends on args. """ - model = architectures.ResNeXt50_64x4d(**kwargs) + model = backbone.ResNeXt50_64x4d(**kwargs) if pretrained: model = _load_pretrained_parameters(model, 'ResNeXt50_64x4d') return model + + def darknet53(pretrained=False, **kwargs): + """ + DarkNet53 + Args: + pretrained: bool=False. If `True` load pretrained parameters, `False` otherwise. + kwargs: + class_dim: int=1000. Output dim of last fc layer. + Returns: + model: nn.Layer. Specific `ResNeXt50_64x4d` model depends on args. + """ + model = backbone.DarkNet53(**kwargs) + if pretrained: + model = _load_pretrained_parameters(model, 'DarkNet53') + + return model