提交 3ba45039 编写于 作者: B Bin Lu

Merge branch 'PaddlePaddle:develop_reg' into develop_reg

# LeViT
## 概述
LeViT是一种快速推理的、用于图像分类任务的混合神经网络。其设计之初考虑了网络模型在不同的硬件平台上的性能,因此能够更好地反映普遍应用的真实场景。通过大量实验,作者找到了卷积神经网络与Transformer体系更好的结合方式,并且提出了attention-based方法,用于整合Transformer中的位置信息编码。[论文地址](https://arxiv.org/abs/2104.01136)
## 精度、FLOPS和参数量
| Models | Top1 | Top5 | Reference<br>top1 | Reference<br>top5 | FLOPS<br>(M) | Params<br>(M) |
|:--:|:--:|:--:|:--:|:--:|:--:|:--:|
| LeViT-128S | 0.7598 | 0.9269 | 0.766 | 0.929 | 305 | 7.8 |
| LeViT-128 | 0.7810 | 0.9371 | 0.786 | 0.940 | 406 | 9.2 |
| LeViT-192 | 0.7934 | 0.9446 | 0.800 | 0.947 | 658 | 11 |
| LeViT-256 | 0.8085 | 0.9497 | 0.816 | 0.954 | 1120 | 19 |
| LeViT-384 | 0.8191 | 0.9551 | 0.826 | 0.960 | 2353 | 39 |
**注**:与Reference的精度差异源于数据预处理不同及未使用蒸馏的head作为输出。
# Twins
## 概述
Twins网络包括Twins-PCPVT和Twins-SVT,其重点对空间注意力机制进行了精心设计,得到了简单却更为有效的方案。由于该体系结构仅涉及矩阵乘法,而目前的深度学习框架中对矩阵乘法有较高的优化程度,因此该体系结构十分高效且易于实现。并且,该体系结构在图像分类、目标检测和语义分割等多种下游视觉任务中都能够取得优异的性能。[论文地址](https://arxiv.org/abs/2104.13840)
## 精度、FLOPS和参数量
| Models | Top1 | Top5 | Reference<br>top1 | Reference<br>top5 | FLOPS<br>(G) | Params<br>(M) |
|:--:|:--:|:--:|:--:|:--:|:--:|:--:|
| pcpvt_small | 0.8082 | 0.9552 | 0.812 | - | 3.7 | 24.1 |
| pcpvt_base | 0.8242 | 0.9619 | 0.827 | - | 6.4 | 43.8 |
| pcpvt_large | 0.8273 | 0.9650 | 0.831 | - | 9.5 | 60.9 |
| alt_gvt_small | 0.8140 | 0.9546 | 0.817 | - | 2.8 | 24 |
| alt_gvt_base | 0.8294 | 0.9621 | 0.832 | - | 8.3 | 56 |
| alt_gvt_large | 0.8331 | 0.9642 | 0.837 | - | 14.8 | 99.2 |
**注**:与Reference的精度差异源于数据预处理不同。
# copyright (c) 2020 PaddlePaddle Authors. All Rights Reserve.
# copyright (c) 2021 PaddlePaddle Authors. All Rights Reserve.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
......@@ -19,11 +19,12 @@ from ppcls.arch.backbone.legendary_models.vgg import VGG11, VGG13, VGG16, VGG19
from ppcls.arch.backbone.legendary_models.inception_v3 import InceptionV3
from ppcls.arch.backbone.legendary_models.hrnet import HRNet_W18_C, HRNet_W30_C, HRNet_W32_C, HRNet_W40_C, HRNet_W44_C, HRNet_W48_C, HRNet_W60_C, HRNet_W64_C, SE_HRNet_W64_C
from ppcls.arch.backbone.model_zoo.resnet_vc import ResNet18_vc, ResNet34_vc, ResNet50_vc, ResNet101_vc, ResNet152_vc
from ppcls.arch.backbone.model_zoo.resnet_vc import ResNet50_vc
from ppcls.arch.backbone.model_zoo.resnext import ResNeXt50_32x4d, ResNeXt50_64x4d, ResNeXt101_32x4d, ResNeXt101_64x4d, ResNeXt152_32x4d, ResNeXt152_64x4d
from ppcls.arch.backbone.model_zoo.res2net import Res2Net50_48w_2s, Res2Net50_26w_4s, Res2Net50_14w_8s, Res2Net50_48w_2s, Res2Net50_26w_6s, Res2Net50_26w_8s, Res2Net101_26w_4s, Res2Net152_26w_4s, Res2Net200_26w_4s
from ppcls.arch.backbone.model_zoo.res2net_vd import Res2Net50_vd_48w_2s, Res2Net50_vd_26w_4s, Res2Net50_vd_14w_8s, Res2Net50_vd_48w_2s, Res2Net50_vd_26w_6s, Res2Net50_vd_26w_8s, Res2Net101_vd_26w_4s, Res2Net152_vd_26w_4s, Res2Net200_vd_26w_4s
from ppcls.arch.backbone.model_zoo.se_resnet_vd import SE_ResNet18_vd, SE_ResNet34_vd, SE_ResNet50_vd, SE_ResNet101_vd, SE_ResNet152_vd, SE_ResNet200_vd
from ppcls.arch.backbone.model_zoo.resnext_vd import ResNeXt50_vd_32x4d, ResNeXt50_vd_64x4d, ResNeXt101_vd_32x4d, ResNeXt101_vd_64x4d, ResNeXt152_vd_32x4d, ResNeXt152_vd_64x4d
from ppcls.arch.backbone.model_zoo.res2net import Res2Net50_26w_4s, Res2Net50_14w_8s
from ppcls.arch.backbone.model_zoo.res2net_vd import Res2Net50_vd_26w_4s, Res2Net101_vd_26w_4s, Res2Net200_vd_26w_4s
from ppcls.arch.backbone.model_zoo.se_resnet_vd import SE_ResNet18_vd, SE_ResNet34_vd, SE_ResNet50_vd
from ppcls.arch.backbone.model_zoo.se_resnext_vd import SE_ResNeXt50_vd_32x4d, SE_ResNeXt50_vd_32x4d, SENet154_vd
from ppcls.arch.backbone.model_zoo.se_resnext import SE_ResNeXt50_32x4d, SE_ResNeXt101_32x4d, SE_ResNeXt152_64x4d
from ppcls.arch.backbone.model_zoo.dpn import DPN68, DPN92, DPN98, DPN107, DPN131
......@@ -33,10 +34,11 @@ from ppcls.arch.backbone.model_zoo.resnest import ResNeSt50_fast_1s1x64d, ResNeS
from ppcls.arch.backbone.model_zoo.googlenet import GoogLeNet
from ppcls.arch.backbone.model_zoo.mobilenet_v2 import MobileNetV2_x0_25, MobileNetV2_x0_5, MobileNetV2_x0_75, MobileNetV2, MobileNetV2_x1_5, MobileNetV2_x2_0
from ppcls.arch.backbone.model_zoo.shufflenet_v2 import ShuffleNetV2_x0_25, ShuffleNetV2_x0_33, ShuffleNetV2_x0_5, ShuffleNetV2_x1_0, ShuffleNetV2_x1_5, ShuffleNetV2_x2_0, ShuffleNetV2_swish
from ppcls.arch.backbone.model_zoo.ghostnet import GhostNet_x0_5, GhostNet_x1_0, GhostNet_x1_3
from ppcls.arch.backbone.model_zoo.alexnet import AlexNet
from ppcls.arch.backbone.model_zoo.inception_v4 import InceptionV4
from ppcls.arch.backbone.model_zoo.xception import Xception41, Xception65, Xception71
from ppcls.arch.backbone.model_zoo.xception_deeplab import Xception41_deeplab, Xception65_deeplab, Xception71_deeplab
from ppcls.arch.backbone.model_zoo.xception_deeplab import Xception41_deeplab, Xception65_deeplab
from ppcls.arch.backbone.model_zoo.resnext101_wsl import ResNeXt101_32x8d_wsl, ResNeXt101_32x16d_wsl, ResNeXt101_32x32d_wsl, ResNeXt101_32x48d_wsl
from ppcls.arch.backbone.model_zoo.squeezenet import SqueezeNet1_0, SqueezeNet1_1
from ppcls.arch.backbone.model_zoo.darknet import DarkNet53
......@@ -47,6 +49,8 @@ from ppcls.arch.backbone.model_zoo.distillation_models import ResNet50_vd_distil
from ppcls.arch.backbone.model_zoo.swin_transformer import SwinTransformer_tiny_patch4_window7_224, SwinTransformer_small_patch4_window7_224, SwinTransformer_base_patch4_window7_224, SwinTransformer_base_patch4_window12_384, SwinTransformer_large_patch4_window7_224, SwinTransformer_large_patch4_window12_384
from ppcls.arch.backbone.model_zoo.mixnet import MixNet_S, MixNet_M, MixNet_L
from ppcls.arch.backbone.model_zoo.rexnet import ReXNet_1_0, ReXNet_1_3, ReXNet_1_5, ReXNet_2_0, ReXNet_3_0
from ppcls.arch.backbone.model_zoo.gvt import pcpvt_small, pcpvt_base, pcpvt_large, alt_gvt_small, alt_gvt_base, alt_gvt_large
from ppcls.arch.backbone.model_zoo.levit import LeViT_128S, LeViT_128, LeViT_192, LeViT_256, LeViT_384
from ppcls.arch.backbone.model_zoo.dla import DLA34, DLA46_c, DLA46x_c, DLA60, DLA60x, DLA60x_c, DLA102, DLA102x, DLA102x2, DLA169
from ppcls.arch.backbone.model_zoo.rednet import RedNet26, RedNet38, RedNet50, RedNet101, RedNet152
from ppcls.arch.backbone.model_zoo.tnt import TNT_small
......
# copyright (c) 2021 PaddlePaddle Authors. All Rights Reserve.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
import paddle
from paddle import ParamAttr
import paddle.nn as nn
......@@ -7,8 +21,11 @@ from paddle.nn import AdaptiveAvgPool2D, MaxPool2D, AvgPool2D
from paddle.nn.initializer import Uniform
import math
__all__ = ["AlexNet"]
from ppcls.utils.save_load import load_dygraph_pretrain, load_dygraph_pretrain_from_url
MODEL_URLS = {"AlexNet": "https://paddle-imagenet-models-name.bj.bcebos.com/dygraph/AlexNet_pretrained.pdparams"}
__all__ = list(MODEL_URLS.keys())
class ConvPoolLayer(nn.Layer):
def __init__(self,
......@@ -126,7 +143,19 @@ class AlexNetDY(nn.Layer):
x = self._fc8(x)
return x
def _load_pretrained(pretrained, model, model_url, use_ssld=False):
if pretrained is False:
pass
elif pretrained is True:
load_dygraph_pretrain_from_url(model, model_url, use_ssld=use_ssld)
elif isinstance(pretrained, str):
load_dygraph_pretrain(model, pretrained)
else:
raise RuntimeError(
"pretrained type is not available. Please use `string` or `boolean` type."
)
def AlexNet(**args):
model = AlexNetDY(**args)
def AlexNet(pretrained=False, use_ssld=False, **kwargs):
model = AlexNetDY(**kwargs)
_load_pretrained(pretrained, model, MODEL_URLS["AlexNet"], use_ssld=use_ssld)
return model
# copyright (c) 2021 PaddlePaddle Authors. All Rights Reserve.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
import paddle
from paddle import ParamAttr
import paddle.nn as nn
......@@ -7,8 +21,11 @@ from paddle.nn import AdaptiveAvgPool2D, MaxPool2D, AvgPool2D
from paddle.nn.initializer import Uniform
import math
__all__ = ["DarkNet53"]
from ppcls.utils.save_load import load_dygraph_pretrain, load_dygraph_pretrain_from_url
MODEL_URLS = {"DarkNet53": "https://paddle-imagenet-models-name.bj.bcebos.com/dygraph/DarkNet53_pretrained.pdparams"}
__all__ = list(MODEL_URLS.keys())
class ConvBNLayer(nn.Layer):
def __init__(self,
......@@ -155,7 +172,19 @@ class DarkNet(nn.Layer):
x = self._out(x)
return x
def DarkNet53(**args):
model = DarkNet(**args)
def _load_pretrained(pretrained, model, model_url, use_ssld=False):
if pretrained is False:
pass
elif pretrained is True:
load_dygraph_pretrain_from_url(model, model_url, use_ssld=use_ssld)
elif isinstance(pretrained, str):
load_dygraph_pretrain(model, pretrained)
else:
raise RuntimeError(
"pretrained type is not available. Please use `string` or `boolean` type."
)
def DarkNet53(pretrained=False, use_ssld=False, **kwargs):
model = DarkNet(**kwargs)
_load_pretrained(pretrained, model, MODEL_URLS["DarkNet53"], use_ssld=use_ssld)
return model
# copyright (c) 2020 PaddlePaddle Authors. All Rights Reserve.
# copyright (c) 2021 PaddlePaddle Authors. All Rights Reserve.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
......@@ -26,9 +26,16 @@ from paddle.nn.initializer import Uniform
import math
__all__ = [
"DenseNet121", "DenseNet161", "DenseNet169", "DenseNet201", "DenseNet264"
]
from ppcls.utils.save_load import load_dygraph_pretrain, load_dygraph_pretrain_from_url
MODEL_URLS = {"DenseNet121": "https://paddle-imagenet-models-name.bj.bcebos.com/dygraph/DenseNet121_pretrained.pdparams",
"DenseNet161": "https://paddle-imagenet-models-name.bj.bcebos.com/dygraph/DenseNet161_pretrained.pdparams",
"DenseNet169": "https://paddle-imagenet-models-name.bj.bcebos.com/dygraph/DenseNet169_pretrained.pdparams",
"DenseNet201": "https://paddle-imagenet-models-name.bj.bcebos.com/dygraph/DenseNet201_pretrained.pdparams",
"DenseNet264": "https://paddle-imagenet-models-name.bj.bcebos.com/dygraph/DenseNet264_pretrained.pdparams",
}
__all__ = list(MODEL_URLS.keys())
class BNACConvLayer(nn.Layer):
......@@ -282,27 +289,43 @@ class DenseNet(nn.Layer):
y = self.out(y)
return y
def DenseNet121(**args):
model = DenseNet(layers=121, **args)
def _load_pretrained(pretrained, model, model_url, use_ssld=False):
if pretrained is False:
pass
elif pretrained is True:
load_dygraph_pretrain_from_url(model, model_url, use_ssld=use_ssld)
elif isinstance(pretrained, str):
load_dygraph_pretrain(model, pretrained)
else:
raise RuntimeError(
"pretrained type is not available. Please use `string` or `boolean` type."
)
def DenseNet121(pretrained=False, use_ssld=False, **kwargs):
model = DenseNet(layers=121, **kwargs)
_load_pretrained(pretrained, model, MODEL_URLS["DenseNet121"], use_ssld=use_ssld)
return model
def DenseNet161(**args):
model = DenseNet(layers=161, **args)
def DenseNet161(pretrained=False, use_ssld=False, **kwargs):
model = DenseNet(layers=161, **kwargs)
_load_pretrained(pretrained, model, MODEL_URLS["DenseNet161"], use_ssld=use_ssld)
return model
def DenseNet169(**args):
model = DenseNet(layers=169, **args)
def DenseNet169(pretrained=False, use_ssld=False, **kwargs):
model = DenseNet(layers=169, **kwargs)
_load_pretrained(pretrained, model, MODEL_URLS["DenseNet169"], use_ssld=use_ssld)
return model
def DenseNet201(**args):
model = DenseNet(layers=201, **args)
def DenseNet201(pretrained=False, use_ssld=False, **kwargs):
model = DenseNet(layers=201, **kwargs)
_load_pretrained(pretrained, model, MODEL_URLS["DenseNet201"], use_ssld=use_ssld)
return model
def DenseNet264(**args):
model = DenseNet(layers=264, **args)
def DenseNet264(pretrained=False, use_ssld=False, **kwargs):
model = DenseNet(layers=264, **kwargs)
_load_pretrained(pretrained, model, MODEL_URLS["DenseNet264"], use_ssld=use_ssld)
return model
......@@ -16,12 +16,20 @@ import paddle
import paddle.nn as nn
from .vision_transformer import VisionTransformer, Identity, trunc_normal_, zeros_
__all__ = [
'DeiT_tiny_patch16_224', 'DeiT_small_patch16_224', 'DeiT_base_patch16_224',
'DeiT_tiny_distilled_patch16_224', 'DeiT_small_distilled_patch16_224',
'DeiT_base_distilled_patch16_224', 'DeiT_base_patch16_384',
'DeiT_base_distilled_patch16_384'
]
from ppcls.utils.save_load import load_dygraph_pretrain, load_dygraph_pretrain_from_url
MODEL_URLS = {
"DeiT_tiny_patch16_224": "https://paddle-imagenet-models-name.bj.bcebos.com/dygraph/DeiT_tiny_patch16_224_pretrained.pdparams",
"DeiT_small_patch16_224": "https://paddle-imagenet-models-name.bj.bcebos.com/dygraph/DeiT_small_patch16_224_pretrained.pdparams",
"DeiT_base_patch16_224": "https://paddle-imagenet-models-name.bj.bcebos.com/dygraph/DeiT_base_patch16_224_pretrained.pdparams",
"DeiT_tiny_distilled_patch16_224": "https://paddle-imagenet-models-name.bj.bcebos.com/dygraph/DeiT_tiny_distilled_patch16_224_pretrained.pdparams",
"DeiT_small_distilled_patch16_224": "https://paddle-imagenet-models-name.bj.bcebos.com/dygraph/DeiT_small_distilled_patch16_224_pretrained.pdparams",
"DeiT_base_distilled_patch16_224": "https://paddle-imagenet-models-name.bj.bcebos.com/dygraph/DeiT_base_distilled_patch16_224_pretrained.pdparams",
"DeiT_base_patch16_384": "https://paddle-imagenet-models-name.bj.bcebos.com/dygraph/DeiT_base_patch16_384_pretrained.pdparams",
"DeiT_base_distilled_patch16_384": "https://paddle-imagenet-models-name.bj.bcebos.com/dygraph/DeiT_base_distilled_patch16_384_pretrained.pdparams",
}
__all__ = list(MODEL_URLS.keys())
class DistilledVisionTransformer(VisionTransformer):
......@@ -90,7 +98,20 @@ class DistilledVisionTransformer(VisionTransformer):
return (x + x_dist) / 2
def DeiT_tiny_patch16_224(**kwargs):
def _load_pretrained(pretrained, model, model_url, use_ssld=False):
if pretrained is False:
pass
elif pretrained is True:
load_dygraph_pretrain_from_url(model, model_url, use_ssld=use_ssld)
elif isinstance(pretrained, str):
load_dygraph_pretrain(model, pretrained)
else:
raise RuntimeError(
"pretrained type is not available. Please use `string` or `boolean` type."
)
def DeiT_tiny_patch16_224(pretrained=False, use_ssld=False, **kwargs):
model = VisionTransformer(
patch_size=16,
embed_dim=192,
......@@ -100,10 +121,11 @@ def DeiT_tiny_patch16_224(**kwargs):
qkv_bias=True,
epsilon=1e-6,
**kwargs)
_load_pretrained(pretrained, model, MODEL_URLS["DeiT_tiny_patch16_224"], use_ssld=use_ssld)
return model
def DeiT_small_patch16_224(**kwargs):
def DeiT_small_patch16_224(pretrained=False, use_ssld=False, **kwargs):
model = VisionTransformer(
patch_size=16,
embed_dim=384,
......@@ -113,10 +135,11 @@ def DeiT_small_patch16_224(**kwargs):
qkv_bias=True,
epsilon=1e-6,
**kwargs)
_load_pretrained(pretrained, model, MODEL_URLS["DeiT_small_patch16_224"], use_ssld=use_ssld)
return model
def DeiT_base_patch16_224(**kwargs):
def DeiT_base_patch16_224(pretrained=False, use_ssld=False, **kwargs):
model = VisionTransformer(
patch_size=16,
embed_dim=768,
......@@ -126,10 +149,11 @@ def DeiT_base_patch16_224(**kwargs):
qkv_bias=True,
epsilon=1e-6,
**kwargs)
_load_pretrained(pretrained, model, MODEL_URLS["DeiT_base_patch16_224"], use_ssld=use_ssld)
return model
def DeiT_tiny_distilled_patch16_224(**kwargs):
def DeiT_tiny_distilled_patch16_224(pretrained=False, use_ssld=False, **kwargs):
model = DistilledVisionTransformer(
patch_size=16,
embed_dim=192,
......@@ -139,10 +163,11 @@ def DeiT_tiny_distilled_patch16_224(**kwargs):
qkv_bias=True,
epsilon=1e-6,
**kwargs)
_load_pretrained(pretrained, model, MODEL_URLS["DeiT_tiny_distilled_patch16_224"], use_ssld=use_ssld)
return model
def DeiT_small_distilled_patch16_224(**kwargs):
def DeiT_small_distilled_patch16_224(pretrained=False, use_ssld=False, **kwargs):
model = DistilledVisionTransformer(
patch_size=16,
embed_dim=384,
......@@ -152,10 +177,11 @@ def DeiT_small_distilled_patch16_224(**kwargs):
qkv_bias=True,
epsilon=1e-6,
**kwargs)
_load_pretrained(pretrained, model, MODEL_URLS["DeiT_small_distilled_patch16_224"], use_ssld=use_ssld)
return model
def DeiT_base_distilled_patch16_224(**kwargs):
def DeiT_base_distilled_patch16_224(pretrained=False, use_ssld=False, **kwargs):
model = DistilledVisionTransformer(
patch_size=16,
embed_dim=768,
......@@ -165,10 +191,11 @@ def DeiT_base_distilled_patch16_224(**kwargs):
qkv_bias=True,
epsilon=1e-6,
**kwargs)
_load_pretrained(pretrained, model, MODEL_URLS["DeiT_base_distilled_patch16_224"], use_ssld=use_ssld)
return model
def DeiT_base_patch16_384(**kwargs):
def DeiT_base_patch16_384(pretrained=False, use_ssld=False, **kwargs):
model = VisionTransformer(
img_size=384,
patch_size=16,
......@@ -179,10 +206,11 @@ def DeiT_base_patch16_384(**kwargs):
qkv_bias=True,
epsilon=1e-6,
**kwargs)
_load_pretrained(pretrained, model, MODEL_URLS["DeiT_base_patch16_384"], use_ssld=use_ssld)
return model
def DeiT_base_distilled_patch16_384(**kwargs):
def DeiT_base_distilled_patch16_384(pretrained=False, use_ssld=False, **kwargs):
model = DistilledVisionTransformer(
img_size=384,
patch_size=16,
......@@ -193,4 +221,5 @@ def DeiT_base_distilled_patch16_384(**kwargs):
qkv_bias=True,
epsilon=1e-6,
**kwargs)
_load_pretrained(pretrained, model, MODEL_URLS["DeiT_base_distilled_patch16_384"], use_ssld=use_ssld)
return model
......@@ -26,25 +26,25 @@ from ppcls.utils.save_load import load_dygraph_pretrain, load_dygraph_pretrain_f
MODEL_URLS = {
"DLA34":
"https://paddle-imagenet-models-name.bj.bcebos.com/dygraph/model_zoo/DLA34_pretrained.pdparams",
"https://paddle-imagenet-models-name.bj.bcebos.com/dygraph/DLA34_pretrained.pdparams",
"DLA46_c":
"https://paddle-imagenet-models-name.bj.bcebos.com/dygraph/model_zoo/DLA46_c_pretrained.pdparams",
"https://paddle-imagenet-models-name.bj.bcebos.com/dygraph/DLA46_c_pretrained.pdparams",
"DLA46x_c":
"https://paddle-imagenet-models-name.bj.bcebos.com/dygraph/model_zoo/DLA46x_c_pretrained.pdparams",
"https://paddle-imagenet-models-name.bj.bcebos.com/dygraph/DLA46x_c_pretrained.pdparams",
"DLA60":
"https://paddle-imagenet-models-name.bj.bcebos.com/dygraph/model_zoo/DLA60_pretrained.pdparams",
"https://paddle-imagenet-models-name.bj.bcebos.com/dygraph/DLA60_pretrained.pdparams",
"DLA60x":
"https://paddle-imagenet-models-name.bj.bcebos.com/dygraph/model_zoo/DLA60x_pretrained.pdparams",
"https://paddle-imagenet-models-name.bj.bcebos.com/dygraph/DLA60x_pretrained.pdparams",
"DLA60x_c":
"https://paddle-imagenet-models-name.bj.bcebos.com/dygraph/model_zoo/DLA60x_c_pretrained.pdparams",
"https://paddle-imagenet-models-name.bj.bcebos.com/dygraph/DLA60x_c_pretrained.pdparams",
"DLA102":
"https://paddle-imagenet-models-name.bj.bcebos.com/dygraph/model_zoo/DLA102_pretrained.pdparams",
"https://paddle-imagenet-models-name.bj.bcebos.com/dygraph/DLA102_pretrained.pdparams",
"DLA102x":
"https://paddle-imagenet-models-name.bj.bcebos.com/dygraph/model_zoo/DLA102x_pretrained.pdparams",
"https://paddle-imagenet-models-name.bj.bcebos.com/dygraph/DLA102x_pretrained.pdparams",
"DLA102x2":
"https://paddle-imagenet-models-name.bj.bcebos.com/dygraph/model_zoo/DLA102x2_pretrained.pdparams",
"https://paddle-imagenet-models-name.bj.bcebos.com/dygraph/DLA102x2_pretrained.pdparams",
"DLA169":
"https://paddle-imagenet-models-name.bj.bcebos.com/dygraph/model_zoo/DLA169_pretrained.pdparams"
"https://paddle-imagenet-models-name.bj.bcebos.com/dygraph/DLA169_pretrained.pdparams"
}
......
......@@ -27,14 +27,16 @@ from paddle.nn.initializer import Uniform
import math
__all__ = [
"DPN",
"DPN68",
"DPN92",
"DPN98",
"DPN107",
"DPN131",
]
from ppcls.utils.save_load import load_dygraph_pretrain, load_dygraph_pretrain_from_url
MODEL_URLS = {"DPN68": "https://paddle-imagenet-models-name.bj.bcebos.com/dygraph/DPN68_pretrained.pdparams",
"DPN92": "https://paddle-imagenet-models-name.bj.bcebos.com/dygraph/DPN92_pretrained.pdparams",
"DPN98": "https://paddle-imagenet-models-name.bj.bcebos.com/dygraph/DPN98_pretrained.pdparams",
"DPN107": "https://paddle-imagenet-models-name.bj.bcebos.com/dygraph/DPN107_pretrained.pdparams",
"DPN131": "https://paddle-imagenet-models-name.bj.bcebos.com/dygraph/DPN131_pretrained.pdparams",
}
__all__ = list(MODEL_URLS.keys())
class ConvBNLayer(nn.Layer):
......@@ -398,28 +400,45 @@ class DPN(nn.Layer):
net_arg['init_padding'] = init_padding
return net_arg
def DPN68(**args):
model = DPN(layers=68, **args)
def _load_pretrained(pretrained, model, model_url, use_ssld=False):
if pretrained is False:
pass
elif pretrained is True:
load_dygraph_pretrain_from_url(model, model_url, use_ssld=use_ssld)
elif isinstance(pretrained, str):
load_dygraph_pretrain(model, pretrained)
else:
raise RuntimeError(
"pretrained type is not available. Please use `string` or `boolean` type."
)
def DPN68(pretrained=False, use_ssld=False, **kwargs):
model = DPN(layers=68, **kwargs)
_load_pretrained(pretrained, model, MODEL_URLS["DPN68"])
return model
def DPN92(**args):
model = DPN(layers=92, **args)
def DPN92(pretrained=False, use_ssld=False, **kwargs):
model = DPN(layers=92, **kwargs)
_load_pretrained(pretrained, model, MODEL_URLS["DPN92"])
return model
def DPN98(**args):
model = DPN(layers=98, **args)
def DPN98(pretrained=False, use_ssld=False, **kwargs):
model = DPN(layers=98, **kwargs)
_load_pretrained(pretrained, model, MODEL_URLS["DPN98"])
return model
def DPN107(**args):
model = DPN(layers=107, **args)
def DPN107(pretrained=False, use_ssld=False, **kwargs):
model = DPN(layers=107, **kwargs)
_load_pretrained(pretrained, model, MODEL_URLS["DPN107"])
return model
def DPN131(**args):
model = DPN(layers=131, **args)
return model
def DPN131(pretrained=False, use_ssld=False, **kwargs):
model = DPN(layers=131, **kwargs)
_load_pretrained(pretrained, model, MODEL_URLS["DPN131"])
return model
\ No newline at end of file
......@@ -9,11 +9,20 @@ import collections
import re
import copy
__all__ = [
'EfficientNet', 'EfficientNetB0_small', 'EfficientNetB0', 'EfficientNetB1',
'EfficientNetB2', 'EfficientNetB3', 'EfficientNetB4', 'EfficientNetB5',
'EfficientNetB6', 'EfficientNetB7'
]
from ppcls.utils.save_load import load_dygraph_pretrain, load_dygraph_pretrain_from_url
MODEL_URLS = {"EfficientNetB0_small": "https://paddle-imagenet-models-name.bj.bcebos.com/dygraph/EfficientNetB0_small_pretrained.pdparams",
"EfficientNetB0": "https://paddle-imagenet-models-name.bj.bcebos.com/dygraph/EfficientNetB0_pretrained.pdparams",
"EfficientNetB1": "https://paddle-imagenet-models-name.bj.bcebos.com/dygraph/EfficientNetB1_pretrained.pdparams",
"EfficientNetB2": "https://paddle-imagenet-models-name.bj.bcebos.com/dygraph/EfficientNetB2_pretrained.pdparams",
"EfficientNetB3": "https://paddle-imagenet-models-name.bj.bcebos.com/dygraph/EfficientNetB3_pretrained.pdparams",
"EfficientNetB4": "https://paddle-imagenet-models-name.bj.bcebos.com/dygraph/EfficientNetB4_pretrained.pdparams",
"EfficientNetB5": "https://paddle-imagenet-models-name.bj.bcebos.com/dygraph/EfficientNetB5_pretrained.pdparams",
"EfficientNetB6": "https://paddle-imagenet-models-name.bj.bcebos.com/dygraph/EfficientNetB6_pretrained.pdparams",
"EfficientNetB7": "https://paddle-imagenet-models-name.bj.bcebos.com/dygraph/EfficientNetB7_pretrained.pdparams",
}
__all__ = list(MODEL_URLS.keys())
GlobalParams = collections.namedtuple('GlobalParams', [
'batch_norm_momentum',
......@@ -783,119 +792,159 @@ class EfficientNet(nn.Layer):
x = self._fc(x)
return x
def _load_pretrained(pretrained, model, model_url, use_ssld=False):
if pretrained is False:
pass
elif pretrained is True:
load_dygraph_pretrain_from_url(model, model_url, use_ssld=use_ssld)
elif isinstance(pretrained, str):
load_dygraph_pretrain(model, pretrained)
else:
raise RuntimeError(
"pretrained type is not available. Please use `string` or `boolean` type."
)
def EfficientNetB0_small(padding_type='DYNAMIC',
override_params=None,
use_se=False,
**args):
pretrained=False,
use_ssld=False,
**kwargs):
model = EfficientNet(
name='b0',
padding_type=padding_type,
override_params=override_params,
use_se=use_se,
**args)
**kwargs)
_load_pretrained(pretrained, model, MODEL_URLS["EfficientNetB0_small"])
return model
def EfficientNetB0(padding_type='SAME',
override_params=None,
use_se=True,
**args):
pretrained=False,
use_ssld=False,
**kwargs):
model = EfficientNet(
name='b0',
padding_type=padding_type,
override_params=override_params,
use_se=use_se,
**args)
**kwargs)
_load_pretrained(pretrained, model, MODEL_URLS["EfficientNetB0"])
return model
def EfficientNetB1(padding_type='SAME',
override_params=None,
use_se=True,
**args):
pretrained=False,
use_ssld=False,
**kwargs):
model = EfficientNet(
name='b1',
padding_type=padding_type,
override_params=override_params,
use_se=use_se,
**args)
**kwargs)
_load_pretrained(pretrained, model, MODEL_URLS["EfficientNetB1"])
return model
def EfficientNetB2(padding_type='SAME',
override_params=None,
use_se=True,
**args):
pretrained=False,
use_ssld=False,
**kwargs):
model = EfficientNet(
name='b2',
padding_type=padding_type,
override_params=override_params,
use_se=use_se,
**args)
**kwargs)
_load_pretrained(pretrained, model, MODEL_URLS["EfficientNetB2"])
return model
def EfficientNetB3(padding_type='SAME',
override_params=None,
use_se=True,
**args):
pretrained=False,
use_ssld=False,
**kwargs):
model = EfficientNet(
name='b3',
padding_type=padding_type,
override_params=override_params,
use_se=use_se,
**args)
**kwargs)
_load_pretrained(pretrained, model, MODEL_URLS["EfficientNetB3"])
return model
def EfficientNetB4(padding_type='SAME',
override_params=None,
use_se=True,
**args):
pretrained=False,
use_ssld=False,
**kwargs):
model = EfficientNet(
name='b4',
padding_type=padding_type,
override_params=override_params,
use_se=use_se,
**args)
**kwargs)
_load_pretrained(pretrained, model, MODEL_URLS["EfficientNetB4"])
return model
def EfficientNetB5(padding_type='SAME',
override_params=None,
use_se=True,
**args):
pretrained=False,
use_ssld=False,
**kwargs):
model = EfficientNet(
name='b5',
padding_type=padding_type,
override_params=override_params,
use_se=use_se,
**args)
**kwargs)
_load_pretrained(pretrained, model, MODEL_URLS["EfficientNetB5"])
return model
def EfficientNetB6(padding_type='SAME',
override_params=None,
use_se=True,
**args):
pretrained=False,
use_ssld=False,
**kwargs):
model = EfficientNet(
name='b6',
padding_type=padding_type,
override_params=override_params,
use_se=use_se,
**args)
**kwargs)
_load_pretrained(pretrained, model, MODEL_URLS["EfficientNetB6"])
return model
def EfficientNetB7(padding_type='SAME',
override_params=None,
use_se=True,
**args):
pretrained=False,
use_ssld=False,
**kwargs):
model = EfficientNet(
name='b7',
padding_type=padding_type,
override_params=override_params,
use_se=use_se,
**args)
return model
**kwargs)
_load_pretrained(pretrained, model, MODEL_URLS["EfficientNetB7"])
return model
\ No newline at end of file
# copyright (c) 2020 PaddlePaddle Authors. All Rights Reserve.
# copyright (c) 2021 PaddlePaddle Authors. All Rights Reserve.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
......@@ -21,7 +21,14 @@ from paddle.nn import Conv2D, BatchNorm, AdaptiveAvgPool2D, Linear
from paddle.regularizer import L2Decay
from paddle.nn.initializer import Uniform, KaimingNormal
__all__ = ["GhostNet_x0_5", "GhostNet_x1_0", "GhostNet_x1_3"]
from ppcls.utils.save_load import load_dygraph_pretrain, load_dygraph_pretrain_from_url
MODEL_URLS = {"GhostNet_x0_5": "https://paddle-imagenet-models-name.bj.bcebos.com/dygraph/GhostNet_x0_5_pretrained.pdparams",
"GhostNet_x1_0": "https://paddle-imagenet-models-name.bj.bcebos.com/dygraph/GhostNet_x1_0_pretrained.pdparams",
"GhostNet_x1_3": "https://paddle-imagenet-models-name.bj.bcebos.com/dygraph/GhostNet_x1_3_pretrained.pdparams",
}
__all__ = list(MODEL_URLS.keys())
class ConvBNLayer(nn.Layer):
......@@ -315,17 +322,33 @@ class GhostNet(nn.Layer):
new_v += divisor
return new_v
def _load_pretrained(pretrained, model, model_url, use_ssld=False):
if pretrained is False:
pass
elif pretrained is True:
load_dygraph_pretrain_from_url(model, model_url, use_ssld=use_ssld)
elif isinstance(pretrained, str):
load_dygraph_pretrain(model, pretrained)
else:
raise RuntimeError(
"pretrained type is not available. Please use `string` or `boolean` type."
)
def GhostNet_x0_5(**args):
model = GhostNet(scale=0.5)
def GhostNet_x0_5(pretrained=False, use_ssld=False, **kwargs):
model = GhostNet(scale=0.5, **kwargs)
_load_pretrained(pretrained, model, MODEL_URLS["GhostNet_x0_5"], use_ssld=use_ssld)
return model
def GhostNet_x1_0(**args):
model = GhostNet(scale=1.0)
def GhostNet_x1_0(pretrained=False, use_ssld=False, **kwargs):
model = GhostNet(scale=1.0, **kwargs)
_load_pretrained(pretrained, model, MODEL_URLS["GhostNet_x1_0"], use_ssld=use_ssld)
return model
def GhostNet_x1_3(**args):
model = GhostNet(scale=1.3)
def GhostNet_x1_3(pretrained=False, use_ssld=False, **kwargs):
model = GhostNet(scale=1.3, **kwargs)
_load_pretrained(pretrained, model, MODEL_URLS["GhostNet_x1_3"], use_ssld=use_ssld)
return model
......@@ -8,7 +8,12 @@ from paddle.nn.initializer import Uniform
import math
__all__ = ['GoogLeNet']
from ppcls.utils.save_load import load_dygraph_pretrain, load_dygraph_pretrain_from_url
MODEL_URLS = {"GoogLeNet": "https://paddle-imagenet-models-name.bj.bcebos.com/dygraph/GoogLeNet_pretrained.pdparams",
}
__all__ = list(MODEL_URLS.keys())
def xavier(channels, filter_size, name):
......@@ -200,8 +205,22 @@ class GoogLeNetDY(nn.Layer):
x = self._drop_o2(x)
out2 = self._out2(x)
return [out, out1, out2]
def GoogLeNet(**args):
model = GoogLeNetDY(**args)
def _load_pretrained(pretrained, model, model_url, use_ssld=False):
if pretrained is False:
pass
elif pretrained is True:
load_dygraph_pretrain_from_url(model, model_url, use_ssld=use_ssld)
elif isinstance(pretrained, str):
load_dygraph_pretrain(model, pretrained)
else:
raise RuntimeError(
"pretrained type is not available. Please use `string` or `boolean` type."
)
def GoogLeNet(pretrained=False, use_ssld=False, **kwargs):
model = GoogLeNetDY(**kwargs)
_load_pretrained(pretrained, model, MODEL_URLS["GoogLeNet"], use_ssld=use_ssld)
return model
此差异已折叠。
......@@ -20,13 +20,13 @@ from ppcls.utils.save_load import load_dygraph_pretrain, load_dygraph_pretrain_f
MODEL_URLS = {
'HarDNet39_ds':
'https://paddle-imagenet-models-name.bj.bcebos.com/dygraph/model_zoo/HarDNet39_ds_pretrained.pdparams',
'https://paddle-imagenet-models-name.bj.bcebos.com/dygraph/HarDNet39_ds_pretrained.pdparams',
'HarDNet68_ds':
'https://paddle-imagenet-models-name.bj.bcebos.com/dygraph/model_zoo/HarDNet68_ds_pretrained.pdparams',
'https://paddle-imagenet-models-name.bj.bcebos.com/dygraph/HarDNet68_ds_pretrained.pdparams',
'HarDNet68':
'https://paddle-imagenet-models-name.bj.bcebos.com/dygraph/model_zoo/HarDNet68_pretrained.pdparams',
'https://paddle-imagenet-models-name.bj.bcebos.com/dygraph/HarDNet68_pretrained.pdparams',
'HarDNet85':
'https://paddle-imagenet-models-name.bj.bcebos.com/dygraph/model_zoo/HarDNet85_pretrained.pdparams'
'https://paddle-imagenet-models-name.bj.bcebos.com/dygraph/HarDNet85_pretrained.pdparams'
}
......
......@@ -27,24 +27,18 @@ from paddle.nn.initializer import Uniform
import math
__all__ = [
"HRNet_W18_C",
"HRNet_W30_C",
"HRNet_W32_C",
"HRNet_W40_C",
"HRNet_W44_C",
"HRNet_W48_C",
"HRNet_W60_C",
"HRNet_W64_C",
"SE_HRNet_W18_C",
"SE_HRNet_W30_C",
"SE_HRNet_W32_C",
"SE_HRNet_W40_C",
"SE_HRNet_W44_C",
"SE_HRNet_W48_C",
"SE_HRNet_W60_C",
"SE_HRNet_W64_C",
]
from ppcls.utils.save_load import load_dygraph_pretrain, load_dygraph_pretrain_from_url
MODEL_URLS = {"HRNet_W18_C": "https://paddle-imagenet-models-name.bj.bcebos.com/dygraph/HRNet_W18_C_pretrained.pdparams",
"HRNet_W30_C": "https://paddle-imagenet-models-name.bj.bcebos.com/dygraph/HRNet_W30_C_pretrained.pdparams",
"HRNet_W32_C": "https://paddle-imagenet-models-name.bj.bcebos.com/dygraph/HRNet_W32_C_pretrained.pdparams",
"HRNet_W40_C": "https://paddle-imagenet-models-name.bj.bcebos.com/dygraph/HRNet_W40_C_pretrained.pdparams",
"HRNet_W44_C": "https://paddle-imagenet-models-name.bj.bcebos.com/dygraph/HRNet_W44_C_pretrained.pdparams",
"HRNet_W48_C": "https://paddle-imagenet-models-name.bj.bcebos.com/dygraph/HRNet_W48_C_pretrained.pdparams",
"HRNet_W64_C": "https://paddle-imagenet-models-name.bj.bcebos.com/dygraph/HRNet_W64_C_pretrained.pdparams",
}
__all__ = list(MODEL_URLS.keys())
class ConvBNLayer(nn.Layer):
......@@ -661,82 +655,62 @@ class HRNet(nn.Layer):
y = self.out(y)
return y
def HRNet_W18_C(**args):
model = HRNet(width=18, **args)
return model
def HRNet_W30_C(**args):
model = HRNet(width=30, **args)
return model
def HRNet_W32_C(**args):
model = HRNet(width=32, **args)
return model
def HRNet_W40_C(**args):
model = HRNet(width=40, **args)
return model
def HRNet_W44_C(**args):
model = HRNet(width=44, **args)
return model
def HRNet_W48_C(**args):
model = HRNet(width=48, **args)
return model
def HRNet_W60_C(**args):
model = HRNet(width=60, **args)
return model
def HRNet_W64_C(**args):
model = HRNet(width=64, **args)
return model
def SE_HRNet_W18_C(**args):
model = HRNet(width=18, has_se=True, **args)
def _load_pretrained(pretrained, model, model_url, use_ssld=False):
if pretrained is False:
pass
elif pretrained is True:
load_dygraph_pretrain_from_url(model, model_url, use_ssld=use_ssld)
elif isinstance(pretrained, str):
load_dygraph_pretrain(model, pretrained)
else:
raise RuntimeError(
"pretrained type is not available. Please use `string` or `boolean` type."
)
def HRNet_W18_C(pretrained=False, use_ssld=False, **kwarg):
model = HRNet(width=18, **kwarg)
_load_pretrained(pretrained, model, MODEL_URLS["HRNet_W18_C"], use_ssld=use_ssld)
return model
def SE_HRNet_W30_C(**args):
model = HRNet(width=30, has_se=True, **args)
def HRNet_W30_C(pretrained=False, use_ssld=False, **kwarg):
model = HRNet(width=30, **kwarg)
_load_pretrained(pretrained, model, MODEL_URLS["HRNet_W30_C"], use_ssld=use_ssld)
return model
def SE_HRNet_W32_C(**args):
model = HRNet(width=32, has_se=True, **args)
def HRNet_W32_C(pretrained=False, use_ssld=False, **kwarg):
model = HRNet(width=32, **kwarg)
_load_pretrained(pretrained, model, MODEL_URLS["HRNet_W32_C"], use_ssld=use_ssld)
return model
def SE_HRNet_W40_C(**args):
model = HRNet(width=40, has_se=True, **args)
def HRNet_W40_C(pretrained=False, use_ssld=False, **kwarg):
model = HRNet(width=40, **kwarg)
_load_pretrained(pretrained, model, MODEL_URLS["HRNet_W40_C"], use_ssld=use_ssld)
return model
def SE_HRNet_W44_C(**args):
model = HRNet(width=44, has_se=True, **args)
def HRNet_W44_C(pretrained=False, use_ssld=False, **kwarg):
model = HRNet(width=44, **kwarg)
_load_pretrained(pretrained, model, MODEL_URLS["HRNet_W44_C"], use_ssld=use_ssld)
return model
def SE_HRNet_W48_C(**args):
model = HRNet(width=48, has_se=True, **args)
def HRNet_W48_C(pretrained=False, use_ssld=False, **kwarg):
model = HRNet(width=48, **kwarg)
_load_pretrained(pretrained, model, MODEL_URLS["HRNet_W48_C"], use_ssld=use_ssld)
return model
def SE_HRNet_W60_C(**args):
model = HRNet(width=60, has_se=True, **args)
def HRNet_W64_C(pretrained=False, use_ssld=False, **kwarg):
model = HRNet(width=64, **kwarg)
_load_pretrained(pretrained, model, MODEL_URLS["HRNet_W64_C"], use_ssld=use_ssld)
return model
def SE_HRNet_W64_C(**args):
model = HRNet(width=64, has_se=True, **args)
def SE_HRNet_W64_C(pretrained=False, use_ssld=False, **kwarg):
model = HRNet(width=64, **kwarg)
_load_pretrained(pretrained, model, MODEL_URLS["SE_HRNet_W64_C"], use_ssld=use_ssld)
return model
# copyright (c) 2020 PaddlePaddle Authors. All Rights Reserve.
# copyright (c) 2021 PaddlePaddle Authors. All Rights Reserve.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
......@@ -26,7 +26,11 @@ from paddle.nn import AdaptiveAvgPool2D, MaxPool2D, AvgPool2D
from paddle.nn.initializer import Uniform
import math
__all__ = ["InceptionV3"]
from ppcls.utils.save_load import load_dygraph_pretrain, load_dygraph_pretrain_from_url
MODEL_URLS = {"InceptionV3": "https://paddle-imagenet-models-name.bj.bcebos.com/dygraph/InceptionV3_pretrained.pdparams"}
__all__ = list(MODEL_URLS.keys())
class ConvBNLayer(nn.Layer):
......@@ -425,9 +429,9 @@ class InceptionE(nn.Layer):
return outputs
class InceptionV3(nn.Layer):
class Inception_V3(nn.Layer):
def __init__(self, class_dim=1000):
super(InceptionV3, self).__init__()
super(Inception_V3, self).__init__()
self.inception_a_list = [[192, 256, 288], [32, 64, 64]]
self.inception_c_list = [[768, 768, 768, 768], [128, 160, 160, 192]]
......@@ -472,10 +476,28 @@ class InceptionV3(nn.Layer):
def forward(self, x):
y = self.inception_stem(x)
for inception_block in self.inception_block_list:
y = inception_block(y)
y = inception_block(y)
y = self.gap(y)
y = paddle.reshape(y, shape=[-1, 2048])
y = self.drop(y)
y = self.out(y)
return y
def _load_pretrained(pretrained, model, model_url, use_ssld=False):
if pretrained is False:
pass
elif pretrained is True:
load_dygraph_pretrain_from_url(model, model_url, use_ssld=use_ssld)
elif isinstance(pretrained, str):
load_dygraph_pretrain(model, pretrained)
else:
raise RuntimeError(
"pretrained type is not available. Please use `string` or `boolean` type."
)
def InceptionV3(pretrained=False, use_ssld=False, **kwargs):
model = Inception_V3(**kwargs)
_load_pretrained(pretrained, model, MODEL_URLS["InceptionV3"], use_ssld=use_ssld)
return model
......@@ -21,7 +21,11 @@ from paddle.nn import AdaptiveAvgPool2D, MaxPool2D, AvgPool2D
from paddle.nn.initializer import Uniform
import math
__all__ = ["InceptionV4"]
from ppcls.utils.save_load import load_dygraph_pretrain, load_dygraph_pretrain_from_url
MODEL_URLS = {"InceptionV4": "https://paddle-imagenet-models-name.bj.bcebos.com/dygraph/InceptionV4_pretrained.pdparams"}
__all__ = list(MODEL_URLS.keys())
class ConvBNLayer(nn.Layer):
......@@ -450,6 +454,19 @@ class InceptionV4DY(nn.Layer):
return x
def InceptionV4(**args):
model = InceptionV4DY(**args)
def _load_pretrained(pretrained, model, model_url, use_ssld=False):
if pretrained is False:
pass
elif pretrained is True:
load_dygraph_pretrain_from_url(model, model_url, use_ssld=use_ssld)
elif isinstance(pretrained, str):
load_dygraph_pretrain(model, pretrained)
else:
raise RuntimeError(
"pretrained type is not available. Please use `string` or `boolean` type."
)
def InceptionV4(pretrained=False, use_ssld=False, **kwargs):
model = InceptionV4DY(**kwargs)
_load_pretrained(pretrained, model, MODEL_URLS["InceptionV4"], use_ssld=use_ssld)
return model
# copyright (c) 2021 PaddlePaddle Authors. All Rights Reserve.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
import itertools
import math
import warnings
import paddle
import paddle.nn as nn
import paddle.nn.functional as F
from paddle.nn.initializer import TruncatedNormal, Constant
from paddle.regularizer import L2Decay
from .vision_transformer import trunc_normal_, zeros_, ones_, Identity
from ppcls.utils.save_load import load_dygraph_pretrain, load_dygraph_pretrain_from_url
MODEL_URLS = {
"LeViT_128S": "https://paddle-imagenet-models-name.bj.bcebos.com/dygraph/LeViT_128S_pretrained.pdparams",
"LeViT_128": "https://paddle-imagenet-models-name.bj.bcebos.com/dygraph/LeViT_128_pretrained.pdparams",
"LeViT_192": "https://paddle-imagenet-models-name.bj.bcebos.com/dygraph/LeViT_192_pretrained.pdparams",
"LeViT_256": "https://paddle-imagenet-models-name.bj.bcebos.com/dygraph/LeViT_256_pretrained.pdparams",
"LeViT_384": "https://paddle-imagenet-models-name.bj.bcebos.com/dygraph/LeViT_384_pretrained.pdparams",
}
__all__ = list(MODEL_URLS.keys())
def cal_attention_biases(attention_biases, attention_bias_idxs):
gather_list = []
attention_bias_t = paddle.transpose(attention_biases, (1, 0))
for idx in attention_bias_idxs:
gather = paddle.gather(attention_bias_t, idx)
gather_list.append(gather)
shape0, shape1 = attention_bias_idxs.shape
return paddle.transpose(paddle.concat(gather_list), (1, 0)).reshape(
(0, shape0, shape1))
class Conv2d_BN(nn.Sequential):
def __init__(self,
a,
b,
ks=1,
stride=1,
pad=0,
dilation=1,
groups=1,
bn_weight_init=1,
resolution=-10000):
super().__init__()
self.add_sublayer(
'c',
nn.Conv2D(
a, b, ks, stride, pad, dilation, groups, bias_attr=False))
bn = nn.BatchNorm2D(b)
ones_(bn.weight)
zeros_(bn.bias)
self.add_sublayer('bn', bn)
class Linear_BN(nn.Sequential):
def __init__(self, a, b, bn_weight_init=1):
super().__init__()
self.add_sublayer('c', nn.Linear(a, b, bias_attr=False))
bn = nn.BatchNorm1D(b)
ones_(bn.weight)
zeros_(bn.bias)
self.add_sublayer('bn', bn)
def forward(self, x):
l, bn = self._sub_layers.values()
x = l(x)
return paddle.reshape(bn(x.flatten(0, 1)), x.shape)
class BN_Linear(nn.Sequential):
def __init__(self, a, b, bias=True, std=0.02):
super().__init__()
self.add_sublayer('bn', nn.BatchNorm1D(a))
l = nn.Linear(a, b, bias_attr=bias)
trunc_normal_(l.weight)
if bias:
zeros_(l.bias)
self.add_sublayer('l', l)
def b16(n, activation, resolution=224):
return nn.Sequential(
Conv2d_BN(
3, n // 8, 3, 2, 1, resolution=resolution),
activation(),
Conv2d_BN(
n // 8, n // 4, 3, 2, 1, resolution=resolution // 2),
activation(),
Conv2d_BN(
n // 4, n // 2, 3, 2, 1, resolution=resolution // 4),
activation(),
Conv2d_BN(
n // 2, n, 3, 2, 1, resolution=resolution // 8))
class Residual(nn.Layer):
def __init__(self, m, drop):
super().__init__()
self.m = m
self.drop = drop
def forward(self, x):
if self.training and self.drop > 0:
return x + self.m(x) * paddle.rand(
x.size(0), 1, 1,
device=x.device).ge_(self.drop).div(1 - self.drop).detach()
else:
return x + self.m(x)
class Attention(nn.Layer):
def __init__(self,
dim,
key_dim,
num_heads=8,
attn_ratio=4,
activation=None,
resolution=14):
super().__init__()
self.num_heads = num_heads
self.scale = key_dim**-0.5
self.key_dim = key_dim
self.nh_kd = nh_kd = key_dim * num_heads
self.d = int(attn_ratio * key_dim)
self.dh = int(attn_ratio * key_dim) * num_heads
self.attn_ratio = attn_ratio
self.h = self.dh + nh_kd * 2
self.qkv = Linear_BN(dim, self.h)
self.proj = nn.Sequential(
activation(), Linear_BN(
self.dh, dim, bn_weight_init=0))
points = list(itertools.product(range(resolution), range(resolution)))
N = len(points)
attention_offsets = {}
idxs = []
for p1 in points:
for p2 in points:
offset = (abs(p1[0] - p2[0]), abs(p1[1] - p2[1]))
if offset not in attention_offsets:
attention_offsets[offset] = len(attention_offsets)
idxs.append(attention_offsets[offset])
self.attention_biases = self.create_parameter(
shape=(num_heads, len(attention_offsets)),
default_initializer=zeros_,
attr=paddle.ParamAttr(regularizer=L2Decay(0.0)))
tensor_idxs = paddle.to_tensor(idxs, dtype='int64')
self.register_buffer('attention_bias_idxs',
paddle.reshape(tensor_idxs, [N, N]))
@paddle.no_grad()
def train(self, mode=True):
if mode:
super().train()
else:
super().eval()
if mode and hasattr(self, 'ab'):
del self.ab
else:
self.ab = cal_attention_biases(self.attention_biases,
self.attention_bias_idxs)
def forward(self, x):
self.training = True
B, N, C = x.shape
qkv = self.qkv(x)
qkv = paddle.reshape(qkv,
[B, N, self.num_heads, self.h // self.num_heads])
q, k, v = paddle.split(
qkv, [self.key_dim, self.key_dim, self.d], axis=3)
q = paddle.transpose(q, perm=[0, 2, 1, 3])
k = paddle.transpose(k, perm=[0, 2, 1, 3])
v = paddle.transpose(v, perm=[0, 2, 1, 3])
k_transpose = paddle.transpose(k, perm=[0, 1, 3, 2])
if self.training:
attention_biases = cal_attention_biases(self.attention_biases,
self.attention_bias_idxs)
else:
attention_biases = self.ab
attn = ((q @k_transpose) * self.scale + attention_biases)
attn = F.softmax(attn)
x = paddle.transpose(attn @v, perm=[0, 2, 1, 3])
x = paddle.reshape(x, [B, N, self.dh])
x = self.proj(x)
return x
class Subsample(nn.Layer):
def __init__(self, stride, resolution):
super().__init__()
self.stride = stride
self.resolution = resolution
def forward(self, x):
B, N, C = x.shape
x = paddle.reshape(x, [B, self.resolution, self.resolution,
C])[:, ::self.stride, ::self.stride]
x = paddle.reshape(x, [B, -1, C])
return x
class AttentionSubsample(nn.Layer):
def __init__(self,
in_dim,
out_dim,
key_dim,
num_heads=8,
attn_ratio=2,
activation=None,
stride=2,
resolution=14,
resolution_=7):
super().__init__()
self.num_heads = num_heads
self.scale = key_dim**-0.5
self.key_dim = key_dim
self.nh_kd = nh_kd = key_dim * num_heads
self.d = int(attn_ratio * key_dim)
self.dh = int(attn_ratio * key_dim) * self.num_heads
self.attn_ratio = attn_ratio
self.resolution_ = resolution_
self.resolution_2 = resolution_**2
self.training = True
h = self.dh + nh_kd
self.kv = Linear_BN(in_dim, h)
self.q = nn.Sequential(
Subsample(stride, resolution), Linear_BN(in_dim, nh_kd))
self.proj = nn.Sequential(activation(), Linear_BN(self.dh, out_dim))
self.stride = stride
self.resolution = resolution
points = list(itertools.product(range(resolution), range(resolution)))
points_ = list(
itertools.product(range(resolution_), range(resolution_)))
N = len(points)
N_ = len(points_)
attention_offsets = {}
idxs = []
i = 0
j = 0
for p1 in points_:
i += 1
for p2 in points:
j += 1
size = 1
offset = (abs(p1[0] * stride - p2[0] + (size - 1) / 2),
abs(p1[1] * stride - p2[1] + (size - 1) / 2))
if offset not in attention_offsets:
attention_offsets[offset] = len(attention_offsets)
idxs.append(attention_offsets[offset])
self.attention_biases = self.create_parameter(
shape=(num_heads, len(attention_offsets)),
default_initializer=zeros_,
attr=paddle.ParamAttr(regularizer=L2Decay(0.0)))
tensor_idxs_ = paddle.to_tensor(idxs, dtype='int64')
self.register_buffer('attention_bias_idxs',
paddle.reshape(tensor_idxs_, [N_, N]))
@paddle.no_grad()
def train(self, mode=True):
if mode:
super().train()
else:
super().eval()
if mode and hasattr(self, 'ab'):
del self.ab
else:
self.ab = cal_attention_biases(self.attention_biases,
self.attention_bias_idxs)
def forward(self, x):
self.training = True
B, N, C = x.shape
kv = self.kv(x)
kv = paddle.reshape(kv, [B, N, self.num_heads, -1])
k, v = paddle.split(kv, [self.key_dim, self.d], axis=3)
k = paddle.transpose(k, perm=[0, 2, 1, 3]) # BHNC
v = paddle.transpose(v, perm=[0, 2, 1, 3])
q = paddle.reshape(
self.q(x), [B, self.resolution_2, self.num_heads, self.key_dim])
q = paddle.transpose(q, perm=[0, 2, 1, 3])
if self.training:
attention_biases = cal_attention_biases(self.attention_biases,
self.attention_bias_idxs)
else:
attention_biases = self.ab
attn = (q @paddle.transpose(
k, perm=[0, 1, 3, 2])) * self.scale + attention_biases
attn = F.softmax(attn)
x = paddle.reshape(
paddle.transpose(
(attn @v), perm=[0, 2, 1, 3]), [B, -1, self.dh])
x = self.proj(x)
return x
class LeViT(nn.Layer):
""" Vision Transformer with support for patch or hybrid CNN input stage
"""
def __init__(self,
img_size=224,
patch_size=16,
in_chans=3,
class_dim=1000,
embed_dim=[192],
key_dim=[64],
depth=[12],
num_heads=[3],
attn_ratio=[2],
mlp_ratio=[2],
hybrid_backbone=None,
down_ops=[],
attention_activation=nn.Hardswish,
mlp_activation=nn.Hardswish,
distillation=True,
drop_path=0):
super().__init__()
self.class_dim = class_dim
self.num_features = embed_dim[-1]
self.embed_dim = embed_dim
self.distillation = distillation
self.patch_embed = hybrid_backbone
self.blocks = []
down_ops.append([''])
resolution = img_size // patch_size
for i, (ed, kd, dpth, nh, ar, mr, do) in enumerate(
zip(embed_dim, key_dim, depth, num_heads, attn_ratio,
mlp_ratio, down_ops)):
for _ in range(dpth):
self.blocks.append(
Residual(
Attention(
ed,
kd,
nh,
attn_ratio=ar,
activation=attention_activation,
resolution=resolution, ),
drop_path))
if mr > 0:
h = int(ed * mr)
self.blocks.append(
Residual(
nn.Sequential(
Linear_BN(ed, h),
mlp_activation(),
Linear_BN(
h, ed, bn_weight_init=0), ),
drop_path))
if do[0] == 'Subsample':
#('Subsample',key_dim, num_heads, attn_ratio, mlp_ratio, stride)
resolution_ = (resolution - 1) // do[5] + 1
self.blocks.append(
AttentionSubsample(
*embed_dim[i:i + 2],
key_dim=do[1],
num_heads=do[2],
attn_ratio=do[3],
activation=attention_activation,
stride=do[5],
resolution=resolution,
resolution_=resolution_))
resolution = resolution_
if do[4] > 0: # mlp_ratio
h = int(embed_dim[i + 1] * do[4])
self.blocks.append(
Residual(
nn.Sequential(
Linear_BN(embed_dim[i + 1], h),
mlp_activation(),
Linear_BN(
h, embed_dim[i + 1], bn_weight_init=0), ),
drop_path))
self.blocks = nn.Sequential(*self.blocks)
# Classifier head
self.head = BN_Linear(embed_dim[-1],
class_dim) if class_dim > 0 else Identity()
if distillation:
self.head_dist = BN_Linear(
embed_dim[-1], class_dim) if class_dim > 0 else Identity()
def forward(self, x):
x = self.patch_embed(x)
x = x.flatten(2)
x = paddle.transpose(x, perm=[0, 2, 1])
x = self.blocks(x)
x = x.mean(1)
if self.distillation:
x = self.head(x), self.head_dist(x)
if not self.training:
x = (x[0] + x[1]) / 2
else:
x = self.head(x)
return x
def model_factory(C, D, X, N, drop_path, class_dim, distillation):
embed_dim = [int(x) for x in C.split('_')]
num_heads = [int(x) for x in N.split('_')]
depth = [int(x) for x in X.split('_')]
act = nn.Hardswish
model = LeViT(
patch_size=16,
embed_dim=embed_dim,
num_heads=num_heads,
key_dim=[D] * 3,
depth=depth,
attn_ratio=[2, 2, 2],
mlp_ratio=[2, 2, 2],
down_ops=[
#('Subsample',key_dim, num_heads, attn_ratio, mlp_ratio, stride)
['Subsample', D, embed_dim[0] // D, 4, 2, 2],
['Subsample', D, embed_dim[1] // D, 4, 2, 2],
],
attention_activation=act,
mlp_activation=act,
hybrid_backbone=b16(embed_dim[0], activation=act),
class_dim=class_dim,
drop_path=drop_path,
distillation=distillation)
return model
specification = {
'LeViT_128S': {
'C': '128_256_384',
'D': 16,
'N': '4_6_8',
'X': '2_3_4',
'drop_path': 0
},
'LeViT_128': {
'C': '128_256_384',
'D': 16,
'N': '4_8_12',
'X': '4_4_4',
'drop_path': 0
},
'LeViT_192': {
'C': '192_288_384',
'D': 32,
'N': '3_5_6',
'X': '4_4_4',
'drop_path': 0
},
'LeViT_256': {
'C': '256_384_512',
'D': 32,
'N': '4_6_8',
'X': '4_4_4',
'drop_path': 0
},
'LeViT_384': {
'C': '384_512_768',
'D': 32,
'N': '6_9_12',
'X': '4_4_4',
'drop_path': 0.1
},
}
def _load_pretrained(pretrained, model, model_url, use_ssld=False):
if pretrained is False:
pass
elif pretrained is True:
load_dygraph_pretrain_from_url(model, model_url, use_ssld=use_ssld)
elif isinstance(pretrained, str):
load_dygraph_pretrain(model, pretrained)
else:
raise RuntimeError(
"pretrained type is not available. Please use `string` or `boolean` type."
)
def LeViT_128S(pretrained=False, use_ssld=False, class_dim=1000, distillation=False, **kwargs):
model = model_factory(
**specification['LeViT_128S'],
class_dim=class_dim,
distillation=distillation)
_load_pretrained(pretrained, model, MODEL_URLS["LeViT_128S"], use_ssld=use_ssld)
return model
def LeViT_128(pretrained=False, use_ssld=False, class_dim=1000, distillation=False, **kwargs):
model = model_factory(
**specification['LeViT_128'],
class_dim=class_dim,
distillation=distillation)
_load_pretrained(pretrained, model, MODEL_URLS["LeViT_128"], use_ssld=use_ssld)
return model
def LeViT_192(pretrained=False, use_ssld=False, class_dim=1000, distillation=False, **kwargs):
model = model_factory(
**specification['LeViT_192'],
class_dim=class_dim,
distillation=distillation)
_load_pretrained(pretrained, model, MODEL_URLS["LeViT_192"], use_ssld=use_ssld)
return model
def LeViT_256(pretrained=False, use_ssld=False, class_dim=1000, distillation=False, **kwargs):
model = model_factory(
**specification['LeViT_256'],
class_dim=class_dim,
distillation=distillation)
_load_pretrained(pretrained, model, MODEL_URLS["LeViT_256"], use_ssld=use_ssld)
return model
def LeViT_384(pretrained=False, use_ssld=False, class_dim=1000, distillation=False, **kwargs):
model = model_factory(
**specification['LeViT_384'],
class_dim=class_dim,
distillation=distillation)
_load_pretrained(pretrained, model, MODEL_URLS["LeViT_384"], use_ssld=use_ssld)
return model
......@@ -17,14 +17,20 @@
https://arxiv.org/abs/1907.09595.
"""
__all__ = ['MixNet_S', 'MixNet_M', 'MixNet_L']
import os
from inspect import isfunction
from functools import reduce
import paddle
import paddle.nn as nn
from ppcls.utils.save_load import load_dygraph_pretrain, load_dygraph_pretrain_from_url
MODEL_URLS = {"MixNet_S": "https://paddle-imagenet-models-name.bj.bcebos.com/dygraph/MixNet_S_pretrained.pdparams",
"MixNet_M": "https://paddle-imagenet-models-name.bj.bcebos.com/dygraph/MixNet_M_pretrained.pdparams",
"MixNet_L": "https://paddle-imagenet-models-name.bj.bcebos.com/dygraph/MixNet_L_pretrained.pdparams"}
__all__ = list(MODEL_URLS.keys())
class Identity(nn.Layer):
"""
......@@ -755,13 +761,33 @@ def get_mixnet(version, width_scale, model_name=None, **kwargs):
return net
def _load_pretrained(pretrained, model, model_url, use_ssld=False):
if pretrained is False:
pass
elif pretrained is True:
load_dygraph_pretrain_from_url(model, model_url, use_ssld=use_ssld)
elif isinstance(pretrained, str):
load_dygraph_pretrain(model, pretrained)
else:
raise RuntimeError(
"pretrained type is not available. Please use `string` or `boolean` type."
)
def MixNet_S(pretrained=False, use_ssld=False, **kwargs):
model = InceptionV4DY(**kwargs)
_load_pretrained(pretrained, model, MODEL_URLS["InceptionV4"], use_ssld=use_ssld)
return model
def MixNet_S(**kwargs):
"""
MixNet-S model from 'MixConv: Mixed Depthwise Convolutional Kernels,'
https://arxiv.org/abs/1907.09595.
"""
return get_mixnet(
model = get_mixnet(
version="s", width_scale=1.0, model_name="MixNet_S", **kwargs)
_load_pretrained(pretrained, model, MODEL_URLS["MixNet_S"], use_ssld=use_ssld)
return model
def MixNet_M(**kwargs):
......@@ -769,14 +795,19 @@ def MixNet_M(**kwargs):
MixNet-M model from 'MixConv: Mixed Depthwise Convolutional Kernels,'
https://arxiv.org/abs/1907.09595.
"""
return get_mixnet(
model = get_mixnet(
version="m", width_scale=1.0, model_name="MixNet_M", **kwargs)
_load_pretrained(pretrained, model, MODEL_URLS["MixNet_M"], use_ssld=use_ssld)
return model
def MixNet_L(**kwargs):
"""
MixNet-L model from 'MixConv: Mixed Depthwise Convolutional Kernels,'
MixNet-S model from 'MixConv: Mixed Depthwise Convolutional Kernels,'
https://arxiv.org/abs/1907.09595.
"""
return get_mixnet(
model = get_mixnet(
version="m", width_scale=1.3, model_name="MixNet_L", **kwargs)
_load_pretrained(pretrained, model, MODEL_URLS["MixNet_L"], use_ssld=use_ssld)
return model
......@@ -26,9 +26,14 @@ from paddle.nn import AdaptiveAvgPool2D, MaxPool2D, AvgPool2D
from paddle.nn.initializer import KaimingNormal
import math
__all__ = [
"MobileNetV1_x0_25", "MobileNetV1_x0_5", "MobileNetV1_x0_75", "MobileNetV1"
]
from ppcls.utils.save_load import load_dygraph_pretrain, load_dygraph_pretrain_from_url
MODEL_URLS = {"MobileNetV1_x0_25": "https://paddle-imagenet-models-name.bj.bcebos.com/dygraph/MobileNetV1_x0_25_pretrained.pdparams",
"MobileNetV1_x0_5": "https://paddle-imagenet-models-name.bj.bcebos.com/dygraph/MobileNetV1_x0_5_pretrained.pdparams",
"MobileNetV1_x0_75": "https://paddle-imagenet-models-name.bj.bcebos.com/dygraph/MobileNetV1_x0_75_pretrained.pdparams",
"MobileNetV1": "https://paddle-imagenet-models-name.bj.bcebos.com/dygraph/MobileNetV1_pretrained.pdparams"}
__all__ = list(MODEL_URLS.keys())
class ConvBNLayer(nn.Layer):
......@@ -245,22 +250,39 @@ class MobileNet(nn.Layer):
y = self.out(y)
return y
def MobileNetV1_x0_25(**args):
model = MobileNet(scale=0.25, **args)
def _load_pretrained(pretrained, model, model_url, use_ssld=False):
if pretrained is False:
pass
elif pretrained is True:
load_dygraph_pretrain_from_url(model, model_url, use_ssld=use_ssld)
elif isinstance(pretrained, str):
load_dygraph_pretrain(model, pretrained)
else:
raise RuntimeError(
"pretrained type is not available. Please use `string` or `boolean` type."
)
def MobileNetV1_x0_25(pretrained=False, use_ssld=False, **kwargs):
model = MobileNet(scale=0.25, **kwargs)
_load_pretrained(pretrained, model, MODEL_URLS["MobileNetV1_x0_25"], use_ssld=use_ssld)
return model
def MobileNetV1_x0_5(**args):
model = MobileNet(scale=0.5, **args)
def MobileNetV1_x0_5(pretrained=False, use_ssld=False, **kwargs):
model = MobileNet(scale=0.5, **kwargs)
_load_pretrained(pretrained, model, MODEL_URLS["MobileNetV1_x0_5"], use_ssld=use_ssld)
return model
def MobileNetV1_x0_75(**args):
model = MobileNet(scale=0.75, **args)
def MobileNetV1_x0_75(pretrained=False, use_ssld=False, **kwargs):
model = MobileNet(scale=0.75, **kwargs)
_load_pretrained(pretrained, model, MODEL_URLS["MobileNetV1_x0_75"], use_ssld=use_ssld)
return model
def MobileNetV1(**args):
model = MobileNet(scale=1.0, **args)
return model
def MobileNetV1(pretrained=False, use_ssld=False, **kwargs):
model = MobileNet(scale=1.0, **kwargs)
_load_pretrained(pretrained, model, MODEL_URLS["MobileNetV1"], use_ssld=use_ssld)
return model
\ No newline at end of file
......@@ -26,10 +26,16 @@ from paddle.nn import AdaptiveAvgPool2D, MaxPool2D, AvgPool2D
import math
__all__ = [
"MobileNetV2_x0_25", "MobileNetV2_x0_5", "MobileNetV2_x0_75",
"MobileNetV2", "MobileNetV2_x1_5", "MobileNetV2_x2_0"
]
from ppcls.utils.save_load import load_dygraph_pretrain, load_dygraph_pretrain_from_url
MODEL_URLS = {"MobileNetV2_x0_25": "https://paddle-imagenet-models-name.bj.bcebos.com/dygraph/MobileNetV2_x0_25_pretrained.pdparams",
"MobileNetV2_x0_5": "https://paddle-imagenet-models-name.bj.bcebos.com/dygraph/MobileNetV2_x0_5_pretrained.pdparams",
"MobileNetV2_x0_75": "https://paddle-imagenet-models-name.bj.bcebos.com/dygraph/MobileNetV2_x0_75_pretrained.pdparams",
"MobileNetV2": "https://paddle-imagenet-models-name.bj.bcebos.com/dygraph/MobileNetV2_pretrained.pdparams",
"MobileNetV2_x1_5": "https://paddle-imagenet-models-name.bj.bcebos.com/dygraph/MobileNetV2_x1_5_pretrained.pdparams",
"MobileNetV2_x2_0": "https://paddle-imagenet-models-name.bj.bcebos.com/dygraph/MobileNetV2_x2_0_pretrained.pdparams"}
__all__ = list(MODEL_URLS.keys())
class ConvBNLayer(nn.Layer):
......@@ -149,7 +155,7 @@ class InvresiBlocks(nn.Layer):
class MobileNet(nn.Layer):
def __init__(self, class_dim=1000, scale=1.0, prefix_name="", **args):
def __init__(self, class_dim=1000, scale=1.0, prefix_name=""):
super(MobileNet, self).__init__()
self.scale = scale
self.class_dim = class_dim
......@@ -216,33 +222,52 @@ class MobileNet(nn.Layer):
y = paddle.flatten(y, start_axis=1, stop_axis=-1)
y = self.out(y)
return y
def MobileNetV2_x0_25(**args):
model = MobileNet(scale=0.25, **args)
def _load_pretrained(pretrained, model, model_url, use_ssld=False):
if pretrained is False:
pass
elif pretrained is True:
load_dygraph_pretrain_from_url(model, model_url, use_ssld=use_ssld)
elif isinstance(pretrained, str):
load_dygraph_pretrain(model, pretrained)
else:
raise RuntimeError(
"pretrained type is not available. Please use `string` or `boolean` type."
)
def MobileNetV2_x0_25(pretrained=False, use_ssld=False, **kwargs):
model = MobileNet(scale=0.25, **kwargs)
_load_pretrained(pretrained, model, MODEL_URLS["MobileNetV2_x0_25"], use_ssld=use_ssld)
return model
def MobileNetV2_x0_5(**args):
model = MobileNet(scale=0.5, **args)
def MobileNetV2_x0_5(pretrained=False, use_ssld=False, **kwargs):
model = MobileNet(scale=0.5, **kwargs)
_load_pretrained(pretrained, model, MODEL_URLS["MobileNetV2_x0_5"], use_ssld=use_ssld)
return model
def MobileNetV2_x0_75(**args):
model = MobileNet(scale=0.75, **args)
def MobileNetV2_x0_75(pretrained=False, use_ssld=False, **kwargs):
model = MobileNet(scale=0.75, **kwargs)
_load_pretrained(pretrained, model, MODEL_URLS["MobileNetV2_x0_75"], use_ssld=use_ssld)
return model
def MobileNetV2(**args):
model = MobileNet(scale=1.0, **args)
def MobileNetV2(pretrained=False, use_ssld=False, **kwargs):
model = MobileNet(scale=1.0, **kwargs)
_load_pretrained(pretrained, model, MODEL_URLS["MobileNetV2"], use_ssld=use_ssld)
return model
def MobileNetV2_x1_5(**args):
model = MobileNet(scale=1.5, **args)
def MobileNetV2_x1_5(pretrained=False, use_ssld=False, **kwargs):
model = MobileNet(scale=1.5, **kwargs)
_load_pretrained(pretrained, model, MODEL_URLS["MobileNetV2_x1_5"], use_ssld=use_ssld)
return model
def MobileNetV2_x2_0(**args):
model = MobileNet(scale=2.0, **args)
def MobileNetV2_x2_0(pretrained=False, use_ssld=False, **kwargs):
model = MobileNet(scale=2.0, **kwargs)
_load_pretrained(pretrained, model, MODEL_URLS["MobileNetV2_x2_0"], use_ssld=use_ssld)
return model
......@@ -28,13 +28,20 @@ from paddle.regularizer import L2Decay
import math
__all__ = [
"MobileNetV3_small_x0_35", "MobileNetV3_small_x0_5",
"MobileNetV3_small_x0_75", "MobileNetV3_small_x1_0",
"MobileNetV3_small_x1_25", "MobileNetV3_large_x0_35",
"MobileNetV3_large_x0_5", "MobileNetV3_large_x0_75",
"MobileNetV3_large_x1_0", "MobileNetV3_large_x1_25"
]
from ppcls.utils.save_load import load_dygraph_pretrain, load_dygraph_pretrain_from_url
MODEL_URLS = {"MobileNetV3_small_x0_35": "https://paddle-imagenet-models-name.bj.bcebos.com/dygraph/MobileNetV3_small_x0_35_pretrained.pdparams",
"MobileNetV3_small_x0_5": "https://paddle-imagenet-models-name.bj.bcebos.com/dygraph/MobileNetV3_small_x0_5_pretrained.pdparams",
"MobileNetV3_small_x0_75": "https://paddle-imagenet-models-name.bj.bcebos.com/dygraph/MobileNetV3_small_x0_75_pretrained.pdparams",
"MobileNetV3_small_x1_0": "https://paddle-imagenet-models-name.bj.bcebos.com/dygraph/MobileNetV3_small_x1_0_pretrained.pdparams",
"MobileNetV3_small_x1_25": "https://paddle-imagenet-models-name.bj.bcebos.com/dygraph/MobileNetV3_small_x1_25_pretrained.pdparams",
"MobileNetV3_large_x0_35": "https://paddle-imagenet-models-name.bj.bcebos.com/dygraph/MobileNetV3_large_x0_35_pretrained.pdparams",
"MobileNetV3_large_x0_5": "https://paddle-imagenet-models-name.bj.bcebos.com/dygraph/MobileNetV3_large_x0_5_pretrained.pdparams",
"MobileNetV3_large_x0_75": "https://paddle-imagenet-models-name.bj.bcebos.com/dygraph/MobileNetV3_large_x0_75_pretrained.pdparams",
"MobileNetV3_large_x1_0": "https://paddle-imagenet-models-name.bj.bcebos.com/dygraph/MobileNetV3_large_x1_0_pretrained.pdparams",
"MobileNetV3_large_x1_25": "https://paddle-imagenet-models-name.bj.bcebos.com/dygraph/MobileNetV3_large_x1_25_pretrained.pdparams"}
__all__ = list(MODEL_URLS.keys())
def make_divisible(v, divisor=8, min_value=None):
......@@ -308,52 +315,75 @@ class SEModule(nn.Layer):
outputs = hardsigmoid(outputs, slope=0.2, offset=0.5)
return paddle.multiply(x=inputs, y=outputs)
def MobileNetV3_small_x0_35(**args):
model = MobileNetV3(model_name="small", scale=0.35, **args)
def _load_pretrained(pretrained, model, model_url, use_ssld=False):
if pretrained is False:
pass
elif pretrained is True:
load_dygraph_pretrain_from_url(model, model_url, use_ssld=use_ssld)
elif isinstance(pretrained, str):
load_dygraph_pretrain(model, pretrained)
else:
raise RuntimeError(
"pretrained type is not available. Please use `string` or `boolean` type."
)
def MobileNetV3_small_x0_35(pretrained=False, use_ssld=False, **kwargs):
model = MobileNetV3(model_name="small", scale=0.35, **kwargs)
_load_pretrained(pretrained, model, MODEL_URLS["MobileNetV3_small_x0_35"], use_ssld=use_ssld)
return model
def MobileNetV3_small_x0_5(**args):
model = MobileNetV3(model_name="small", scale=0.5, **args)
def MobileNetV3_small_x0_5(pretrained=False, use_ssld=False, **kwargs):
model = MobileNetV3(model_name="small", scale=0.5, **kwargs)
_load_pretrained(pretrained, model, MODEL_URLS["MobileNetV3_small_x0_5"], use_ssld=use_ssld)
return model
def MobileNetV3_small_x0_75(**args):
model = MobileNetV3(model_name="small", scale=0.75, **args)
def MobileNetV3_small_x0_75(pretrained=False, use_ssld=False, **kwargs):
model = MobileNetV3(model_name="small", scale=0.75, **kwargs)
_load_pretrained(pretrained, model, MODEL_URLS["MobileNetV3_small_x0_75"], use_ssld=use_ssld)
return model
def MobileNetV3_small_x1_0(**args):
model = MobileNetV3(model_name="small", scale=1.0, **args)
def MobileNetV3_small_x1_0(pretrained=False, use_ssld=False, **kwargs):
model = MobileNetV3(model_name="small", scale=1.0, **kwargs)
_load_pretrained(pretrained, model, MODEL_URLS["MobileNetV3_small_x1_0"], use_ssld=use_ssld)
return model
def MobileNetV3_small_x1_25(**args):
model = MobileNetV3(model_name="small", scale=1.25, **args)
def MobileNetV3_small_x1_25(pretrained=False, use_ssld=False, **kwargs):
model = MobileNetV3(model_name="small", scale=1.25, **kwargs)
_load_pretrained(pretrained, model, MODEL_URLS["MobileNetV3_small_x1_25"], use_ssld=use_ssld)
return model
def MobileNetV3_large_x0_35(**args):
model = MobileNetV3(model_name="large", scale=0.35, **args)
def MobileNetV3_large_x0_35(pretrained=False, use_ssld=False, **kwargs):
model = MobileNetV3(model_name="large", scale=0.35, **kwargs)
_load_pretrained(pretrained, model, MODEL_URLS["MobileNetV3_large_x0_35"], use_ssld=use_ssld)
return model
def MobileNetV3_large_x0_5(**args):
model = MobileNetV3(model_name="large", scale=0.5, **args)
def MobileNetV3_large_x0_5(pretrained=False, use_ssld=False, **kwargs):
model = MobileNetV3(model_name="large", scale=0.5, **kwargs)
_load_pretrained(pretrained, model, MODEL_URLS["MobileNetV3_large_x0_5"], use_ssld=use_ssld)
return model
def MobileNetV3_large_x0_75(**args):
model = MobileNetV3(model_name="large", scale=0.75, **args)
def MobileNetV3_large_x0_75(pretrained=False, use_ssld=False, **kwargs):
model = MobileNetV3(model_name="large", scale=0.75, **kwargs)
_load_pretrained(pretrained, model, MODEL_URLS["MobileNetV3_large_x0_75"], use_ssld=use_ssld)
return model
def MobileNetV3_large_x1_0(**args):
model = MobileNetV3(model_name="large", scale=1.0, **args)
def MobileNetV3_large_x1_0(pretrained=False, use_ssld=False, **kwargs):
model = MobileNetV3(model_name="large", scale=1.0, **kwargs)
_load_pretrained(pretrained, model, MODEL_URLS["MobileNetV3_large_x1_0"], use_ssld=use_ssld)
return model
def MobileNetV3_large_x1_25(**args):
model = MobileNetV3(model_name="large", scale=1.25, **args)
def MobileNetV3_large_x1_25(pretrained=False, use_ssld=False, **kwargs):
model = MobileNetV3(model_name="large", scale=1.25, **kwargs)
_load_pretrained(pretrained, model, MODEL_URLS["MobileNetV3_large_x1_25"], use_ssld=use_ssld)
return model
......@@ -22,15 +22,15 @@ from ppcls.utils.save_load import load_dygraph_pretrain, load_dygraph_pretrain_f
MODEL_URLS = {
"RedNet26":
"https://paddle-imagenet-models-name.bj.bcebos.com/dygraph/model_zoo/RedNet26_pretrained.pdparams",
"https://paddle-imagenet-models-name.bj.bcebos.com/dygraph/RedNet26_pretrained.pdparams",
"RedNet38":
"https://paddle-imagenet-models-name.bj.bcebos.com/dygraph/model_zoo/RedNet38_pretrained.pdparams",
"https://paddle-imagenet-models-name.bj.bcebos.com/dygraph/RedNet38_pretrained.pdparams",
"RedNet50":
"https://paddle-imagenet-models-name.bj.bcebos.com/dygraph/model_zoo/RedNet50_pretrained.pdparams",
"https://paddle-imagenet-models-name.bj.bcebos.com/dygraph/RedNet50_pretrained.pdparams",
"RedNet101":
"https://paddle-imagenet-models-name.bj.bcebos.com/dygraph/model_zoo/RedNet101_pretrained.pdparams",
"https://paddle-imagenet-models-name.bj.bcebos.com/dygraph/RedNet101_pretrained.pdparams",
"RedNet152":
"https://paddle-imagenet-models-name.bj.bcebos.com/dygraph/model_zoo/RedNet152_pretrained.pdparams"
"https://paddle-imagenet-models-name.bj.bcebos.com/dygraph/RedNet152_pretrained.pdparams"
}
......
......@@ -26,10 +26,17 @@ from paddle.nn import AdaptiveAvgPool2D, MaxPool2D, AvgPool2D
from paddle.nn.initializer import Uniform
import math
__all__ = [
"RegNetX_200MF", "RegNetX_4GF", "RegNetX_32GF", "RegNetY_200MF",
"RegNetY_4GF", "RegNetY_32GF"
]
from ppcls.utils.save_load import load_dygraph_pretrain, load_dygraph_pretrain_from_url
MODEL_URLS = {"RegNetX_200MF": "https://paddle-imagenet-models-name.bj.bcebos.com/dygraph/RegNetX_200MF_pretrained.pdparams",
"RegNetX_4GF": "https://paddle-imagenet-models-name.bj.bcebos.com/dygraph/RegNetX_4GF_pretrained.pdparams",
"RegNetX_32GF": "https://paddle-imagenet-models-name.bj.bcebos.com/dygraph/RegNetX_32GF_pretrained.pdparams",
"RegNetY_200MF": "https://paddle-imagenet-models-name.bj.bcebos.com/dygraph/RegNetY_200MF_pretrained.pdparams",
"RegNetY_4GF": "https://paddle-imagenet-models-name.bj.bcebos.com/dygraph/RegNetY_4GF_pretrained.pdparams",
"RegNetY_32GF": "https://paddle-imagenet-models-name.bj.bcebos.com/dygraph/RegNetY_32GF_pretrained.pdparams",
}
__all__ = list(MODEL_URLS.keys())
def quantize_float(f, q):
......@@ -308,14 +315,28 @@ class RegNet(nn.Layer):
y = self.out(y)
return y
def RegNetX_200MF(**args):
def _load_pretrained(pretrained, model, model_url, use_ssld=False):
if pretrained is False:
pass
elif pretrained is True:
load_dygraph_pretrain_from_url(model, model_url, use_ssld=use_ssld)
elif isinstance(pretrained, str):
load_dygraph_pretrain(model, pretrained)
else:
raise RuntimeError(
"pretrained type is not available. Please use `string` or `boolean` type."
)
def RegNetX_200MF(pretrained=False, use_ssld=False, **kwargs):
model = RegNet(
w_a=36.44, w_0=24, w_m=2.49, d=13, group_w=8, bot_mul=1.0, q=8, **args)
w_a=36.44, w_0=24, w_m=2.49, d=13, group_w=8, bot_mul=1.0, q=8, **kwargs)
_load_pretrained(pretrained, model, MODEL_URLS["RegNetX_200MF"], use_ssld=use_ssld)
return model
def RegNetX_4GF(**args):
def RegNetX_4GF(pretrained=False, use_ssld=False, **kwargs):
model = RegNet(
w_a=38.65,
w_0=96,
......@@ -324,11 +345,12 @@ def RegNetX_4GF(**args):
group_w=40,
bot_mul=1.0,
q=8,
**args)
**kwargs)
_load_pretrained(pretrained, model, MODEL_URLS["RegNetX_4GF"], use_ssld=use_ssld)
return model
def RegNetX_32GF(**args):
def RegNetX_32GF(pretrained=False, use_ssld=False, **kwargs):
model = RegNet(
w_a=69.86,
w_0=320,
......@@ -337,11 +359,12 @@ def RegNetX_32GF(**args):
group_w=168,
bot_mul=1.0,
q=8,
**args)
**kwargs)
_load_pretrained(pretrained, model, MODEL_URLS["RegNetX_32GF"], use_ssld=use_ssld)
return model
def RegNetY_200MF(**args):
def RegNetY_200MF(pretrained=False, use_ssld=False, **kwargs):
model = RegNet(
w_a=36.44,
w_0=24,
......@@ -351,11 +374,12 @@ def RegNetY_200MF(**args):
bot_mul=1.0,
q=8,
se_on=True,
**args)
**kwargs)
_load_pretrained(pretrained, model, MODEL_URLS["RegNetX_32GF"], use_ssld=use_ssld)
return model
def RegNetY_4GF(**args):
def RegNetY_4GF(pretrained=False, use_ssld=False, **kwargs):
model = RegNet(
w_a=31.41,
w_0=96,
......@@ -365,11 +389,12 @@ def RegNetY_4GF(**args):
bot_mul=1.0,
q=8,
se_on=True,
**args)
**kwargs)
_load_pretrained(pretrained, model, MODEL_URLS["RegNetX_32GF"], use_ssld=use_ssld)
return model
def RegNetY_32GF(**args):
def RegNetY_32GF(pretrained=False, use_ssld=False, **kwargs):
model = RegNet(
w_a=115.89,
w_0=232,
......@@ -379,5 +404,6 @@ def RegNetY_32GF(**args):
bot_mul=1.0,
q=8,
se_on=True,
**args)
**kwargs)
_load_pretrained(pretrained, model, MODEL_URLS["RegNetX_32GF"], use_ssld=use_ssld)
return model
......@@ -2,22 +2,29 @@ import paddle.nn as nn
import paddle
import numpy as np
__all__ = [
'RepVGG',
'RepVGG_A0',
'RepVGG_A1',
'RepVGG_A2',
'RepVGG_B0',
'RepVGG_B1',
'RepVGG_B2',
'RepVGG_B3',
'RepVGG_B1g2',
'RepVGG_B1g4',
'RepVGG_B2g2',
'RepVGG_B2g4',
'RepVGG_B3g2',
'RepVGG_B3g4',
]
from ppcls.utils.save_load import load_dygraph_pretrain, load_dygraph_pretrain_from_url
MODEL_URLS = {"RepVGG_A0": "https://paddle-imagenet-models-name.bj.bcebos.com/dygraph/RepVGG_A0_pretrained.pdparams",
"RepVGG_A1": "https://paddle-imagenet-models-name.bj.bcebos.com/dygraph/RepVGG_A1_pretrained.pdparams",
"RepVGG_A2": "https://paddle-imagenet-models-name.bj.bcebos.com/dygraph/RepVGG_A2_pretrained.pdparams",
"RepVGG_B0": "https://paddle-imagenet-models-name.bj.bcebos.com/dygraph/RepVGG_B0_pretrained.pdparams",
"RepVGG_B1": "https://paddle-imagenet-models-name.bj.bcebos.com/dygraph/RepVGG_B1_pretrained.pdparams",
"RepVGG_B2": "https://paddle-imagenet-models-name.bj.bcebos.com/dygraph/RepVGG_B2_pretrained.pdparams",
"RepVGG_B3": "https://paddle-imagenet-models-name.bj.bcebos.com/dygraph/RepVGG_B3_pretrained.pdparams",
"RepVGG_B1g2": "https://paddle-imagenet-models-name.bj.bcebos.com/dygraph/RepVGG_B1g2_pretrained.pdparams",
"RepVGG_B1g4": "https://paddle-imagenet-models-name.bj.bcebos.com/dygraph/RepVGG_B1g4_pretrained.pdparams",
"RepVGG_B2g2": "https://paddle-imagenet-models-name.bj.bcebos.com/dygraph/RepVGG_B2g2_pretrained.pdparams",
"RepVGG_B2g4": "https://paddle-imagenet-models-name.bj.bcebos.com/dygraph/RepVGG_B2g4_pretrained.pdparams",
"RepVGG_B3g2": "https://paddle-imagenet-models-name.bj.bcebos.com/dygraph/RepVGG_B3g2_pretrained.pdparams",
"RepVGG_B3g4": "https://paddle-imagenet-models-name.bj.bcebos.com/dygraph/RepVGG_B3g4_pretrained.pdparams",
}
__all__ = list(MODEL_URLS.keys())
optional_groupwise_layers = [2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 24, 26]
g2_map = {l: 2 for l in optional_groupwise_layers}
g4_map = {l: 4 for l in optional_groupwise_layers}
class ConvBN(nn.Layer):
......@@ -230,110 +237,144 @@ class RepVGG(nn.Layer):
return out
optional_groupwise_layers = [2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 24, 26]
g2_map = {l: 2 for l in optional_groupwise_layers}
g4_map = {l: 4 for l in optional_groupwise_layers}
def RepVGG_A0(**kwargs):
return RepVGG(
def _load_pretrained(pretrained, model, model_url, use_ssld=False):
if pretrained is False:
pass
elif pretrained is True:
load_dygraph_pretrain_from_url(model, model_url, use_ssld=use_ssld)
elif isinstance(pretrained, str):
load_dygraph_pretrain(model, pretrained)
else:
raise RuntimeError(
"pretrained type is not available. Please use `string` or `boolean` type."
)
def RepVGG_A0(pretrained=False, use_ssld=False, **kwargs):
model = RepVGG(
num_blocks=[2, 4, 14, 1],
width_multiplier=[0.75, 0.75, 0.75, 2.5],
override_groups_map=None,
**kwargs)
_load_pretrained(pretrained, model, MODEL_URLS["RepVGG_A0"], use_ssld=use_ssld)
return model
def RepVGG_A1(**kwargs):
return RepVGG(
def RepVGG_A1(pretrained=False, use_ssld=False, **kwargs):
model = RepVGG(
num_blocks=[2, 4, 14, 1],
width_multiplier=[1, 1, 1, 2.5],
override_groups_map=None,
**kwargs)
_load_pretrained(pretrained, model, MODEL_URLS["RepVGG_A1"], use_ssld=use_ssld)
return model
def RepVGG_A2(**kwargs):
return RepVGG(
def RepVGG_A2(pretrained=False, use_ssld=False, **kwargs):
model = RepVGG(
num_blocks=[2, 4, 14, 1],
width_multiplier=[1.5, 1.5, 1.5, 2.75],
override_groups_map=None,
**kwargs)
_load_pretrained(pretrained, model, MODEL_URLS["RepVGG_A2"], use_ssld=use_ssld)
return model
def RepVGG_B0(**kwargs):
return RepVGG(
def RepVGG_B0(pretrained=False, use_ssld=False, **kwargs):
model = RepVGG(
num_blocks=[4, 6, 16, 1],
width_multiplier=[1, 1, 1, 2.5],
override_groups_map=None,
**kwargs)
_load_pretrained(pretrained, model, MODEL_URLS["RepVGG_B0"], use_ssld=use_ssld)
return model
def RepVGG_B1(**kwargs):
return RepVGG(
def RepVGG_B1(pretrained=False, use_ssld=False, **kwargs):
model = RepVGG(
num_blocks=[4, 6, 16, 1],
width_multiplier=[2, 2, 2, 4],
override_groups_map=None,
**kwargs)
_load_pretrained(pretrained, model, MODEL_URLS["RepVGG_B1"], use_ssld=use_ssld)
return model
def RepVGG_B1g2(**kwargs):
return RepVGG(
def RepVGG_B1g2(pretrained=False, use_ssld=False, **kwargs):
model = RepVGG(
num_blocks=[4, 6, 16, 1],
width_multiplier=[2, 2, 2, 4],
override_groups_map=g2_map,
**kwargs)
_load_pretrained(pretrained, model, MODEL_URLS["RepVGG_B1g2"], use_ssld=use_ssld)
return model
def RepVGG_B1g4(**kwargs):
return RepVGG(
def RepVGG_B1g4(pretrained=False, use_ssld=False, **kwargs):
model = RepVGG(
num_blocks=[4, 6, 16, 1],
width_multiplier=[2, 2, 2, 4],
override_groups_map=g4_map,
**kwargs)
_load_pretrained(pretrained, model, MODEL_URLS["RepVGG_B1g4"], use_ssld=use_ssld)
return model
def RepVGG_B2(**kwargs):
return RepVGG(
def RepVGG_B2(pretrained=False, use_ssld=False, **kwargs):
model = RepVGG(
num_blocks=[4, 6, 16, 1],
width_multiplier=[2.5, 2.5, 2.5, 5],
override_groups_map=None,
**kwargs)
_load_pretrained(pretrained, model, MODEL_URLS["RepVGG_B2"], use_ssld=use_ssld)
return model
def RepVGG_B2g2(**kwargs):
return RepVGG(
def RepVGG_B2g2(pretrained=False, use_ssld=False, **kwargs):
model = RepVGG(
num_blocks=[4, 6, 16, 1],
width_multiplier=[2.5, 2.5, 2.5, 5],
override_groups_map=g2_map,
**kwargs)
_load_pretrained(pretrained, model, MODEL_URLS["RepVGG_B2g2"], use_ssld=use_ssld)
return model
def RepVGG_B2g4(**kwargs):
return RepVGG(
def RepVGG_B2g4(pretrained=False, use_ssld=False, **kwargs):
model = RepVGG(
num_blocks=[4, 6, 16, 1],
width_multiplier=[2.5, 2.5, 2.5, 5],
override_groups_map=g4_map,
**kwargs)
_load_pretrained(pretrained, model, MODEL_URLS["RepVGG_B2g4"], use_ssld=use_ssld)
return model
def RepVGG_B3(**kwargs):
return RepVGG(
def RepVGG_B3(pretrained=False, use_ssld=False, **kwargs):
model = RepVGG(
num_blocks=[4, 6, 16, 1],
width_multiplier=[3, 3, 3, 5],
override_groups_map=None,
**kwargs)
_load_pretrained(pretrained, model, MODEL_URLS["RepVGG_B3"], use_ssld=use_ssld)
return model
def RepVGG_B3g2(**kwargs):
return RepVGG(
def RepVGG_B3g2(pretrained=False, use_ssld=False, **kwargs):
model = RepVGG(
num_blocks=[4, 6, 16, 1],
width_multiplier=[3, 3, 3, 5],
override_groups_map=g2_map,
**kwargs)
_load_pretrained(pretrained, model, MODEL_URLS["RepVGG_B3g2"], use_ssld=use_ssld)
return model
def RepVGG_B3g4(**kwargs):
return RepVGG(
def RepVGG_B3g4(pretrained=False, use_ssld=False, **kwargs):
model = RepVGG(
num_blocks=[4, 6, 16, 1],
width_multiplier=[3, 3, 3, 5],
override_groups_map=g4_map,
**kwargs)
_load_pretrained(pretrained, model, MODEL_URLS["RepVGG_B3g4"], use_ssld=use_ssld)
return model
......@@ -27,11 +27,13 @@ from paddle.nn.initializer import Uniform
import math
__all__ = [
"Res2Net50_48w_2s", "Res2Net50_26w_4s", "Res2Net50_14w_8s",
"Res2Net50_48w_2s", "Res2Net50_26w_6s", "Res2Net50_26w_8s",
"Res2Net101_26w_4s", "Res2Net152_26w_4s", "Res2Net200_26w_4s"
]
from ppcls.utils.save_load import load_dygraph_pretrain, load_dygraph_pretrain_from_url
MODEL_URLS = {"Res2Net50_26w_4s": "https://paddle-imagenet-models-name.bj.bcebos.com/dygraph/Res2Net50_26w_4s_pretrained.pdparams",
"Res2Net50_14w_8s": "https://paddle-imagenet-models-name.bj.bcebos.com/dygraph/Res2Net50_14w_8s_pretrained.pdparams",
}
__all__ = list(MODEL_URLS.keys())
class ConvBNLayer(nn.Layer):
......@@ -232,41 +234,26 @@ class Res2Net(nn.Layer):
return y
def Res2Net50_48w_2s(**args):
model = Res2Net(layers=50, scales=2, width=48, **args)
return model
def Res2Net50_26w_4s(**args):
model = Res2Net(layers=50, scales=4, width=26, **args)
return model
def Res2Net50_14w_8s(**args):
model = Res2Net(layers=50, scales=8, width=14, **args)
return model
def Res2Net50_26w_6s(**args):
model = Res2Net(layers=50, scales=6, width=26, **args)
def _load_pretrained(pretrained, model, model_url, use_ssld=False):
if pretrained is False:
pass
elif pretrained is True:
load_dygraph_pretrain_from_url(model, model_url, use_ssld=use_ssld)
elif isinstance(pretrained, str):
load_dygraph_pretrain(model, pretrained)
else:
raise RuntimeError(
"pretrained type is not available. Please use `string` or `boolean` type."
)
def Res2Net50_26w_4s(pretrained=False, use_ssld=False, **kwargs):
model = Res2Net(layers=50, scales=4, width=26, **kwargs)
_load_pretrained(pretrained, model, MODEL_URLS["Res2Net50_26w_4s"], use_ssld=use_ssld)
return model
def Res2Net50_26w_8s(**args):
model = Res2Net(layers=50, scales=8, width=26, **args)
return model
def Res2Net101_26w_4s(**args):
model = Res2Net(layers=101, scales=4, width=26, **args)
return model
def Res2Net152_26w_4s(**args):
model = Res2Net(layers=152, scales=4, width=26, **args)
return model
def Res2Net200_26w_4s(**args):
model = Res2Net(layers=200, scales=4, width=26, **args)
return model
def Res2Net50_14w_8s(pretrained=False, use_ssld=False, **kwargs):
model = Res2Net(layers=50, scales=8, width=14, **kwargs)
_load_pretrained(pretrained, model, MODEL_URLS["Res2Net50_14w_8s"], use_ssld=use_ssld)
return model
\ No newline at end of file
......@@ -27,11 +27,14 @@ from paddle.nn.initializer import Uniform
import math
__all__ = [
"Res2Net50_vd_48w_2s", "Res2Net50_vd_26w_4s", "Res2Net50_vd_14w_8s",
"Res2Net50_vd_48w_2s", "Res2Net50_vd_26w_6s", "Res2Net50_vd_26w_8s",
"Res2Net101_vd_26w_4s", "Res2Net152_vd_26w_4s", "Res2Net200_vd_26w_4s"
]
from ppcls.utils.save_load import load_dygraph_pretrain, load_dygraph_pretrain_from_url
MODEL_URLS = {"Res2Net50_vd_26w_4s": "https://paddle-imagenet-models-name.bj.bcebos.com/dygraph/Res2Net50_vd_26w_4s_pretrained.pdparams",
"Res2Net101_vd_26w_4s": "https://paddle-imagenet-models-name.bj.bcebos.com/dygraph/Res2Net101_vd_26w_4s_pretrained.pdparams",
"Res2Net200_vd_26w_4s": "https://paddle-imagenet-models-name.bj.bcebos.com/dygraph/Res2Net200_vd_26w_4s_pretrained.pdparams",
}
__all__ = list(MODEL_URLS.keys())
class ConvBNLayer(nn.Layer):
......@@ -255,41 +258,32 @@ class Res2Net_vd(nn.Layer):
return y
def Res2Net50_vd_48w_2s(**args):
model = Res2Net_vd(layers=50, scales=2, width=48, **args)
return model
def Res2Net50_vd_26w_4s(**args):
model = Res2Net_vd(layers=50, scales=4, width=26, **args)
return model
def Res2Net50_vd_14w_8s(**args):
model = Res2Net_vd(layers=50, scales=8, width=14, **args)
return model
def Res2Net50_vd_26w_6s(**args):
model = Res2Net_vd(layers=50, scales=6, width=26, **args)
return model
def _load_pretrained(pretrained, model, model_url, use_ssld=False):
if pretrained is False:
pass
elif pretrained is True:
load_dygraph_pretrain_from_url(model, model_url, use_ssld=use_ssld)
elif isinstance(pretrained, str):
load_dygraph_pretrain(model, pretrained)
else:
raise RuntimeError(
"pretrained type is not available. Please use `string` or `boolean` type."
)
def Res2Net50_vd_26w_8s(**args):
model = Res2Net_vd(layers=50, scales=8, width=26, **args)
def Res2Net50_vd_26w_4s(pretrained=False, use_ssld=False, **kwargs):
model = Res2Net_vd(layers=50, scales=4, width=26, **kwargs)
_load_pretrained(pretrained, model, MODEL_URLS["Res2Net50_vd_26w_4s"], use_ssld=use_ssld)
return model
def Res2Net101_vd_26w_4s(**args):
model = Res2Net_vd(layers=101, scales=4, width=26, **args)
def Res2Net101_vd_26w_4s(pretrained=False, use_ssld=False, **kwargs):
model = Res2Net_vd(layers=101, scales=4, width=26, **kwargs)
_load_pretrained(pretrained, model, MODEL_URLS["Res2Net101_vd_26w_4s"], use_ssld=use_ssld)
return model
def Res2Net152_vd_26w_4s(**args):
model = Res2Net_vd(layers=152, scales=4, width=26, **args)
return model
def Res2Net200_vd_26w_4s(**args):
model = Res2Net_vd(layers=200, scales=4, width=26, **args)
return model
def Res2Net200_vd_26w_4s(pretrained=False, use_ssld=False, **kwargs):
model = Res2Net_vd(layers=200, scales=4, width=26, **kwargs)
_load_pretrained(pretrained, model, MODEL_URLS["Res2Net200_vd_26w_4s"], use_ssld=use_ssld)
return model
\ No newline at end of file
......@@ -27,7 +27,14 @@ from paddle.nn import Conv2D, BatchNorm, Linear, Dropout
from paddle.nn import AdaptiveAvgPool2D, MaxPool2D, AvgPool2D
from paddle.regularizer import L2Decay
__all__ = ["ResNeSt50_fast_1s1x64d", "ResNeSt50", "ResNeSt101"]
from ppcls.utils.save_load import load_dygraph_pretrain, load_dygraph_pretrain_from_url
MODEL_URLS = {"ResNeSt50_fast_1s1x64d": "https://paddle-imagenet-models-name.bj.bcebos.com/dygraph/ResNeSt50_fast_1s1x64d_pretrained.pdparams",
"ResNeSt50": "https://paddle-imagenet-models-name.bj.bcebos.com/dygraph/ResNeSt50_pretrained.pdparams",
"ResNeSt101": "https://paddle-imagenet-models-name.bj.bcebos.com/dygraph/ResNeSt101_pretrained.pdparams",
}
__all__ = list(MODEL_URLS.keys())
class ConvBNLayer(nn.Layer):
......@@ -656,8 +663,21 @@ class ResNeSt(nn.Layer):
x = self.out(x)
return x
def ResNeSt50_fast_1s1x64d(**args):
def _load_pretrained(pretrained, model, model_url, use_ssld=False):
if pretrained is False:
pass
elif pretrained is True:
load_dygraph_pretrain_from_url(model, model_url, use_ssld=use_ssld)
elif isinstance(pretrained, str):
load_dygraph_pretrain(model, pretrained)
else:
raise RuntimeError(
"pretrained type is not available. Please use `string` or `boolean` type."
)
def ResNeSt50_fast_1s1x64d(pretrained=False, use_ssld=False, **kwargs):
model = ResNeSt(
layers=[3, 4, 6, 3],
radix=1,
......@@ -669,11 +689,12 @@ def ResNeSt50_fast_1s1x64d(**args):
avd=True,
avd_first=True,
final_drop=0.0,
**args)
**kwargs)
_load_pretrained(pretrained, model, MODEL_URLS["ResNeSt50_fast_1s1x64d"], use_ssld=use_ssld)
return model
def ResNeSt50(**args):
def ResNeSt50(pretrained=False, use_ssld=False, **kwargs):
model = ResNeSt(
layers=[3, 4, 6, 3],
radix=2,
......@@ -685,11 +706,12 @@ def ResNeSt50(**args):
avd=True,
avd_first=False,
final_drop=0.0,
**args)
**kwargs)
_load_pretrained(pretrained, model, MODEL_URLS["ResNeSt50"], use_ssld=use_ssld)
return model
def ResNeSt101(**args):
def ResNeSt101(pretrained=False, use_ssld=False, **kwargs):
model = ResNeSt(
layers=[3, 4, 23, 3],
radix=2,
......@@ -701,5 +723,6 @@ def ResNeSt101(**args):
avd=True,
avd_first=False,
final_drop=0.0,
**args)
**kwargs)
_load_pretrained(pretrained, model, MODEL_URLS["ResNeSt101"], use_ssld=use_ssld)
return model
......@@ -27,7 +27,16 @@ from paddle.nn.initializer import Uniform
import math
__all__ = ["ResNet18", "ResNet34", "ResNet50", "ResNet101", "ResNet152"]
from ppcls.utils.save_load import load_dygraph_pretrain, load_dygraph_pretrain_from_url
MODEL_URLS = {"ResNet18": "https://paddle-imagenet-models-name.bj.bcebos.com/dygraph/ResNet18_pretrained.pdparams",
"ResNet34": "https://paddle-imagenet-models-name.bj.bcebos.com/dygraph/ResNet34_pretrained.pdparams",
"ResNet50": "https://paddle-imagenet-models-name.bj.bcebos.com/dygraph/ResNet50_pretrained.pdparams",
"ResNet101": "https://paddle-imagenet-models-name.bj.bcebos.com/dygraph/ResNet101_pretrained.pdparams",
"ResNet152": "https://paddle-imagenet-models-name.bj.bcebos.com/dygraph/ResNet152_pretrained.pdparams",
}
__all__ = list(MODEL_URLS.keys())
class ConvBNLayer(nn.Layer):
......@@ -290,27 +299,45 @@ class ResNet(nn.Layer):
y = self.out(y)
return y
def ResNet18(**args):
model = ResNet(layers=18, **args)
def _load_pretrained(pretrained, model, model_url, use_ssld=False):
if pretrained is False:
pass
elif pretrained is True:
load_dygraph_pretrain_from_url(model, model_url, use_ssld=use_ssld)
elif isinstance(pretrained, str):
load_dygraph_pretrain(model, pretrained)
else:
raise RuntimeError(
"pretrained type is not available. Please use `string` or `boolean` type."
)
def ResNet18(pretrained=False, use_ssld=False, **kwargs):
model = ResNet(layers=18, **kwargs)
_load_pretrained(pretrained, model, MODEL_URLS["ResNet18"], use_ssld=use_ssld)
return model
def ResNet34(**args):
model = ResNet(layers=34, **args)
def ResNet34(pretrained=False, use_ssld=False, **kwargs):
model = ResNet(layers=34, **kwargs)
_load_pretrained(pretrained, model, MODEL_URLS["ResNet34"], use_ssld=use_ssld)
return model
def ResNet50(**args):
model = ResNet(layers=50, **args)
def ResNet50(pretrained=False, use_ssld=False, **kwargs):
model = ResNet(layers=50, **kwargs)
_load_pretrained(pretrained, model, MODEL_URLS["ResNet50"], use_ssld=use_ssld)
return model
def ResNet101(**args):
model = ResNet(layers=101, **args)
def ResNet101(pretrained=False, use_ssld=False, **kwargs):
model = ResNet(layers=101, **kwargs)
_load_pretrained(pretrained, model, MODEL_URLS["ResNet101"], use_ssld=use_ssld)
return model
def ResNet152(**args):
model = ResNet(layers=152, **args)
def ResNet152(pretrained=False, use_ssld=False, **kwargs):
model = ResNet(layers=152, **kwargs)
_load_pretrained(pretrained, model, MODEL_URLS["ResNet152"], use_ssld=use_ssld)
return model
......@@ -27,9 +27,13 @@ from paddle.nn.initializer import Uniform
import math
__all__ = [
"ResNet18_vc", "ResNet34_vc", "ResNet50_vc", "ResNet101_vc", "ResNet152_vc"
]
from ppcls.utils.save_load import load_dygraph_pretrain, load_dygraph_pretrain_from_url
MODEL_URLS = {
"ResNet50_vc": "https://paddle-imagenet-models-name.bj.bcebos.com/dygraph/ResNet50_vc_pretrained.pdparams",
}
__all__ = list(MODEL_URLS.keys())
class ConvBNLayer(nn.Layer):
......@@ -283,27 +287,22 @@ class ResNet_vc(nn.Layer):
y = self.out(y)
return y
def ResNet18_vc(**args):
model = ResNet_vc(layers=18, **args)
return model
def ResNet34_vc(**args):
model = ResNet_vc(layers=34, **args)
return model
def ResNet50_vc(**args):
model = ResNet_vc(layers=50, **args)
def _load_pretrained(pretrained, model, model_url, use_ssld=False):
if pretrained is False:
pass
elif pretrained is True:
load_dygraph_pretrain_from_url(model, model_url, use_ssld=use_ssld)
elif isinstance(pretrained, str):
load_dygraph_pretrain(model, pretrained)
else:
raise RuntimeError(
"pretrained type is not available. Please use `string` or `boolean` type."
)
def ResNet50_vc(pretrained=False, use_ssld=False, **kwargs):
model = ResNet_vc(layers=50, **kwargs)
_load_pretrained(pretrained, model, MODEL_URLS["ResNet50_vc"], use_ssld=use_ssld)
return model
def ResNet101_vc(**args):
model = ResNet_vc(layers=101, **args)
return model
def ResNet152_vc(**args):
model = ResNet_vc(layers=152, **args)
return model
......@@ -27,9 +27,18 @@ from paddle.nn.initializer import Uniform
import math
__all__ = [
"ResNet18_vd", "ResNet34_vd", "ResNet50_vd", "ResNet101_vd", "ResNet152_vd"
]
from ppcls.utils.save_load import load_dygraph_pretrain, load_dygraph_pretrain_from_url
MODEL_URLS = {
"ResNet18_vd": "https://paddle-imagenet-models-name.bj.bcebos.com/dygraph/ResNet18_vd_pretrained.pdparams",
"ResNet34_vd": "https://paddle-imagenet-models-name.bj.bcebos.com/dygraph/ResNet34_vd_pretrained.pdparams",
"ResNet50_vd": "https://paddle-imagenet-models-name.bj.bcebos.com/dygraph/ResNet50_vd_pretrained.pdparams",
"ResNet101_vd": "https://paddle-imagenet-models-name.bj.bcebos.com/dygraph/ResNet101_vd_pretrained.pdparams",
"ResNet152_vd": "https://paddle-imagenet-models-name.bj.bcebos.com/dygraph/ResNet152_vd_pretrained.pdparams",
"ResNet200_vd": "https://paddle-imagenet-models-name.bj.bcebos.com/dygraph/ResNet200_vd_pretrained.pdparams",
}
__all__ = list(MODEL_URLS.keys())
class ConvBNLayer(nn.Layer):
......@@ -324,31 +333,50 @@ class ResNet_vd(nn.Layer):
return y
def ResNet18_vd(**args):
model = ResNet_vd(layers=18, **args)
def _load_pretrained(pretrained, model, model_url, use_ssld=False):
if pretrained is False:
pass
elif pretrained is True:
load_dygraph_pretrain_from_url(model, model_url, use_ssld=use_ssld)
elif isinstance(pretrained, str):
load_dygraph_pretrain(model, pretrained)
else:
raise RuntimeError(
"pretrained type is not available. Please use `string` or `boolean` type."
)
def ResNet18_vd(pretrained=False, use_ssld=False, **kwargs):
model = ResNet_vd(layers=18, **kwargs)
_load_pretrained(pretrained, model, MODEL_URLS["ResNet18_vd"], use_ssld=use_ssld)
return model
def ResNet34_vd(**args):
model = ResNet_vd(layers=34, **args)
def ResNet34_vd(pretrained=False, use_ssld=False, **kwargs):
model = ResNet_vd(layers=34, **kwargs)
_load_pretrained(pretrained, model, MODEL_URLS["ResNet34_vd"], use_ssld=use_ssld)
return model
def ResNet50_vd(**args):
model = ResNet_vd(layers=50, **args)
def ResNet50_vd(pretrained=False, use_ssld=False, **kwargs):
model = ResNet_vd(layers=50, **kwargs)
_load_pretrained(pretrained, model, MODEL_URLS["ResNet50_vd"], use_ssld=use_ssld)
return model
def ResNet101_vd(**args):
model = ResNet_vd(layers=101, **args)
def ResNet101_vd(pretrained=False, use_ssld=False, **kwargs):
model = ResNet_vd(layers=101, **kwargs)
_load_pretrained(pretrained, model, MODEL_URLS["ResNet101_vd"], use_ssld=use_ssld)
return model
def ResNet152_vd(**args):
model = ResNet_vd(layers=152, **args)
def ResNet152_vd(pretrained=False, use_ssld=False, **kwargs):
model = ResNet_vd(layers=152, **kwargs)
_load_pretrained(pretrained, model, MODEL_URLS["ResNet152_vd"], use_ssld=use_ssld)
return model
def ResNet200_vd(**args):
model = ResNet_vd(layers=200, **args)
def ResNet200_vd(pretrained=False, use_ssld=False, **kwargs):
model = ResNet_vd(layers=200, **kwargs)
_load_pretrained(pretrained, model, MODEL_URLS["ResNet200_vd"], use_ssld=use_ssld)
return model
......@@ -27,10 +27,18 @@ from paddle.nn.initializer import Uniform
import math
__all__ = [
"ResNeXt50_32x4d", "ResNeXt50_64x4d", "ResNeXt101_32x4d",
"ResNeXt101_64x4d", "ResNeXt152_32x4d", "ResNeXt152_64x4d"
]
from ppcls.utils.save_load import load_dygraph_pretrain, load_dygraph_pretrain_from_url
MODEL_URLS = {
"ResNeXt50_32x4d": "https://paddle-imagenet-models-name.bj.bcebos.com/dygraph/ResNeXt50_32x4d_pretrained.pdparams",
"ResNeXt50_64x4d": "https://paddle-imagenet-models-name.bj.bcebos.com/dygraph/ResNeXt50_64x4d_pretrained.pdparams",
"ResNeXt101_32x4d": "https://paddle-imagenet-models-name.bj.bcebos.com/dygraph/ResNeXt101_32x4d_pretrained.pdparams",
"ResNeXt101_64x4d": "https://paddle-imagenet-models-name.bj.bcebos.com/dygraph/ResNeXt101_64x4d_pretrained.pdparams",
"ResNeXt152_32x4d": "https://paddle-imagenet-models-name.bj.bcebos.com/dygraph/ResNeXt152_32x4d_pretrained.pdparams",
"ResNeXt152_64x4d": "https://paddle-imagenet-models-name.bj.bcebos.com/dygraph/ResNeXt152_64x4d_pretrained.pdparams",
}
__all__ = list(MODEL_URLS.keys())
class ConvBNLayer(nn.Layer):
......@@ -222,32 +230,51 @@ class ResNeXt(nn.Layer):
y = self.out(y)
return y
def ResNeXt50_32x4d(**args):
model = ResNeXt(layers=50, cardinality=32, **args)
def _load_pretrained(pretrained, model, model_url, use_ssld=False):
if pretrained is False:
pass
elif pretrained is True:
load_dygraph_pretrain_from_url(model, model_url, use_ssld=use_ssld)
elif isinstance(pretrained, str):
load_dygraph_pretrain(model, pretrained)
else:
raise RuntimeError(
"pretrained type is not available. Please use `string` or `boolean` type."
)
def ResNeXt50_32x4d(pretrained=False, use_ssld=False, **kwargs):
model = ResNeXt(layers=50, cardinality=32, **kwargs)
_load_pretrained(pretrained, model, MODEL_URLS["ResNeXt50_32x4d"], use_ssld=use_ssld)
return model
def ResNeXt50_64x4d(**args):
model = ResNeXt(layers=50, cardinality=64, **args)
def ResNeXt50_64x4d(pretrained=False, use_ssld=False, **kwargs):
model = ResNeXt(layers=50, cardinality=64, **kwargs)
_load_pretrained(pretrained, model, MODEL_URLS["ResNeXt50_64x4d"], use_ssld=use_ssld)
return model
def ResNeXt101_32x4d(**args):
model = ResNeXt(layers=101, cardinality=32, **args)
def ResNeXt101_32x4d(pretrained=False, use_ssld=False, **kwargs):
model = ResNeXt(layers=101, cardinality=32, **kwargs)
_load_pretrained(pretrained, model, MODEL_URLS["ResNeXt101_32x4d"], use_ssld=use_ssld)
return model
def ResNeXt101_64x4d(**args):
model = ResNeXt(layers=101, cardinality=64, **args)
def ResNeXt101_64x4d(pretrained=False, use_ssld=False, **kwargs):
model = ResNeXt(layers=101, cardinality=64, **kwargs)
_load_pretrained(pretrained, model, MODEL_URLS["ResNeXt101_64x4d"], use_ssld=use_ssld)
return model
def ResNeXt152_32x4d(**args):
model = ResNeXt(layers=152, cardinality=32, **args)
def ResNeXt152_32x4d(pretrained=False, use_ssld=False, **kwargs):
model = ResNeXt(layers=152, cardinality=32, **kwargs)
_load_pretrained(pretrained, model, MODEL_URLS["ResNeXt152_32x4d"], use_ssld=use_ssld)
return model
def ResNeXt152_64x4d(**args):
model = ResNeXt(layers=152, cardinality=64, **args)
def ResNeXt152_64x4d(pretrained=False, use_ssld=False, **kwargs):
model = ResNeXt(layers=152, cardinality=64, **kwargs)
_load_pretrained(pretrained, model, MODEL_URLS["ResNeXt152_64x4d"], use_ssld=use_ssld)
return model
......@@ -6,10 +6,18 @@ from paddle.nn import Conv2D, BatchNorm, Linear, Dropout
from paddle.nn import AdaptiveAvgPool2D, MaxPool2D, AvgPool2D
from paddle.nn.initializer import Uniform
__all__ = [
"ResNeXt101_32x8d_wsl", "ResNeXt101_32x16d_wsl", "ResNeXt101_32x32d_wsl",
"ResNeXt101_32x48d_wsl"
]
from ppcls.utils.save_load import load_dygraph_pretrain, load_dygraph_pretrain_from_url
MODEL_URLS = {
"ResNeXt101_32x8d_wsl": "https://paddle-imagenet-models-name.bj.bcebos.com/dygraph/ResNeXt101_32x8d_wsl_pretrained.pdparams",
"ResNeXt101_32x16d_wsl": "https://paddle-imagenet-models-name.bj.bcebos.com/dygraph/ResNeXt101_32x816_wsl_pretrained.pdparams",
"ResNeXt101_32x32d_wsl": "https://paddle-imagenet-models-name.bj.bcebos.com/dygraph/ResNeXt101_32x32d_wsl_pretrained.pdparams",
"ResNeXt101_32x48d_wsl": "https://paddle-imagenet-models-name.bj.bcebos.com/dygraph/ResNeXt101_32x48d_wsl_pretrained.pdparams",
}
__all__ = list(MODEL_URLS.keys())
class ConvBNLayer(nn.Layer):
......@@ -426,22 +434,39 @@ class ResNeXt101WSL(nn.Layer):
x = self._out(x)
return x
def ResNeXt101_32x8d_wsl(**args):
model = ResNeXt101WSL(cardinality=32, width=8, **args)
def _load_pretrained(pretrained, model, model_url, use_ssld=False):
if pretrained is False:
pass
elif pretrained is True:
load_dygraph_pretrain_from_url(model, model_url, use_ssld=use_ssld)
elif isinstance(pretrained, str):
load_dygraph_pretrain(model, pretrained)
else:
raise RuntimeError(
"pretrained type is not available. Please use `string` or `boolean` type."
)
def ResNeXt101_32x8d_wsl(pretrained=False, use_ssld=False, **kwargs):
model = ResNeXt101WSL(cardinality=32, width=8, **kwargs)
_load_pretrained(pretrained, model, MODEL_URLS["ResNeXt101_32x8d_wsl"], use_ssld=use_ssld)
return model
def ResNeXt101_32x16d_wsl(**args):
model = ResNeXt101WSL(cardinality=32, width=16, **args)
model = ResNeXt101WSL(cardinality=32, width=16, **kwargs)
_load_pretrained(pretrained, model, MODEL_URLS["ResNeXt101_32x16d_ws"], use_ssld=use_ssld)
return model
def ResNeXt101_32x32d_wsl(**args):
model = ResNeXt101WSL(cardinality=32, width=32, **args)
model = ResNeXt101WSL(cardinality=32, width=32, **kwargs)
_load_pretrained(pretrained, model, MODEL_URLS["ResNeXt101_32x32d_wsl"], use_ssld=use_ssld)
return model
def ResNeXt101_32x48d_wsl(**args):
model = ResNeXt101WSL(cardinality=32, width=48, **args)
model = ResNeXt101WSL(cardinality=32, width=48, **kwargs)
_load_pretrained(pretrained, model, MODEL_URLS["ResNeXt101_32x48d_wsl"], use_ssld=use_ssld)
return model
......@@ -27,11 +27,18 @@ from paddle.nn.initializer import Uniform
import math
__all__ = [
"ResNeXt50_vd_32x4d", "ResNeXt50_vd_64x4d", "ResNeXt101_vd_32x4d",
"ResNeXt101_vd_64x4d", "ResNeXt152_vd_32x4d", "ResNeXt152_vd_64x4d"
]
from ppcls.utils.save_load import load_dygraph_pretrain, load_dygraph_pretrain_from_url
MODEL_URLS = {
"ResNeXt50_vd_32x4d": "https://paddle-imagenet-models-name.bj.bcebos.com/dygraph/ResNeXt50_vd_32x4d_pretrained.pdparams",
"ResNeXt50_vd_64x4d": "https://paddle-imagenet-models-name.bj.bcebos.com/dygraph/ResNeXt50_vd_64x4d_pretrained.pdparams",
"ResNeXt101_vd_32x4d": "https://paddle-imagenet-models-name.bj.bcebos.com/dygraph/ResNeXt101_vd_32x4d_pretrained.pdparams",
"ResNeXt101_vd_64x4d": "https://paddle-imagenet-models-name.bj.bcebos.com/dygraph/ResNeXt101_vd_64x4d_pretrained.pdparams",
"ResNeXt152_vd_32x4d": "https://paddle-imagenet-models-name.bj.bcebos.com/dygraph/ResNeXt152_vd_32x4d_pretrained.pdparams",
"ResNeXt152_vd_64x4d": "https://paddle-imagenet-models-name.bj.bcebos.com/dygraph/ResNeXt152_vd_64x4d_pretrained.pdparams",
}
__all__ = list(MODEL_URLS.keys())
class ConvBNLayer(nn.Layer):
def __init__(
......@@ -235,32 +242,50 @@ class ResNeXt(nn.Layer):
y = self.out(y)
return y
def ResNeXt50_vd_32x4d(**args):
model = ResNeXt(layers=50, cardinality=32, **args)
def _load_pretrained(pretrained, model, model_url, use_ssld=False):
if pretrained is False:
pass
elif pretrained is True:
load_dygraph_pretrain_from_url(model, model_url, use_ssld=use_ssld)
elif isinstance(pretrained, str):
load_dygraph_pretrain(model, pretrained)
else:
raise RuntimeError(
"pretrained type is not available. Please use `string` or `boolean` type."
)
def ResNeXt50_vd_32x4d(pretrained=False, use_ssld=False, **kwargs):
model = ResNeXt(layers=50, cardinality=32, **kwargs)
_load_pretrained(pretrained, model, MODEL_URLS["ResNeXt50_vd_32x4d"], use_ssld=use_ssld)
return model
def ResNeXt50_vd_64x4d(**args):
model = ResNeXt(layers=50, cardinality=64, **args)
def ResNeXt50_vd_64x4d(pretrained=False, use_ssld=False, **kwargs):
model = ResNeXt(layers=50, cardinality=64, **kwargs)
_load_pretrained(pretrained, model, MODEL_URLS["ResNeXt50_vd_64x4d"], use_ssld=use_ssld)
return model
def ResNeXt101_vd_32x4d(**args):
model = ResNeXt(layers=101, cardinality=32, **args)
def ResNeXt101_vd_32x4d(pretrained=False, use_ssld=False, **kwargs):
model = ResNeXt(layers=101, cardinality=32, **kwargs)
_load_pretrained(pretrained, model, MODEL_URLS["ResNeXt101_vd_32x4d"], use_ssld=use_ssld)
return model
def ResNeXt101_vd_64x4d(**args):
model = ResNeXt(layers=101, cardinality=64, **args)
def ResNeXt101_vd_64x4d(pretrained=False, use_ssld=False, **kwargs):
model = ResNeXt(layers=101, cardinality=64, **kwargs)
_load_pretrained(pretrained, model, MODEL_URLS["ResNeXt101_vd_64x4d"], use_ssld=use_ssld)
return model
def ResNeXt152_vd_32x4d(**args):
model = ResNeXt(layers=152, cardinality=32, **args)
def ResNeXt152_vd_32x4d(pretrained=False, use_ssld=False, **kwargs):
model = ResNeXt(layers=152, cardinality=32, **kwargs)
_load_pretrained(pretrained, model, MODEL_URLS["ResNeXt152_vd_32x4d"], use_ssld=use_ssld)
return model
def ResNeXt152_vd_64x4d(**args):
model = ResNeXt(layers=152, cardinality=64, **args)
def ResNeXt152_vd_64x4d(pretrained=False, use_ssld=False, **kwargs):
model = ResNeXt(layers=152, cardinality=64, **kwargs)
_load_pretrained(pretrained, model, MODEL_URLS["ResNeXt152_vd_64x4d"], use_ssld=use_ssld)
return model
......@@ -22,9 +22,17 @@ from paddle import ParamAttr
import paddle.nn as nn
from math import ceil
__all__ = [
"ReXNet_1_0", "ReXNet_1_3", "ReXNet_1_5", "ReXNet_2_0", "ReXNet_3_0"
]
from ppcls.utils.save_load import load_dygraph_pretrain, load_dygraph_pretrain_from_url
MODEL_URLS = {
"ReXNet_1_0": "https://paddle-imagenet-models-name.bj.bcebos.com/dygraph/ReXNet_1_0_pretrained.pdparams",
"ReXNet_1_3": "https://paddle-imagenet-models-name.bj.bcebos.com/dygraph/ReXNet_1_3_pretrained.pdparams",
"ReXNet_1_5": "https://paddle-imagenet-models-name.bj.bcebos.com/dygraph/ReXNet_1_5_32x4d_pretrained.pdparams",
"ReXNet_2_0": "https://paddle-imagenet-models-name.bj.bcebos.com/dygraph/ReXNet_2_0_pretrained.pdparams",
"ReXNet_3_0": "https://paddle-imagenet-models-name.bj.bcebos.com/dygraph/ReXNet_3_0_pretrained.pdparams",
}
__all__ = list(MODEL_URLS.keys())
def conv_bn_act(out,
......@@ -220,21 +228,44 @@ class ReXNetV1(nn.Layer):
return x
def ReXNet_1_0(**args):
return ReXNetV1(width_mult=1.0, **args)
def _load_pretrained(pretrained, model, model_url, use_ssld=False):
if pretrained is False:
pass
elif pretrained is True:
load_dygraph_pretrain_from_url(model, model_url, use_ssld=use_ssld)
elif isinstance(pretrained, str):
load_dygraph_pretrain(model, pretrained)
else:
raise RuntimeError(
"pretrained type is not available. Please use `string` or `boolean` type."
)
def ReXNet_1_0(pretrained=False, use_ssld=False, **kwargs):
model = ReXNetV1(width_mult=1.0, **kwargs)
_load_pretrained(pretrained, model, MODEL_URLS["ReXNet_1_0"], use_ssld=use_ssld)
return model
def ReXNet_1_3(**args):
return ReXNetV1(width_mult=1.3, **args)
def ReXNet_1_3(pretrained=False, use_ssld=False, **kwargs):
model = ReXNetV1(width_mult=1.3, **kwargs)
_load_pretrained(pretrained, model, MODEL_URLS["ReXNet_1_3"], use_ssld=use_ssld)
return model
def ReXNet_1_5(**args):
return ReXNetV1(width_mult=1.5, **args)
def ReXNet_1_5(pretrained=False, use_ssld=False, **kwargs):
model = ReXNetV1(width_mult=1.5, **kwargs)
_load_pretrained(pretrained, model, MODEL_URLS["ReXNet_1_5"], use_ssld=use_ssld)
return model
def ReXNet_2_0(**args):
return ReXNetV1(width_mult=2.0, **args)
def ReXNet_2_0(pretrained=False, use_ssld=False, **kwargs):
model = ReXNetV1(width_mult=2.0, **kwargs)
_load_pretrained(pretrained, model, MODEL_URLS["ReXNet_2_0"], use_ssld=use_ssld)
return model
def ReXNet_3_0(**args):
return ReXNetV1(width_mult=3.0, **args)
def ReXNet_3_0(pretrained=False, use_ssld=False, **kwargs):
model = ReXNetV1(width_mult=3.0, **kwargs)
_load_pretrained(pretrained, model, MODEL_URLS["ReXNet_3_0"], use_ssld=use_ssld)
return model
\ No newline at end of file
......@@ -26,10 +26,16 @@ from paddle.nn.initializer import Uniform
import math
__all__ = [
"SE_ResNet18_vd", "SE_ResNet34_vd", "SE_ResNet50_vd", "SE_ResNet101_vd",
"SE_ResNet152_vd", "SE_ResNet200_vd"
]
from ppcls.utils.save_load import load_dygraph_pretrain, load_dygraph_pretrain_from_url
MODEL_URLS = {
"SE_ResNet18_vd": "https://paddle-imagenet-models-name.bj.bcebos.com/dygraph/SE_ResNet18_vd_pretrained.pdparams",
"SE_ResNet34_vd": "https://paddle-imagenet-models-name.bj.bcebos.com/dygraph/SE_ResNet34_vd_pretrained.pdparams",
"SE_ResNet50_vd": "https://paddle-imagenet-models-name.bj.bcebos.com/dygraph/SE_ResNet50_vd_pretrained.pdparams",
}
__all__ = list(MODEL_URLS.keys())
class ConvBNLayer(nn.Layer):
......@@ -347,32 +353,33 @@ class SE_ResNet_vd(nn.Layer):
y = self.out(y)
return y
def SE_ResNet18_vd(**args):
model = SE_ResNet_vd(layers=18, **args)
return model
def SE_ResNet34_vd(**args):
model = SE_ResNet_vd(layers=34, **args)
return model
def SE_ResNet50_vd(**args):
model = SE_ResNet_vd(layers=50, **args)
return model
def SE_ResNet101_vd(**args):
model = SE_ResNet_vd(layers=101, **args)
def _load_pretrained(pretrained, model, model_url, use_ssld=False):
if pretrained is False:
pass
elif pretrained is True:
load_dygraph_pretrain_from_url(model, model_url, use_ssld=use_ssld)
elif isinstance(pretrained, str):
load_dygraph_pretrain(model, pretrained)
else:
raise RuntimeError(
"pretrained type is not available. Please use `string` or `boolean` type."
)
def SE_ResNet18_vd(pretrained=False, use_ssld=False, **kwargs):
model = SE_ResNet_vd(layers=18, **kwargs)
_load_pretrained(pretrained, model, MODEL_URLS["SE_ResNet18_vd"], use_ssld=use_ssld)
return model
def SE_ResNet152_vd(**args):
model = SE_ResNet_vd(layers=152, **args)
def SE_ResNet34_vd(pretrained=False, use_ssld=False, **kwargs):
model = SE_ResNet_vd(layers=34, **kwargs)
_load_pretrained(pretrained, model, MODEL_URLS["SE_ResNet34_vd"], use_ssld=use_ssld)
return model
def SE_ResNet200_vd(**args):
model = SE_ResNet_vd(layers=200, **args)
def SE_ResNet50_vd(pretrained=False, use_ssld=False, **kwargs):
model = SE_ResNet_vd(layers=50, **kwargs)
_load_pretrained(pretrained, model, MODEL_URLS["SE_ResNet50_vd"], use_ssld=use_ssld)
return model
......@@ -27,7 +27,16 @@ from paddle.nn.initializer import Uniform
import math
__all__ = ["SE_ResNeXt50_32x4d", "SE_ResNeXt101_32x4d", "SE_ResNeXt152_64x4d"]
from ppcls.utils.save_load import load_dygraph_pretrain, load_dygraph_pretrain_from_url
MODEL_URLS = {
"SE_ResNeXt50_32x4d": "https://paddle-imagenet-models-name.bj.bcebos.com/dygraph/SE_ResNeXt50_32x4d_pretrained.pdparams",
"SE_ResNeXt101_32x4d": "https://paddle-imagenet-models-name.bj.bcebos.com/dygraph/SE_ResNeXt101_32x4d_pretrained.pdparams",
"SE_ResNeXt152_64x4d": "https://paddle-imagenet-models-name.bj.bcebos.com/dygraph/SE_ResNeXt152_64x4d_pretrained.pdparams",
}
__all__ = list(MODEL_URLS.keys())
class ConvBNLayer(nn.Layer):
......@@ -301,17 +310,33 @@ class ResNeXt(nn.Layer):
y = self.out(y)
return y
def SE_ResNeXt50_32x4d(**args):
model = ResNeXt(layers=50, cardinality=32, **args)
def _load_pretrained(pretrained, model, model_url, use_ssld=False):
if pretrained is False:
pass
elif pretrained is True:
load_dygraph_pretrain_from_url(model, model_url, use_ssld=use_ssld)
elif isinstance(pretrained, str):
load_dygraph_pretrain(model, pretrained)
else:
raise RuntimeError(
"pretrained type is not available. Please use `string` or `boolean` type."
)
def SE_ResNeXt50_32x4d(pretrained=False, use_ssld=False, **kwargs):
model = ResNeXt(layers=50, cardinality=32, **kwargs)
_load_pretrained(pretrained, model, MODEL_URLS["SE_ResNeXt50_32x4d"], use_ssld=use_ssld)
return model
def SE_ResNeXt101_32x4d(**args):
model = ResNeXt(layers=101, cardinality=32, **args)
def SE_ResNeXt101_32x4d(pretrained=False, use_ssld=False, **kwargs):
model = ResNeXt(layers=101, cardinality=32, **kwargs)
_load_pretrained(pretrained, model, MODEL_URLS["SE_ResNeXt101_32x4d"], use_ssld=use_ssld)
return model
def SE_ResNeXt152_64x4d(**args):
model = ResNeXt(layers=152, cardinality=64, **args)
def SE_ResNeXt152_64x4d(pretrained=False, use_ssld=False, **kwargs):
model = ResNeXt(layers=152, cardinality=64, **kwargs)
_load_pretrained(pretrained, model, MODEL_URLS["SE_ResNeXt152_64x4d"], use_ssld=use_ssld)
return model
......@@ -27,7 +27,16 @@ from paddle.nn.initializer import Uniform
import math
__all__ = ["SE_ResNeXt50_vd_32x4d", "SE_ResNeXt50_vd_32x4d", "SENet154_vd"]
from ppcls.utils.save_load import load_dygraph_pretrain, load_dygraph_pretrain_from_url
MODEL_URLS = {
"SE_ResNeXt50_vd_32x4d": "https://paddle-imagenet-models-name.bj.bcebos.com/dygraph/SE_ResNeXt50_vd_32x4d_pretrained.pdparams",
"SE_ResNeXt50_vd_32x4d": "https://paddle-imagenet-models-name.bj.bcebos.com/dygraph/SE_ResNeXt50_vd_32x4d_pretrained.pdparams",
"SENet154_vd": "https://paddle-imagenet-models-name.bj.bcebos.com/dygraph/SENet154_vd_pretrained.pdparams",
}
__all__ = list(MODEL_URLS.keys())
class ConvBNLayer(nn.Layer):
......@@ -269,17 +278,33 @@ class ResNeXt(nn.Layer):
y = self.out(y)
return y
def SE_ResNeXt50_vd_32x4d(**args):
model = ResNeXt(layers=50, cardinality=32, **args)
def _load_pretrained(pretrained, model, model_url, use_ssld=False):
if pretrained is False:
pass
elif pretrained is True:
load_dygraph_pretrain_from_url(model, model_url, use_ssld=use_ssld)
elif isinstance(pretrained, str):
load_dygraph_pretrain(model, pretrained)
else:
raise RuntimeError(
"pretrained type is not available. Please use `string` or `boolean` type."
)
def SE_ResNeXt50_vd_32x4d(pretrained=False, use_ssld=False, **kwargs):
model = ResNeXt(layers=50, cardinality=32, **kwargs)
_load_pretrained(pretrained, model, MODEL_URLS["SE_ResNeXt50_vd_32x4d"], use_ssld=use_ssld)
return model
def SE_ResNeXt101_vd_32x4d(**args):
model = ResNeXt(layers=101, cardinality=32, **args)
def SE_ResNeXt101_vd_32x4d(pretrained=False, use_ssld=False, **kwargs):
model = ResNeXt(layers=101, cardinality=32, **kwargs)
_load_pretrained(pretrained, model, MODEL_URLS["SE_ResNeXt101_vd_32x4d"], use_ssld=use_ssld)
return model
def SENet154_vd(**args):
model = ResNeXt(layers=152, cardinality=64, **args)
def SENet154_vd(pretrained=False, use_ssld=False, **kwargs):
model = ResNeXt(layers=152, cardinality=64, **kwargs)
_load_pretrained(pretrained, model, MODEL_URLS["SENet154_vd"], use_ssld=use_ssld)
return model
......@@ -22,11 +22,19 @@ from paddle.nn import Layer, Conv2D, MaxPool2D, AdaptiveAvgPool2D, BatchNorm, Li
from paddle.nn.initializer import KaimingNormal
from paddle.nn.functional import swish
__all__ = [
"ShuffleNetV2_x0_25", "ShuffleNetV2_x0_33", "ShuffleNetV2_x0_5",
"ShuffleNetV2_x1_0", "ShuffleNetV2_x1_5", "ShuffleNetV2_x2_0",
"ShuffleNetV2_swish"
]
from ppcls.utils.save_load import load_dygraph_pretrain, load_dygraph_pretrain_from_url
MODEL_URLS = {
"ShuffleNetV2_x0_25": "https://paddle-imagenet-models-name.bj.bcebos.com/dygraph/ShuffleNetV2_x0_25_pretrained.pdparams",
"ShuffleNetV2_x0_33": "https://paddle-imagenet-models-name.bj.bcebos.com/dygraph/ShuffleNetV2_x0_33_pretrained.pdparams",
"ShuffleNetV2_x0_5": "https://paddle-imagenet-models-name.bj.bcebos.com/dygraph/ShuffleNetV2_x0_5_pretrained.pdparams",
"ShuffleNetV2_x1_0": "https://paddle-imagenet-models-name.bj.bcebos.com/dygraph/ShuffleNetV2_x1_0_pretrained.pdparams",
"ShuffleNetV2_x1_5": "https://paddle-imagenet-models-name.bj.bcebos.com/dygraph/ShuffleNetV2_x1_5_pretrained.pdparams",
"ShuffleNetV2_x2_0": "https://paddle-imagenet-models-name.bj.bcebos.com/dygraph/ShuffleNetV2_x2_0_pretrained.pdparams",
"ShuffleNetV2_swish": "https://paddle-imagenet-models-name.bj.bcebos.com/dygraph/ShuffleNetV2_swish_pretrained.pdparams"
}
__all__ = list(MODEL_URLS.keys())
def channel_shuffle(x, groups):
......@@ -285,36 +293,56 @@ class ShuffleNet(Layer):
return y
def ShuffleNetV2_x0_25(**args):
model = ShuffleNet(scale=0.25, **args)
def _load_pretrained(pretrained, model, model_url, use_ssld=False):
if pretrained is False:
pass
elif pretrained is True:
load_dygraph_pretrain_from_url(model, model_url, use_ssld=use_ssld)
elif isinstance(pretrained, str):
load_dygraph_pretrain(model, pretrained)
else:
raise RuntimeError(
"pretrained type is not available. Please use `string` or `boolean` type."
)
def ShuffleNetV2_x0_25(pretrained=False, use_ssld=False, **kwargs):
model = ShuffleNet(scale=0.25, **kwargs)
_load_pretrained(pretrained, model, MODEL_URLS["ShuffleNetV2_x0_25"], use_ssld=use_ssld)
return model
def ShuffleNetV2_x0_33(**args):
model = ShuffleNet(scale=0.33, **args)
def ShuffleNetV2_x0_33(pretrained=False, use_ssld=False, **kwargs):
model = ShuffleNet(scale=0.33, **kwargs)
_load_pretrained(pretrained, model, MODEL_URLS["ShuffleNetV2_x0_33"], use_ssld=use_ssld)
return model
def ShuffleNetV2_x0_5(**args):
model = ShuffleNet(scale=0.5, **args)
def ShuffleNetV2_x0_5(pretrained=False, use_ssld=False, **kwargs):
model = ShuffleNet(scale=0.5, **kwargs)
_load_pretrained(pretrained, model, MODEL_URLS["ShuffleNetV2_x0_5"], use_ssld=use_ssld)
return model
def ShuffleNetV2_x1_0(**args):
model = ShuffleNet(scale=1.0, **args)
def ShuffleNetV2_x1_0(pretrained=False, use_ssld=False, **kwargs):
model = ShuffleNet(scale=1.0, **kwargs)
_load_pretrained(pretrained, model, MODEL_URLS["ShuffleNetV2_x1_0"], use_ssld=use_ssld)
return model
def ShuffleNetV2_x1_5(**args):
model = ShuffleNet(scale=1.5, **args)
def ShuffleNetV2_x1_5(pretrained=False, use_ssld=False, **kwargs):
model = ShuffleNet(scale=1.5, **kwargs)
_load_pretrained(pretrained, model, MODEL_URLS["ShuffleNetV2_x1_5"], use_ssld=use_ssld)
return model
def ShuffleNetV2_x2_0(**args):
model = ShuffleNet(scale=2.0, **args)
def ShuffleNetV2_x2_0(pretrained=False, use_ssld=False, **kwargs):
model = ShuffleNet(scale=2.0, **kwargs)
_load_pretrained(pretrained, model, MODEL_URLS["ShuffleNetV2_x2_0"], use_ssld=use_ssld)
return model
def ShuffleNetV2_swish(**args):
model = ShuffleNet(scale=1.0, act="swish", **args)
def ShuffleNetV2_swish(pretrained=False, use_ssld=False, **kwargs):
model = ShuffleNet(scale=1.0, act="swish", **kwargs)
_load_pretrained(pretrained, model, MODEL_URLS["ShuffleNetV2_swish"], use_ssld=use_ssld)
return model
# copyright (c) 2020 PaddlePaddle Authors. All Rights Reserve.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
import paddle
from paddle import ParamAttr
import paddle.nn as nn
......@@ -5,7 +19,14 @@ import paddle.nn.functional as F
from paddle.nn import Conv2D, BatchNorm, Linear, Dropout
from paddle.nn import AdaptiveAvgPool2D, MaxPool2D, AvgPool2D
__all__ = ["SqueezeNet1_0", "SqueezeNet1_1"]
from ppcls.utils.save_load import load_dygraph_pretrain, load_dygraph_pretrain_from_url
MODEL_URLS = {
"SqueezeNet1_0": "https://paddle-imagenet-models-name.bj.bcebos.com/dygraph/SqueezeNet1_0_pretrained.pdparams",
"SqueezeNet1_1": "https://paddle-imagenet-models-name.bj.bcebos.com/dygraph/SqueezeNet1_1_pretrained.pdparams",
}
__all__ = list(MODEL_URLS.keys())
class MakeFireConv(nn.Layer):
......@@ -143,12 +164,26 @@ class SqueezeNet(nn.Layer):
x = paddle.squeeze(x, axis=[2, 3])
return x
def SqueezeNet1_0(**args):
model = SqueezeNet(version="1.0", **args)
def _load_pretrained(pretrained, model, model_url, use_ssld=False):
if pretrained is False:
pass
elif pretrained is True:
load_dygraph_pretrain_from_url(model, model_url, use_ssld=use_ssld)
elif isinstance(pretrained, str):
load_dygraph_pretrain(model, pretrained)
else:
raise RuntimeError(
"pretrained type is not available. Please use `string` or `boolean` type."
)
def SqueezeNet1_0(pretrained=False, use_ssld=False, **kwargs):
model = SqueezeNet(version="1.0", **kwargs)
_load_pretrained(pretrained, model, MODEL_URLS["SqueezeNet1_0"], use_ssld=use_ssld)
return model
def SqueezeNet1_1(**args):
model = SqueezeNet(version="1.1", **args)
def SqueezeNet1_1(pretrained=False, use_ssld=False, **kwargs):
model = SqueezeNet(version="1.1", **kwargs)
_load_pretrained(pretrained, model, MODEL_URLS["SqueezeNet1_1"], use_ssld=use_ssld)
return model
......@@ -21,6 +21,19 @@ from paddle.nn.initializer import TruncatedNormal, Constant
from .vision_transformer import trunc_normal_, zeros_, ones_, to_2tuple, DropPath, Identity
from ppcls.utils.save_load import load_dygraph_pretrain, load_dygraph_pretrain_from_url
MODEL_URLS = {
"SwinTransformer_tiny_patch4_window7_224": "https://paddle-imagenet-models-name.bj.bcebos.com/dygraph/SwinTransformer_tiny_patch4_window7_224_pretrained.pdparams",
"SwinTransformer_small_patch4_window7_224": "https://paddle-imagenet-models-name.bj.bcebos.com/dygraph/SwinTransformer_small_patch4_window7_224_pretrained.pdparams",
"SwinTransformer_base_patch4_window7_224": "https://paddle-imagenet-models-name.bj.bcebos.com/dygraph/SwinTransformer_base_patch4_window7_224_pretrained.pdparams",
"SwinTransformer_base_patch4_window12_384": "https://paddle-imagenet-models-name.bj.bcebos.com/dygraph/SwinTransformer_base_patch4_window12_384_pretrained.pdparams",
"SwinTransformer_large_patch4_window7_224": "https://paddle-imagenet-models-name.bj.bcebos.com/dygraph/SwinTransformer_large_patch4_window7_224_pretrained.pdparams",
"SwinTransformer_large_patch4_window12_384": "https://paddle-imagenet-models-name.bj.bcebos.com/dygraph/SwinTransformer_large_patch4_window12_384_pretrained.pdparams",
}
__all__ = list(MODEL_URLS.keys())
class Mlp(nn.Layer):
def __init__(self,
......@@ -716,40 +729,56 @@ class SwinTransformer(nn.Layer):
flops += self.num_features * self.num_classes
return flops
def SwinTransformer_tiny_patch4_window7_224(**args):
def _load_pretrained(pretrained, model, model_url, use_ssld=False):
if pretrained is False:
pass
elif pretrained is True:
load_dygraph_pretrain_from_url(model, model_url, use_ssld=use_ssld)
elif isinstance(pretrained, str):
load_dygraph_pretrain(model, pretrained)
else:
raise RuntimeError(
"pretrained type is not available. Please use `string` or `boolean` type."
)
def SwinTransformer_tiny_patch4_window7_224(pretrained=False, use_ssld=False, **kwargs):
model = SwinTransformer(
embed_dim=96,
depths=[2, 2, 6, 2],
num_heads=[3, 6, 12, 24],
window_size=7,
drop_path_rate=0.2,
**args)
**kwargs)
_load_pretrained(pretrained, model, MODEL_URLS["SwinTransformer_tiny_patch4_window7_224"], use_ssld=use_ssld)
return model
def SwinTransformer_small_patch4_window7_224(**args):
def SwinTransformer_small_patch4_window7_224(pretrained=False, use_ssld=False, **kwargs):
model = SwinTransformer(
embed_dim=96,
depths=[2, 2, 18, 2],
num_heads=[3, 6, 12, 24],
window_size=7,
**args)
**kwargs)
_load_pretrained(pretrained, model, MODEL_URLS["SwinTransformer_small_patch4_window7_224"], use_ssld=use_ssld)
return model
def SwinTransformer_base_patch4_window7_224(**args):
def SwinTransformer_base_patch4_window7_224(pretrained=False, use_ssld=False, **kwargs):
model = SwinTransformer(
embed_dim=128,
depths=[2, 2, 18, 2],
num_heads=[4, 8, 16, 32],
window_size=7,
drop_path_rate=0.5,
**args)
**kwargs)
_load_pretrained(pretrained, model, MODEL_URLS["SwinTransformer_base_patch4_window7_224"], use_ssld=use_ssld)
return model
def SwinTransformer_base_patch4_window12_384(**args):
def SwinTransformer_base_patch4_window12_384(pretrained=False, use_ssld=False, **kwargs):
model = SwinTransformer(
img_size=384,
embed_dim=128,
......@@ -757,26 +786,29 @@ def SwinTransformer_base_patch4_window12_384(**args):
num_heads=[4, 8, 16, 32],
window_size=12,
drop_path_rate=0.5, # NOTE: do not appear in offical code
**args)
**kwargs)
_load_pretrained(pretrained, model, MODEL_URLS["SwinTransformer_base_patch4_window12_384"], use_ssld=use_ssld)
return model
def SwinTransformer_large_patch4_window7_224(**args):
def SwinTransformer_large_patch4_window7_224(pretrained=False, use_ssld=False, **kwargs):
model = SwinTransformer(
embed_dim=192,
depths=[2, 2, 18, 2],
num_heads=[6, 12, 24, 48],
window_size=7,
**args)
**kwargs)
_load_pretrained(pretrained, model, MODEL_URLS["SwinTransformer_large_patch4_window7_224"], use_ssld=use_ssld)
return model
def SwinTransformer_large_patch4_window12_384(**args):
def SwinTransformer_large_patch4_window12_384(pretrained=False, use_ssld=False, **kwargs):
model = SwinTransformer(
img_size=384,
embed_dim=192,
depths=[2, 2, 18, 2],
num_heads=[6, 12, 24, 48],
window_size=12,
**args)
**kwargs)
_load_pretrained(pretrained, model, MODEL_URLS["SwinTransformer_large_patch4_window12_384"], use_ssld=use_ssld)
return model
......@@ -26,7 +26,7 @@ from ppcls.utils.save_load import load_dygraph_pretrain, load_dygraph_pretrain_f
MODEL_URLS = {
"TNT_small":
"https://paddle-imagenet-models-name.bj.bcebos.com/dygraph/model_zoo/TNT_small_pretrained.pdparams"
"https://paddle-imagenet-models-name.bj.bcebos.com/dygraph/TNT_small_pretrained.pdparams"
}
......
......@@ -5,7 +5,16 @@ import paddle.nn.functional as F
from paddle.nn import Conv2D, BatchNorm, Linear, Dropout
from paddle.nn import AdaptiveAvgPool2D, MaxPool2D, AvgPool2D
__all__ = ["VGG11", "VGG13", "VGG16", "VGG19"]
from ppcls.utils.save_load import load_dygraph_pretrain, load_dygraph_pretrain_from_url
MODEL_URLS = {
"VGG11": "https://paddle-imagenet-models-name.bj.bcebos.com/dygraph/VGG11_pretrained.pdparams",
"VGG13": "https://paddle-imagenet-models-name.bj.bcebos.com/dygraph/VGG13_pretrained.pdparams",
"VGG16": "https://paddle-imagenet-models-name.bj.bcebos.com/dygraph/VGG16_pretrained.pdparams",
"VGG19": "https://paddle-imagenet-models-name.bj.bcebos.com/dygraph/VGG19_pretrained.pdparams",
}
__all__ = list(MODEL_URLS.keys())
class ConvBlock(nn.Layer):
......@@ -131,22 +140,40 @@ class VGGNet(nn.Layer):
x = self._out(x)
return x
def VGG11(**args):
model = VGGNet(layers=11, **args)
def _load_pretrained(pretrained, model, model_url, use_ssld=False):
if pretrained is False:
pass
elif pretrained is True:
load_dygraph_pretrain_from_url(model, model_url, use_ssld=use_ssld)
elif isinstance(pretrained, str):
load_dygraph_pretrain(model, pretrained)
else:
raise RuntimeError(
"pretrained type is not available. Please use `string` or `boolean` type."
)
def VGG11(pretrained, model, model_url, use_ssld=False, **kwargs):
model = VGGNet(layers=11, **kwargs)
_load_pretrained(pretrained, model, MODEL_URLS["VGG11"], use_ssld=use_ssld)
return model
def VGG13(**args):
model = VGGNet(layers=13, **args)
def VGG13(pretrained, model, model_url, use_ssld=False, **kwargs):
model = VGGNet(layers=13, **kwargs)
_load_pretrained(pretrained, model, MODEL_URLS["VGG13"], use_ssld=use_ssld)
return model
def VGG16(**args):
model = VGGNet(layers=16, **args)
def VGG16(pretrained, model, model_url, use_ssld=False, **kwargs):
model = VGGNet(layers=16, **kwargs)
_load_pretrained(pretrained, model, MODEL_URLS["VGG16"], use_ssld=use_ssld)
return model
def VGG19(**args):
model = VGGNet(layers=19, **args)
def VGG19(pretrained, model, model_url, use_ssld=False, **kwargs):
model = VGGNet(layers=19, **kwargs)
_load_pretrained(pretrained, model, MODEL_URLS["VGG19"], use_ssld=use_ssld)
return model
......@@ -12,19 +12,32 @@
# See the License for the specific language governing permissions and
# limitations under the License.
from collections import Callable
import numpy as np
import paddle
import paddle.nn as nn
from paddle.nn.initializer import TruncatedNormal, Constant
from paddle.nn.initializer import TruncatedNormal, Constant, Normal
from ppcls.utils.save_load import load_dygraph_pretrain, load_dygraph_pretrain_from_url
MODEL_URLS = {
"ViT_small_patch16_224": "https://paddle-imagenet-models-name.bj.bcebos.com/dygraph/ViT_small_patch16_224_pretrained.pdparams",
"ViT_base_patch16_224": "https://paddle-imagenet-models-name.bj.bcebos.com/dygraph/ViT_base_patch16_224_pretrained.pdparams",
"ViT_base_patch16_384": "https://paddle-imagenet-models-name.bj.bcebos.com/dygraph/ViT_base_patch16_384_pretrained.pdparams",
"ViT_base_patch32_384": "https://paddle-imagenet-models-name.bj.bcebos.com/dygraph/ViT_base_patch32_384_pretrained.pdparams",
"ViT_large_patch16_224": "https://paddle-imagenet-models-name.bj.bcebos.com/dygraph/ViT_large_patch16_224_pretrained.pdparams",
"ViT_large_patch16_384": "https://paddle-imagenet-models-name.bj.bcebos.com/dygraph/ViT_large_patch16_384_pretrained.pdparams",
"ViT_large_patch32_384": "https://paddle-imagenet-models-name.bj.bcebos.com/dygraph/ViT_large_patch32_384_pretrained.pdparams",
"ViT_huge_patch16_224": "https://paddle-imagenet-models-name.bj.bcebos.com/dygraph/ViT_huge_patch16_224_pretrained.pdparams",
"ViT_huge_patch32_384": "https://paddle-imagenet-models-name.bj.bcebos.com/dygraph/ViT_huge_patch32_384_pretrained.pdparams"
}
__all__ = list(MODEL_URLS.keys())
__all__ = [
"VisionTransformer", "ViT_small_patch16_224", "ViT_base_patch16_224",
"ViT_base_patch16_384", "ViT_base_patch32_384", "ViT_large_patch16_224",
"ViT_large_patch16_384", "ViT_large_patch32_384", "ViT_huge_patch16_224",
"ViT_huge_patch32_384"
]
trunc_normal_ = TruncatedNormal(std=.02)
normal_ = Normal
zeros_ = Constant(value=0.)
ones_ = Constant(value=1.)
......@@ -141,7 +154,13 @@ class Block(nn.Layer):
norm_layer='nn.LayerNorm',
epsilon=1e-5):
super().__init__()
self.norm1 = eval(norm_layer)(dim, epsilon=epsilon)
if isinstance(norm_layer, str):
self.norm1 = eval(norm_layer)(dim, epsilon=epsilon)
elif isinstance(norm_layer, Callable):
self.norm1 = norm_layer(dim)
else:
raise TypeError(
"The norm_layer must be str or paddle.nn.layer.Layer class")
self.attn = Attention(
dim,
num_heads=num_heads,
......@@ -151,7 +170,13 @@ class Block(nn.Layer):
proj_drop=drop)
# NOTE: drop path for stochastic depth, we shall see if this is better than dropout here
self.drop_path = DropPath(drop_path) if drop_path > 0. else Identity()
self.norm2 = eval(norm_layer)(dim, epsilon=epsilon)
if isinstance(norm_layer, str):
self.norm2 = eval(norm_layer)(dim, epsilon=epsilon)
elif isinstance(norm_layer, Callable):
self.norm2 = norm_layer(dim)
else:
raise TypeError(
"The norm_layer must be str or paddle.nn.layer.Layer class")
mlp_hidden_dim = int(dim * mlp_ratio)
self.mlp = Mlp(in_features=dim,
hidden_features=mlp_hidden_dim,
......@@ -285,7 +310,21 @@ class VisionTransformer(nn.Layer):
return x
def ViT_small_patch16_224(**kwargs):
def _load_pretrained(pretrained, model, model_url, use_ssld=False):
if pretrained is False:
pass
elif pretrained is True:
load_dygraph_pretrain_from_url(model, model_url, use_ssld=use_ssld)
elif isinstance(pretrained, str):
load_dygraph_pretrain(model, pretrained)
else:
raise RuntimeError(
"pretrained type is not available. Please use `string` or `boolean` type."
)
def ViT_small_patch16_224(pretrained, model, model_url, use_ssld=False, **kwargs):
model = VisionTransformer(
patch_size=16,
embed_dim=768,
......@@ -294,10 +333,12 @@ def ViT_small_patch16_224(**kwargs):
mlp_ratio=3,
qk_scale=768**-0.5,
**kwargs)
_load_pretrained(pretrained, model, MODEL_URLS["ViT_small_patch16_224"], use_ssld=use_ssld)
return model
def ViT_base_patch16_224(**kwargs):
def ViT_base_patch16_224(pretrained, model, model_url, use_ssld=False, **kwargs):
model = VisionTransformer(
patch_size=16,
embed_dim=768,
......@@ -307,10 +348,11 @@ def ViT_base_patch16_224(**kwargs):
qkv_bias=True,
epsilon=1e-6,
**kwargs)
_load_pretrained(pretrained, model, MODEL_URLS["ViT_base_patch16_224"], use_ssld=use_ssld)
return model
def ViT_base_patch16_384(**kwargs):
def ViT_base_patch16_384(pretrained, model, model_url, use_ssld=False, **kwargs):
model = VisionTransformer(
img_size=384,
patch_size=16,
......@@ -321,10 +363,11 @@ def ViT_base_patch16_384(**kwargs):
qkv_bias=True,
epsilon=1e-6,
**kwargs)
_load_pretrained(pretrained, model, MODEL_URLS["ViT_base_patch16_384"], use_ssld=use_ssld)
return model
def ViT_base_patch32_384(**kwargs):
def ViT_base_patch32_384(pretrained, model, model_url, use_ssld=False, **kwargs):
model = VisionTransformer(
img_size=384,
patch_size=32,
......@@ -335,10 +378,11 @@ def ViT_base_patch32_384(**kwargs):
qkv_bias=True,
epsilon=1e-6,
**kwargs)
_load_pretrained(pretrained, model, MODEL_URLS["ViT_base_patch32_384"], use_ssld=use_ssld)
return model
def ViT_large_patch16_224(**kwargs):
def ViT_large_patch16_224(pretrained, model, model_url, use_ssld=False, **kwargs):
model = VisionTransformer(
patch_size=16,
embed_dim=1024,
......@@ -348,10 +392,11 @@ def ViT_large_patch16_224(**kwargs):
qkv_bias=True,
epsilon=1e-6,
**kwargs)
_load_pretrained(pretrained, model, MODEL_URLS["ViT_large_patch16_224"], use_ssld=use_ssld)
return model
def ViT_large_patch16_384(**kwargs):
def ViT_large_patch16_384(pretrained, model, model_url, use_ssld=False, **kwargs):
model = VisionTransformer(
img_size=384,
patch_size=16,
......@@ -362,10 +407,11 @@ def ViT_large_patch16_384(**kwargs):
qkv_bias=True,
epsilon=1e-6,
**kwargs)
_load_pretrained(pretrained, model, MODEL_URLS["ViT_large_patch16_384"], use_ssld=use_ssld)
return model
def ViT_large_patch32_384(**kwargs):
def ViT_large_patch32_384(pretrained, model, model_url, use_ssld=False, **kwargs):
model = VisionTransformer(
img_size=384,
patch_size=32,
......@@ -376,10 +422,11 @@ def ViT_large_patch32_384(**kwargs):
qkv_bias=True,
epsilon=1e-6,
**kwargs)
_load_pretrained(pretrained, model, MODEL_URLS["ViT_large_patch32_384"], use_ssld=use_ssld)
return model
def ViT_huge_patch16_224(**kwargs):
def ViT_huge_patch16_224(pretrained, model, model_url, use_ssld=False, **kwargs):
model = VisionTransformer(
patch_size=16,
embed_dim=1280,
......@@ -387,10 +434,11 @@ def ViT_huge_patch16_224(**kwargs):
num_heads=16,
mlp_ratio=4,
**kwargs)
_load_pretrained(pretrained, model, MODEL_URLS["ViT_huge_patch16_224"], use_ssld=use_ssld)
return model
def ViT_huge_patch32_384(**kwargs):
def ViT_huge_patch32_384(pretrained, model, model_url, use_ssld=False, **kwargs):
model = VisionTransformer(
img_size=384,
patch_size=32,
......@@ -399,4 +447,5 @@ def ViT_huge_patch32_384(**kwargs):
num_heads=16,
mlp_ratio=4,
**kwargs)
_load_pretrained(pretrained, model, MODEL_URLS["ViT_huge_patch32_384"], use_ssld=use_ssld)
return model
......@@ -8,7 +8,16 @@ from paddle.nn.initializer import Uniform
import math
import sys
__all__ = ['Xception41', 'Xception65', 'Xception71']
from ppcls.utils.save_load import load_dygraph_pretrain, load_dygraph_pretrain_from_url
MODEL_URLS = {
"Xception41": "https://paddle-imagenet-models-name.bj.bcebos.com/dygraph/Xception41_pretrained.pdparams",
"Xception65": "https://paddle-imagenet-models-name.bj.bcebos.com/dygraph/Xception65_pretrained.pdparams",
"Xception71": "https://paddle-imagenet-models-name.bj.bcebos.com/dygraph/Xception71_pretrained.pdparams"
}
__all__ = list(MODEL_URLS.keys())
class ConvBNLayer(nn.Layer):
......@@ -329,17 +338,32 @@ class Xception(nn.Layer):
x = self._exit_flow(x)
return x
def Xception41(**args):
model = Xception(entry_flow_block_num=3, middle_flow_block_num=8, **args)
def _load_pretrained(pretrained, model, model_url, use_ssld=False):
if pretrained is False:
pass
elif pretrained is True:
load_dygraph_pretrain_from_url(model, model_url, use_ssld=use_ssld)
elif isinstance(pretrained, str):
load_dygraph_pretrain(model, pretrained)
else:
raise RuntimeError(
"pretrained type is not available. Please use `string` or `boolean` type."
)
def Xception41(pretrained=False, use_ssld=False, **kwargs):
model = Xception(entry_flow_block_num=3, middle_flow_block_num=8, **kwargs)
_load_pretrained(pretrained, model, MODEL_URLS["Xception41"], use_ssld=use_ssld)
return model
def Xception65(**args):
model = Xception(entry_flow_block_num=3, middle_flow_block_num=16, **args)
def Xception65(pretrained=False, use_ssld=False, **kwargs):
model = Xception(entry_flow_block_num=3, middle_flow_block_num=16, **kwargs)
_load_pretrained(pretrained, model, MODEL_URLS["Xception65"], use_ssld=use_ssld)
return model
def Xception71(**args):
model = Xception(entry_flow_block_num=5, middle_flow_block_num=16, **args)
def Xception71(pretrained=False, use_ssld=False, **kwargs):
model = Xception(entry_flow_block_num=5, middle_flow_block_num=16, **kwargs)
_load_pretrained(pretrained, model, MODEL_URLS["Xception71"], use_ssld=use_ssld)
return model
# copyright (c) 2021 PaddlePaddle Authors. All Rights Reserve.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
import paddle
from paddle import ParamAttr
import paddle.nn as nn
......@@ -5,7 +19,12 @@ import paddle.nn.functional as F
from paddle.nn import Conv2D, BatchNorm, Linear, Dropout
from paddle.nn import AdaptiveAvgPool2D, MaxPool2D, AvgPool2D
__all__ = ["Xception41_deeplab", "Xception65_deeplab", "Xception71_deeplab"]
from ppcls.utils.save_load import load_dygraph_pretrain, load_dygraph_pretrain_from_url
MODEL_URLS = {"Xception41_deeplab": "https://paddle-imagenet-models-name.bj.bcebos.com/dygraph/Xception41_deeplab_pretrained.pdparams",
"Xception65_deeplab": "https://paddle-imagenet-models-name.bj.bcebos.com/dygraph/Xception41_deeplab_pretrained.pdparams"}
__all__ = list(MODEL_URLS.keys())
def check_data(data, number):
......@@ -369,18 +388,28 @@ class XceptionDeeplab(nn.Layer):
x = paddle.squeeze(x, axis=[2, 3])
x = self._fc(x)
return x
def _load_pretrained(pretrained, model, model_url, use_ssld=False):
if pretrained is False:
pass
elif pretrained is True:
load_dygraph_pretrain_from_url(model, model_url, use_ssld=use_ssld)
elif isinstance(pretrained, str):
load_dygraph_pretrain(model, pretrained)
else:
raise RuntimeError(
"pretrained type is not available. Please use `string` or `boolean` type."
)
def Xception41_deeplab(**args):
model = XceptionDeeplab('xception_41', **args)
return model
def Xception65_deeplab(**args):
model = XceptionDeeplab("xception_65", **args)
def Xception41_deeplab(pretrained=False, use_ssld=False, **kwargs):
model = XceptionDeeplab('xception_41', **kwargs)
_load_pretrained(pretrained, model, MODEL_URLS["Xception41_deeplab"], use_ssld=use_ssld)
return model
def Xception71_deeplab(**args):
model = XceptionDeeplab("xception_71", **args)
def Xception65_deeplab(pretrained=False, use_ssld=False, **kwargs):
model = XceptionDeeplab("xception_65", **kwargs)
_load_pretrained(pretrained, model, MODEL_URLS["Xception65_deeplab"], use_ssld=use_ssld)
return model
# global configs
Global:
checkpoints: null
pretrained_model: null
output_dir: ./output/
device: gpu
class_num: 1000
save_interval: 1
eval_during_train: True
eval_interval: 1
epochs: 120
print_batch_step: 10
use_visualdl: False
# used for static mode and model export
image_shape: [3, 224, 224]
save_inference_dir: ./inference
# model architecture
Arch:
name: AlexNet
# loss function config for traing/eval process
Loss:
Train:
- CELoss:
weight: 1.0
Eval:
- CELoss:
weight: 1.0
Optimizer:
name: Momentum
momentum: 0.9
lr:
name: Piecewise
learning_rate: 0.01
decay_epochs: [30, 60, 90]
values: [0.1, 0.01, 0.001, 0.0001]
regularizer:
name: 'L2'
coeff: 0.0001
# data loader for train and eval
DataLoader:
Train:
dataset:
name: ImageNetDataset
image_root: ./dataset/ILSVRC2012/
cls_label_path: ./dataset/ILSVRC2012/train_list.txt
transform_ops:
- DecodeImage:
to_rgb: True
channel_first: False
- RandCropImage:
size: 224
- RandFlipImage:
flip_code: 1
- NormalizeImage:
scale: 1.0/255.0
mean: [0.485, 0.456, 0.406]
std: [0.229, 0.224, 0.225]
order: ''
sampler:
name: DistributedBatchSampler
batch_size: 64
drop_last: False
shuffle: True
loader:
num_workers: 4
use_shared_memory: True
Eval:
# TOTO: modify to the latest trainer
dataset:
name: ImageNetDataset
image_root: ./dataset/ILSVRC2012/
cls_label_path: ./dataset/ILSVRC2012/val_list.txt
transform_ops:
- DecodeImage:
to_rgb: True
channel_first: False
- ResizeImage:
resize_short: 256
- CropImage:
size: 224
- NormalizeImage:
scale: 1.0/255.0
mean: [0.485, 0.456, 0.406]
std: [0.229, 0.224, 0.225]
order: ''
sampler:
name: DistributedBatchSampler
batch_size: 64
drop_last: False
shuffle: False
loader:
num_workers: 4
use_shared_memory: True
Infer:
infer_imgs: docs/images/whl/demo.jpg
batch_size: 10
transforms:
- DecodeImage:
to_rgb: True
channel_first: False
- ResizeImage:
resize_short: 256
- CropImage:
size: 224
- NormalizeImage:
scale: 1.0/255.0
mean: [0.485, 0.456, 0.406]
std: [0.229, 0.224, 0.225]
order: ''
- ToCHWImage:
PostProcess:
name: Topk
topk: 5
class_id_map_file: ppcls/utils/imagenet1k_label_list.txt
Metric:
Train:
- TopkAcc:
topk: [1, 5]
Eval:
- TopkAcc:
topk: [1, 5]
# global configs
Global:
checkpoints: null
pretrained_model: null
output_dir: ./output/
device: gpu
class_num: 1000
save_interval: 1
eval_during_train: True
eval_interval: 1
epochs: 200
print_batch_step: 10
use_visualdl: False
# used for static mode and model export
image_shape: [3, 224, 224]
save_inference_dir: ./inference
# model architecture
Arch:
name: DPN107
# loss function config for traing/eval process
Loss:
Train:
- CELoss:
weight: 1.0
epsilon: 0.1
Eval:
- CELoss:
weight: 1.0
Optimizer:
name: Momentum
momentum: 0.9
lr:
name: Cosine
learning_rate: 0.1
regularizer:
name: 'L2'
coeff: 0.0001
# data loader for train and eval
DataLoader:
Train:
dataset:
name: ImageNetDataset
image_root: ./dataset/ILSVRC2012/
cls_label_path: ./dataset/ILSVRC2012/train_list.txt
transform_ops:
- DecodeImage:
to_rgb: True
channel_first: False
- RandCropImage:
size: 224
- RandFlipImage:
flip_code: 1
- NormalizeImage:
scale: 1.0/255.0
mean: [0.485, 0.456, 0.406]
std: [0.229, 0.224, 0.225]
order: ''
batch_transform_ops:
- MixupOperator:
alpha: 0.2
sampler:
name: DistributedBatchSampler
batch_size: 64
drop_last: False
shuffle: True
loader:
num_workers: 4
use_shared_memory: True
Eval:
# TOTO: modify to the latest trainer
dataset:
name: ImageNetDataset
image_root: ./dataset/ILSVRC2012/
cls_label_path: ./dataset/ILSVRC2012/val_list.txt
transform_ops:
- DecodeImage:
to_rgb: True
channel_first: False
- ResizeImage:
resize_short: 256
- CropImage:
size: 224
- NormalizeImage:
scale: 1.0/255.0
mean: [0.485, 0.456, 0.406]
std: [0.229, 0.224, 0.225]
order: ''
sampler:
name: DistributedBatchSampler
batch_size: 64
drop_last: False
shuffle: False
loader:
num_workers: 4
use_shared_memory: True
Infer:
infer_imgs: docs/images/whl/demo.jpg
batch_size: 10
transforms:
- DecodeImage:
to_rgb: True
channel_first: False
- ResizeImage:
resize_short: 256
- CropImage:
size: 224
- NormalizeImage:
scale: 1.0/255.0
mean: [0.485, 0.456, 0.406]
std: [0.229, 0.224, 0.225]
order: ''
- ToCHWImage:
PostProcess:
name: Topk
topk: 5
class_id_map_file: ppcls/utils/imagenet1k_label_list.txt
Metric:
Train:
Eval:
- TopkAcc:
topk: [1, 5]
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
......@@ -50,6 +50,9 @@ DataLoader:
image_root: ./dataset/ILSVRC2012/
cls_label_path: ./dataset/ILSVRC2012/train_list.txt
transform_ops:
- DecodeImage:
to_rgb: True
channel_first: False
- RandCropImage:
size: 224
- RandFlipImage:
......@@ -76,6 +79,9 @@ DataLoader:
image_root: ./dataset/ILSVRC2012/
cls_label_path: ./dataset/ILSVRC2012/val_list.txt
transform_ops:
- DecodeImage:
to_rgb: True
channel_first: False
- ResizeImage:
resize_short: 256
- CropImage:
......
......@@ -50,6 +50,9 @@ DataLoader:
image_root: ./dataset/ILSVRC2012/
cls_label_path: ./dataset/ILSVRC2012/train_list.txt
transform_ops:
- DecodeImage:
to_rgb: True
channel_first: False
- RandCropImage:
size: 224
- RandFlipImage:
......@@ -76,6 +79,9 @@ DataLoader:
image_root: ./dataset/ILSVRC2012/
cls_label_path: ./dataset/ILSVRC2012/val_list.txt
transform_ops:
- DecodeImage:
to_rgb: True
channel_first: False
- ResizeImage:
resize_short: 256
- CropImage:
......
......@@ -50,6 +50,9 @@ DataLoader:
image_root: ./dataset/ILSVRC2012/
cls_label_path: ./dataset/ILSVRC2012/train_list.txt
transform_ops:
- DecodeImage:
to_rgb: True
channel_first: False
- RandCropImage:
size: 224
- RandFlipImage:
......@@ -76,6 +79,9 @@ DataLoader:
image_root: ./dataset/ILSVRC2012/
cls_label_path: ./dataset/ILSVRC2012/val_list.txt
transform_ops:
- DecodeImage:
to_rgb: True
channel_first: False
- ResizeImage:
resize_short: 256
- CropImage:
......
......@@ -50,6 +50,9 @@ DataLoader:
image_root: ./dataset/ILSVRC2012/
cls_label_path: ./dataset/ILSVRC2012/train_list.txt
transform_ops:
- DecodeImage:
to_rgb: True
channel_first: False
- RandCropImage:
size: 224
- RandFlipImage:
......@@ -76,6 +79,9 @@ DataLoader:
image_root: ./dataset/ILSVRC2012/
cls_label_path: ./dataset/ILSVRC2012/val_list.txt
transform_ops:
- DecodeImage:
to_rgb: True
channel_first: False
- ResizeImage:
resize_short: 256
- CropImage:
......
......@@ -50,6 +50,9 @@ DataLoader:
image_root: ./dataset/ILSVRC2012/
cls_label_path: ./dataset/ILSVRC2012/train_list.txt
transform_ops:
- DecodeImage:
to_rgb: True
channel_first: False
- RandCropImage:
size: 224
- RandFlipImage:
......@@ -76,6 +79,9 @@ DataLoader:
image_root: ./dataset/ILSVRC2012/
cls_label_path: ./dataset/ILSVRC2012/val_list.txt
transform_ops:
- DecodeImage:
to_rgb: True
channel_first: False
- ResizeImage:
resize_short: 256
- CropImage:
......
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册