From fdcb57fb9c16ff917e853b07e387ff5c30da1580 Mon Sep 17 00:00:00 2001 From: Nyakku Shigure Date: Thu, 23 Jun 2022 15:27:22 +0800 Subject: [PATCH] fix paddle.vision.models.* en (#43636) * add outputs for code examples, test=document_fix * missing code example update, test=document_fix * missing returns, test=document_fix * fix the case of proper nouns, test=document_fix * fix SqueezeNet code example (add a blank line), test=document_fix * fix ShuffleNetV2 args style, test=document_fix * missing paper links, test=document_fix * missing `optional`, test=document_fix * refine parameter `pretrained`, test=document_fix * add parameter `kwargs`, test=document_fix * refine parameter `num_classes`, test=document_fix * capitalize the first letter, test=document_fix * missing output of code example, test=document_fix * fix wrong api label, test=document_fix * refine returns, test=document_fix * add missing `.` after paper link, test=document_fix * remove extra `:`, test=document_fix * :math:\`0.0\`, test=document_fix --- python/paddle/vision/models/alexnet.py | 30 +++++-- python/paddle/vision/models/densenet.py | 94 +++++++++++++++++---- python/paddle/vision/models/googlenet.py | 24 ++++-- python/paddle/vision/models/inceptionv3.py | 30 ++++--- python/paddle/vision/models/lenet.py | 14 ++- python/paddle/vision/models/mobilenetv1.py | 24 ++++-- python/paddle/vision/models/mobilenetv2.py | 24 ++++-- python/paddle/vision/models/mobilenetv3.py | 30 +++++-- python/paddle/vision/models/resnet.py | 78 +++++++++-------- python/paddle/vision/models/shufflenetv2.py | 94 +++++++++++++++------ python/paddle/vision/models/squeezenet.py | 51 +++++++++-- python/paddle/vision/models/vgg.py | 83 ++++++++++++++---- 12 files changed, 427 insertions(+), 149 deletions(-) diff --git a/python/paddle/vision/models/alexnet.py b/python/paddle/vision/models/alexnet.py index d483009fdeb..b24afac253f 100644 --- a/python/paddle/vision/models/alexnet.py +++ b/python/paddle/vision/models/alexnet.py @@ -74,18 +74,28 @@ class ConvPoolLayer(nn.Layer): class AlexNet(nn.Layer): """AlexNet model from `"ImageNet Classification with Deep Convolutional Neural Networks" - `_ + `_. Args: - num_classes (int): Output dim of last fc layer. Default: 1000. + num_classes (int, optional): Output dim of last fc layer. If num_classes <= 0, last fc layer + will not be defined. Default: 1000. + + Returns: + :ref:`api_paddle_nn_Layer`. An instance of AlexNet model. Examples: .. code-block:: python + import paddle from paddle.vision.models import AlexNet alexnet = AlexNet() + x = paddle.rand([1, 3, 224, 224]) + out = alexnet(x) + + print(out.shape) + # [1, 1000] """ def __init__(self, num_classes=1000): @@ -175,19 +185,21 @@ def _alexnet(arch, pretrained, **kwargs): def alexnet(pretrained=False, **kwargs): - """ - AlexNet model + """AlexNet model from + `"ImageNet Classification with Deep Convolutional Neural Networks" + `_. Args: - pretrained (bool, optional): If True, returns a model pre-trained on ImageNet. Default: False. - **kwargs: Additional keyword arguments,For details, please refer to :ref:`AlexNet `. - + pretrained (bool, optional): Whether to load pre-trained weights. If True, returns a model pre-trained + on ImageNet. Default: False. + **kwargs (optional): Additional keyword arguments. For details, please refer to :ref:`AlexNet `. + Returns: - the model of alexnet. + :ref:`api_paddle_nn_Layer`. An instance of AlexNet model. Examples: .. code-block:: python - :name: code-example + import paddle from paddle.vision.models import alexnet diff --git a/python/paddle/vision/models/densenet.py b/python/paddle/vision/models/densenet.py index a764be95445..5580b97a3a8 100644 --- a/python/paddle/vision/models/densenet.py +++ b/python/paddle/vision/models/densenet.py @@ -185,14 +185,18 @@ class ConvBNLayer(nn.Layer): class DenseNet(nn.Layer): """DenseNet model from - `"Densely Connected Convolutional Networks" `_ + `"Densely Connected Convolutional Networks" `_. Args: - layers (int): layers of densenet. Default: 121. - bn_size (int): expansion of growth rate in the middle layer. Default: 4. - dropout (float): dropout rate. Default: 0.. - num_classes (int): output dim of last fc layer. Default: 1000. - with_pool (bool): use pool before the last fc layer or not. Default: True. + layers (int, optional): Layers of DenseNet. Default: 121. + bn_size (int, optional): Expansion of growth rate in the middle layer. Default: 4. + dropout (float, optional): Dropout rate. Default: :math:`0.0`. + num_classes (int, optional): Output dim of last fc layer. If num_classes <= 0, last fc layer + will not be defined. Default: 1000. + with_pool (bool, optional): Use pool before the last fc layer or not. Default: True. + + Returns: + :ref:`api_paddle_nn_Layer`. An instance of DenseNet model. Examples: .. code-block:: python @@ -207,6 +211,7 @@ class DenseNet(nn.Layer): out = densenet(x) print(out.shape) + # [1, 1000] """ def __init__(self, @@ -314,14 +319,21 @@ def _densenet(arch, layers, pretrained, **kwargs): def densenet121(pretrained=False, **kwargs): - """DenseNet 121-layer model + """DenseNet 121-layer model from + `"Densely Connected Convolutional Networks" `_. Args: - pretrained (bool): If True, returns a model pre-trained on ImageNet + pretrained (bool, optional): Whether to load pre-trained weights. If True, returns a model pre-trained + on ImageNet. Default: False. + **kwargs (optional): Additional keyword arguments. For details, please refer to :ref:`DenseNet `. + + Returns: + :ref:`api_paddle_nn_Layer`. An instance of DenseNet 121-layer model. Examples: .. code-block:: python + import paddle from paddle.vision.models import densenet121 # build model @@ -329,15 +341,27 @@ def densenet121(pretrained=False, **kwargs): # build model and load imagenet pretrained weight # model = densenet121(pretrained=True) + + x = paddle.rand([1, 3, 224, 224]) + out = model(x) + + print(out.shape) + # [1, 1000] """ return _densenet('densenet121', 121, pretrained, **kwargs) def densenet161(pretrained=False, **kwargs): - """DenseNet 161-layer model + """DenseNet 161-layer model from + `"Densely Connected Convolutional Networks" `_. Args: - pretrained (bool): If True, returns a model pre-trained on ImageNet + pretrained (bool, optional): Whether to load pre-trained weights. If True, returns a model pre-trained + on ImageNet. Default: False. + **kwargs (optional): Additional keyword arguments. For details, please refer to :ref:`DenseNet `. + + Returns: + :ref:`api_paddle_nn_Layer`. An instance of DenseNet 161-layer model. Examples: .. code-block:: python @@ -354,14 +378,21 @@ def densenet161(pretrained=False, **kwargs): def densenet169(pretrained=False, **kwargs): - """DenseNet 169-layer model + """DenseNet 169-layer model from + `"Densely Connected Convolutional Networks" `_. Args: - pretrained (bool): If True, returns a model pre-trained on ImageNet + pretrained (bool, optional): Whether to load pre-trained weights. If True, returns a model pre-trained + on ImageNet. Default: False. + **kwargs (optional): Additional keyword arguments. For details, please refer to :ref:`DenseNet `. + + Returns: + :ref:`api_paddle_nn_Layer`. An instance of DenseNet 169-layer model. Examples: .. code-block:: python + import paddle from paddle.vision.models import densenet169 # build model @@ -369,19 +400,32 @@ def densenet169(pretrained=False, **kwargs): # build model and load imagenet pretrained weight # model = densenet169(pretrained=True) + + x = paddle.rand([1, 3, 224, 224]) + out = model(x) + + print(out.shape) + # [1, 1000] """ return _densenet('densenet169', 169, pretrained, **kwargs) def densenet201(pretrained=False, **kwargs): - """DenseNet 201-layer model + """DenseNet 201-layer model from + `"Densely Connected Convolutional Networks" `_. Args: - pretrained (bool): If True, returns a model pre-trained on ImageNet + pretrained (bool, optional): Whether to load pre-trained weights. If True, returns a model pre-trained + on ImageNet. Default: False. + **kwargs (optional): Additional keyword arguments. For details, please refer to :ref:`DenseNet `. + + Returns: + :ref:`api_paddle_nn_Layer`. An instance of DenseNet 201-layer model. Examples: .. code-block:: python + import paddle from paddle.vision.models import densenet201 # build model @@ -389,19 +433,31 @@ def densenet201(pretrained=False, **kwargs): # build model and load imagenet pretrained weight # model = densenet201(pretrained=True) + x = paddle.rand([1, 3, 224, 224]) + out = model(x) + + print(out.shape) + # [1, 1000] """ return _densenet('densenet201', 201, pretrained, **kwargs) def densenet264(pretrained=False, **kwargs): - """DenseNet 264-layer model + """DenseNet 264-layer model from + `"Densely Connected Convolutional Networks" `_. Args: - pretrained (bool): If True, returns a model pre-trained on ImageNet + pretrained (bool, optional): Whether to load pre-trained weights. If True, returns a model pre-trained + on ImageNet. Default: False. + **kwargs (optional): Additional keyword arguments. For details, please refer to :ref:`DenseNet `. + + Returns: + :ref:`api_paddle_nn_Layer`. An instance of DenseNet 264-layer model. Examples: .. code-block:: python + import paddle from paddle.vision.models import densenet264 # build model @@ -409,5 +465,11 @@ def densenet264(pretrained=False, **kwargs): # build model and load imagenet pretrained weight # model = densenet264(pretrained=True) + + x = paddle.rand([1, 3, 224, 224]) + out = model(x) + + print(out.shape) + # [1, 1000] """ return _densenet('densenet264', 264, pretrained, **kwargs) diff --git a/python/paddle/vision/models/googlenet.py b/python/paddle/vision/models/googlenet.py index b1d1d38e2ee..b5fc9ae4ab2 100644 --- a/python/paddle/vision/models/googlenet.py +++ b/python/paddle/vision/models/googlenet.py @@ -97,12 +97,15 @@ class Inception(nn.Layer): class GoogLeNet(nn.Layer): """GoogLeNet (Inception v1) model architecture from - `"Going Deeper with Convolutions" `_ + `"Going Deeper with Convolutions" `_. Args: - num_classes (int): output dim of last fc layer. If num_classes <=0, last fc layer + num_classes (int, optional): Output dim of last fc layer. If num_classes <= 0, last fc layer will not be defined. Default: 1000. - with_pool (bool, optional): use pool before the last fc layer or not. Default: True. + with_pool (bool, optional): Use pool before the last fc layer or not. Default: True. + + Returns: + :ref:`api_paddle_nn_Layer`. An instance of GoogLeNet (Inception v1) model. Examples: .. code-block:: python @@ -116,7 +119,8 @@ class GoogLeNet(nn.Layer): x = paddle.rand([1, 3, 224, 224]) out, out1, out2 = model(x) - print(out.shape) + print(out.shape, out1.shape, out2.shape) + # [1, 1000] [1, 1000] [1, 1000] """ def __init__(self, num_classes=1000, with_pool=True): @@ -219,10 +223,15 @@ class GoogLeNet(nn.Layer): def googlenet(pretrained=False, **kwargs): """GoogLeNet (Inception v1) model architecture from - `"Going Deeper with Convolutions" `_ + `"Going Deeper with Convolutions" `_. Args: - pretrained (bool): If True, returns a model pre-trained on ImageNet + pretrained (bool, optional): Whether to load pre-trained weights. If True, returns a model pre-trained + on ImageNet. Default: False. + **kwargs (optional): Additional keyword arguments. For details, please refer to :ref:`GoogLeNet `. + + Returns: + :ref:`api_paddle_nn_Layer`. An instance of GoogLeNet (Inception v1) model. Examples: .. code-block:: python @@ -239,7 +248,8 @@ def googlenet(pretrained=False, **kwargs): x = paddle.rand([1, 3, 224, 224]) out, out1, out2 = model(x) - print(out.shape) + print(out.shape, out1.shape, out2.shape) + # [1, 1000] [1, 1000] [1, 1000] """ model = GoogLeNet(**kwargs) arch = "googlenet" diff --git a/python/paddle/vision/models/inceptionv3.py b/python/paddle/vision/models/inceptionv3.py index 8ffb23e62ce..a2a06de3d85 100644 --- a/python/paddle/vision/models/inceptionv3.py +++ b/python/paddle/vision/models/inceptionv3.py @@ -413,12 +413,16 @@ class InceptionE(nn.Layer): class InceptionV3(nn.Layer): - """ - InceptionV3 + """Inception v3 model from + `"Rethinking the Inception Architecture for Computer Vision" `_. + Args: - num_classes (int, optional): output dim of last fc layer. If num_classes <=0, last fc layer - will not be defined. Default: 1000. - with_pool (bool, optional): use pool before the last fc layer or not. Default: True. + num_classes (int, optional): Output dim of last fc layer. If num_classes <= 0, last fc layer + will not be defined. Default: 1000. + with_pool (bool, optional): Use pool before the last fc layer or not. Default: True. + + Returns: + :ref:`api_paddle_nn_Layer`. An instance of Inception v3 model. Examples: .. code-block:: python @@ -432,6 +436,7 @@ class InceptionV3(nn.Layer): out = inception_v3(x) print(out.shape) + # [1, 1000] """ def __init__(self, num_classes=1000, with_pool=True): @@ -505,13 +510,17 @@ class InceptionV3(nn.Layer): def inception_v3(pretrained=False, **kwargs): - """ - InceptionV3 model from - `"Rethinking the Inception Architecture for Computer Vision" `_ + """Inception v3 model from + `"Rethinking the Inception Architecture for Computer Vision" `_. Args: - pretrained (bool): If True, returns a model pre-trained on ImageNet - + pretrained (bool, optional): Whether to load pre-trained weights. If True, returns a model pre-trained + on ImageNet. Default: False. + **kwargs (optional): Additional keyword arguments. For details, please refer to :ref:`InceptionV3 `. + + Returns: + :ref:`api_paddle_nn_Layer`. An instance of Inception v3 model. + Examples: .. code-block:: python @@ -528,6 +537,7 @@ def inception_v3(pretrained=False, **kwargs): out = model(x) print(out.shape) + # [1, 1000] """ model = InceptionV3(**kwargs) arch = "inception_v3" diff --git a/python/paddle/vision/models/lenet.py b/python/paddle/vision/models/lenet.py index a526bb719ef..1d446569a66 100644 --- a/python/paddle/vision/models/lenet.py +++ b/python/paddle/vision/models/lenet.py @@ -20,18 +20,28 @@ __all__ = [] class LeNet(nn.Layer): """LeNet model from - `"LeCun Y, Bottou L, Bengio Y, et al. Gradient-based learning applied to document recognition[J]. Proceedings of the IEEE, 1998, 86(11): 2278-2324.`_ + `"Gradient-based learning applied to document recognition" `_. Args: - num_classes (int): output dim of last fc layer. If num_classes <=0, last fc layer + num_classes (int, optional): Output dim of last fc layer. If num_classes <= 0, last fc layer will not be defined. Default: 10. + Returns: + :ref:`api_paddle_nn_Layer`. An instance of LeNet model. + Examples: .. code-block:: python + import paddle from paddle.vision.models import LeNet model = LeNet() + + x = paddle.rand([1, 1, 28, 28]) + out = model(x) + + print(out.shape) + # [1, 10] """ def __init__(self, num_classes=10): diff --git a/python/paddle/vision/models/mobilenetv1.py b/python/paddle/vision/models/mobilenetv1.py index 3cc5e5a20e9..6359fcffcdf 100644 --- a/python/paddle/vision/models/mobilenetv1.py +++ b/python/paddle/vision/models/mobilenetv1.py @@ -58,14 +58,17 @@ class MobileNetV1(nn.Layer): `"MobileNets: Efficient Convolutional Neural Networks for Mobile Vision Applications" `_. Args: - scale (float, optional): scale of channels in each layer. Default: 1.0. - num_classes (int, optional): output dim of last fc layer. If num_classes <=0, last fc layer + scale (float, optional): Scale of channels in each layer. Default: 1.0. + num_classes (int, optional): Output dim of last fc layer. If num_classes <= 0, last fc layer will not be defined. Default: 1000. - with_pool (bool, optional): use pool before the last fc layer or not. Default: True. + with_pool (bool, optional): Use pool before the last fc layer or not. Default: True. + + Returns: + :ref:`api_paddle_nn_Layer`. An instance of MobileNetV1 model. Examples: .. code-block:: python - :name: code-example1 + import paddle from paddle.vision.models import MobileNetV1 @@ -217,11 +220,17 @@ def _mobilenet(arch, pretrained=False, **kwargs): def mobilenet_v1(pretrained=False, scale=1.0, **kwargs): - """MobileNetV1 + """MobileNetV1 from + `"MobileNets: Efficient Convolutional Neural Networks for Mobile Vision Applications" `_. Args: - pretrained (bool): If True, returns a model pre-trained on ImageNet. Default: False. - scale: (float): scale of channels in each layer. Default: 1.0. + pretrained (bool, optional): Whether to load pre-trained weights. If True, returns a model pre-trained + on ImageNet. Default: False. + scale (float, optional): Scale of channels in each layer. Default: 1.0. + **kwargs (optional): Additional keyword arguments. For details, please refer to :ref:`MobileNetV1 `. + + Returns: + :ref:`api_paddle_nn_Layer`. An instance of MobileNetV1 model. Examples: .. code-block:: python @@ -242,6 +251,7 @@ def mobilenet_v1(pretrained=False, scale=1.0, **kwargs): out = model(x) print(out.shape) + # [1, 1000] """ model = _mobilenet('mobilenetv1_' + str(scale), pretrained, diff --git a/python/paddle/vision/models/mobilenetv2.py b/python/paddle/vision/models/mobilenetv2.py index 80ca7105cb4..88fa8ebf6e6 100644 --- a/python/paddle/vision/models/mobilenetv2.py +++ b/python/paddle/vision/models/mobilenetv2.py @@ -75,14 +75,17 @@ class MobileNetV2(nn.Layer): `"MobileNetV2: Inverted Residuals and Linear Bottlenecks" `_. Args: - scale (float, optional): scale of channels in each layer. Default: 1.0. - num_classes (int, optional): output dim of last fc layer. If num_classes <=0, last fc layer + scale (float, optional): Scale of channels in each layer. Default: 1.0. + num_classes (int, optional): Output dim of last fc layer. If num_classes <= 0, last fc layer will not be defined. Default: 1000. - with_pool (bool, optional): use pool before the last fc layer or not. Default: True. + with_pool (bool, optional): Use pool before the last fc layer or not. Default: True. + + Returns: + :ref:`api_paddle_nn_Layer`. An instance of MobileNetV2 model. Examples: .. code-block:: python - :name: code-example1 + import paddle from paddle.vision.models import MobileNetV2 @@ -181,11 +184,17 @@ def _mobilenet(arch, pretrained=False, **kwargs): def mobilenet_v2(pretrained=False, scale=1.0, **kwargs): - """MobileNetV2 + """MobileNetV2 from + `"MobileNetV2: Inverted Residuals and Linear Bottlenecks" `_. Args: - pretrained (bool): If True, returns a model pre-trained on ImageNet. Default: False. - scale: (float): scale of channels in each layer. Default: 1.0. + pretrained (bool, optional): Whether to load pre-trained weights. If True, returns a model pre-trained + on ImageNet. Default: False. + scale (float, optional): Scale of channels in each layer. Default: 1.0. + **kwargs (optional): Additional keyword arguments. For details, please refer to :ref:`MobileNetV2 `. + + Returns: + :ref:`api_paddle_nn_Layer`. An instance of MobileNetV2 model. Examples: .. code-block:: python @@ -206,6 +215,7 @@ def mobilenet_v2(pretrained=False, scale=1.0, **kwargs): out = model(x) print(out.shape) + # [1, 1000] """ model = _mobilenet('mobilenetv2_' + str(scale), pretrained, diff --git a/python/paddle/vision/models/mobilenetv3.py b/python/paddle/vision/models/mobilenetv3.py index 0dd97755b62..8d3c8520ec6 100644 --- a/python/paddle/vision/models/mobilenetv3.py +++ b/python/paddle/vision/models/mobilenetv3.py @@ -254,10 +254,13 @@ class MobileNetV3Small(MobileNetV3): Args: scale (float, optional): Scale of channels in each layer. Default: 1.0. - num_classes (int, optional): Output dim of last fc layer. If num_classes <=0, last fc layer + num_classes (int, optional): Output dim of last fc layer. If num_classes <= 0, last fc layer will not be defined. Default: 1000. with_pool (bool, optional): Use pool before the last fc layer or not. Default: True. + Returns: + :ref:`api_paddle_nn_Layer`. An instance of MobileNetV3 Small architecture model. + Examples: .. code-block:: python @@ -271,6 +274,7 @@ class MobileNetV3Small(MobileNetV3): out = model(x) print(out.shape) + # [1, 1000] """ def __init__(self, scale=1.0, num_classes=1000, with_pool=True): @@ -301,10 +305,13 @@ class MobileNetV3Large(MobileNetV3): Args: scale (float, optional): Scale of channels in each layer. Default: 1.0. - num_classes (int, optional): Output dim of last fc layer. If num_classes <=0, last fc layer + num_classes (int, optional): Output dim of last fc layer. If num_classes <= 0, last fc layer will not be defined. Default: 1000. with_pool (bool, optional): Use pool before the last fc layer or not. Default: True. + Returns: + :ref:`api_paddle_nn_Layer`. An instance of MobileNetV3 Large architecture model. + Examples: .. code-block:: python @@ -318,6 +325,7 @@ class MobileNetV3Large(MobileNetV3): out = model(x) print(out.shape) + # [1, 1000] """ def __init__(self, scale=1.0, num_classes=1000, with_pool=True): @@ -379,8 +387,13 @@ def mobilenet_v3_small(pretrained=False, scale=1.0, **kwargs): `"Searching for MobileNetV3" `_. Args: - pretrained (bool): If True, returns a model pre-trained on ImageNet. Default: False. + pretrained (bool, optional): Whether to load pre-trained weights. If True, returns a model pre-trained + on ImageNet. Default: False. scale (float, optional): Scale of channels in each layer. Default: 1.0. + **kwargs (optional): Additional keyword arguments. For details, please refer to :ref:`MobileNetV3Small `. + + Returns: + :ref:`api_paddle_nn_Layer`. An instance of MobileNetV3 Small architecture model. Examples: .. code-block:: python @@ -401,7 +414,7 @@ def mobilenet_v3_small(pretrained=False, scale=1.0, **kwargs): out = model(x) print(out.shape) - + # [1, 1000] """ model = _mobilenet_v3("mobilenet_v3_small", scale=scale, @@ -415,8 +428,13 @@ def mobilenet_v3_large(pretrained=False, scale=1.0, **kwargs): `"Searching for MobileNetV3" `_. Args: - pretrained (bool): If True, returns a model pre-trained on ImageNet. Default: False. + pretrained (bool, optional): Whether to load pre-trained weights. If True, returns a model pre-trained + on ImageNet. Default: False. scale (float, optional): Scale of channels in each layer. Default: 1.0. + **kwargs (optional): Additional keyword arguments. For details, please refer to :ref:`MobileNetV3Large `. + + Returns: + :ref:`api_paddle_nn_Layer`. An instance of MobileNetV3 Large architecture model. Examples: .. code-block:: python @@ -437,7 +455,7 @@ def mobilenet_v3_large(pretrained=False, scale=1.0, **kwargs): out = model(x) print(out.shape) - + # [1, 1000] """ model = _mobilenet_v3("mobilenet_v3_large", scale=scale, diff --git a/python/paddle/vision/models/resnet.py b/python/paddle/vision/models/resnet.py index b1263f62dca..4cf479c0572 100644 --- a/python/paddle/vision/models/resnet.py +++ b/python/paddle/vision/models/resnet.py @@ -177,19 +177,19 @@ class BottleneckBlock(nn.Layer): class ResNet(nn.Layer): """ResNet model from - `"Deep Residual Learning for Image Recognition" `_ + `"Deep Residual Learning for Image Recognition" `_. Args: - Block (BasicBlock|BottleneckBlock): block module of model. - depth (int, optional): layers of ResNet, Default: 50. - width (int, optional): base width per convolution group for each convolution block, Default: 64. - num_classes (int, optional): output dim of last fc layer. If num_classes <=0, last fc layer + Block (BasicBlock|BottleneckBlock): Block module of model. + depth (int, optional): Layers of ResNet, Default: 50. + width (int, optional): Base width per convolution group for each convolution block, Default: 64. + num_classes (int, optional): Output dim of last fc layer. If num_classes <= 0, last fc layer will not be defined. Default: 1000. - with_pool (bool, optional): use pool before the last fc layer or not. Default: True. - groups (int, optional): number of groups for each convolution block, Default: 1. + with_pool (bool, optional): Use pool before the last fc layer or not. Default: True. + groups (int, optional): Number of groups for each convolution block, Default: 1. Returns: - ResNet model. An instance of :ref:`api_fluid_dygraph_Layer`. + :ref:`api_paddle_nn_Layer`. An instance of ResNet model. Examples: .. code-block:: python @@ -215,7 +215,6 @@ class ResNet(nn.Layer): print(out.shape) # [1, 1000] - """ def __init__(self, @@ -330,14 +329,15 @@ def _resnet(arch, Block, depth, pretrained, **kwargs): def resnet18(pretrained=False, **kwargs): """ResNet 18-layer model from - `"Deep Residual Learning for Image Recognition" `_ + `"Deep Residual Learning for Image Recognition" `_. Args: pretrained (bool, optional): Whether to load pre-trained weights. If True, returns a model pre-trained on ImageNet. Default: False. + **kwargs (optional): Additional keyword arguments. For details, please refer to :ref:`ResNet `. Returns: - ResNet 18-layer model. An instance of :ref:`api_fluid_dygraph_Layer`. + :ref:`api_paddle_nn_Layer`. An instance of ResNet 18-layer model. Examples: .. code-block:: python @@ -362,14 +362,15 @@ def resnet18(pretrained=False, **kwargs): def resnet34(pretrained=False, **kwargs): """ResNet 34-layer model from - `"Deep Residual Learning for Image Recognition" `_ + `"Deep Residual Learning for Image Recognition" `_. Args: pretrained (bool, optional): Whether to load pre-trained weights. If True, returns a model pre-trained on ImageNet. Default: False. + **kwargs (optional): Additional keyword arguments. For details, please refer to :ref:`ResNet `. Returns: - ResNet 34-layer model. An instance of :ref:`api_fluid_dygraph_Layer`. + :ref:`api_paddle_nn_Layer`. An instance of ResNet 34-layer model. Examples: .. code-block:: python @@ -394,14 +395,15 @@ def resnet34(pretrained=False, **kwargs): def resnet50(pretrained=False, **kwargs): """ResNet 50-layer model from - `"Deep Residual Learning for Image Recognition" `_ + `"Deep Residual Learning for Image Recognition" `_. Args: pretrained (bool, optional): Whether to load pre-trained weights. If True, returns a model pre-trained on ImageNet. Default: False. + **kwargs (optional): Additional keyword arguments. For details, please refer to :ref:`ResNet `. Returns: - ResNet 50-layer model. An instance of :ref:`api_fluid_dygraph_Layer`. + :ref:`api_paddle_nn_Layer`. An instance of ResNet 50-layer model. Examples: .. code-block:: python @@ -426,14 +428,15 @@ def resnet50(pretrained=False, **kwargs): def resnet101(pretrained=False, **kwargs): """ResNet 101-layer model from - `"Deep Residual Learning for Image Recognition" `_ + `"Deep Residual Learning for Image Recognition" `_. Args: pretrained (bool, optional): Whether to load pre-trained weights. If True, returns a model pre-trained on ImageNet. Default: False. + **kwargs (optional): Additional keyword arguments. For details, please refer to :ref:`ResNet `. Returns: - ResNet 101-layer. An instance of :ref:`api_fluid_dygraph_Layer`. + :ref:`api_paddle_nn_Layer`. An instance of ResNet 101-layer. Examples: .. code-block:: python @@ -458,14 +461,15 @@ def resnet101(pretrained=False, **kwargs): def resnet152(pretrained=False, **kwargs): """ResNet 152-layer model from - `"Deep Residual Learning for Image Recognition" `_ + `"Deep Residual Learning for Image Recognition" `_. Args: pretrained (bool, optional): Whether to load pre-trained weights. If True, returns a model pre-trained on ImageNet. Default: False. + **kwargs (optional): Additional keyword arguments. For details, please refer to :ref:`ResNet `. Returns: - ResNet 152-layer model. An instance of :ref:`api_fluid_dygraph_Layer`. + :ref:`api_paddle_nn_Layer`. An instance of ResNet 152-layer model. Examples: .. code-block:: python @@ -490,14 +494,15 @@ def resnet152(pretrained=False, **kwargs): def resnext50_32x4d(pretrained=False, **kwargs): """ResNeXt-50 32x4d model from - `"Aggregated Residual Transformations for Deep Neural Networks" `_ + `"Aggregated Residual Transformations for Deep Neural Networks" `_. Args: pretrained (bool, optional): Whether to load pre-trained weights. If True, returns a model pre-trained on ImageNet. Default: False. + **kwargs (optional): Additional keyword arguments. For details, please refer to :ref:`ResNet `. Returns: - ResNeXt-50 32x4d model. An instance of :ref:`api_fluid_dygraph_Layer`. + :ref:`api_paddle_nn_Layer`. An instance of ResNeXt-50 32x4d model. Examples: .. code-block:: python @@ -524,14 +529,15 @@ def resnext50_32x4d(pretrained=False, **kwargs): def resnext50_64x4d(pretrained=False, **kwargs): """ResNeXt-50 64x4d model from - `"Aggregated Residual Transformations for Deep Neural Networks" `_ + `"Aggregated Residual Transformations for Deep Neural Networks" `_. Args: pretrained (bool, optional): Whether to load pre-trained weights. If True, returns a model pre-trained on ImageNet. Default: False. + **kwargs (optional): Additional keyword arguments. For details, please refer to :ref:`ResNet `. Returns: - ResNeXt-50 64x4d model. An instance of :ref:`api_fluid_dygraph_Layer`. + :ref:`api_paddle_nn_Layer`. An instance of ResNeXt-50 64x4d model. Examples: .. code-block:: python @@ -558,14 +564,15 @@ def resnext50_64x4d(pretrained=False, **kwargs): def resnext101_32x4d(pretrained=False, **kwargs): """ResNeXt-101 32x4d model from - `"Aggregated Residual Transformations for Deep Neural Networks" `_ + `"Aggregated Residual Transformations for Deep Neural Networks" `_. Args: pretrained (bool, optional): Whether to load pre-trained weights. If True, returns a model pre-trained on ImageNet. Default: False. + **kwargs (optional): Additional keyword arguments. For details, please refer to :ref:`ResNet `. Returns: - ResNeXt-101 32x4d model. An instance of :ref:`api_fluid_dygraph_Layer`. + :ref:`api_paddle_nn_Layer`. An instance of ResNeXt-101 32x4d model. Examples: .. code-block:: python @@ -593,14 +600,15 @@ def resnext101_32x4d(pretrained=False, **kwargs): def resnext101_64x4d(pretrained=False, **kwargs): """ResNeXt-101 64x4d model from - `"Aggregated Residual Transformations for Deep Neural Networks" `_ + `"Aggregated Residual Transformations for Deep Neural Networks" `_. Args: pretrained (bool, optional): Whether to load pre-trained weights. If True, returns a model pre-trained on ImageNet. Default: False. + **kwargs (optional): Additional keyword arguments. For details, please refer to :ref:`ResNet `. Returns: - ResNeXt-101 64x4d model. An instance of :ref:`api_fluid_dygraph_Layer`. + :ref:`api_paddle_nn_Layer`. An instance of ResNeXt-101 64x4d model. Examples: .. code-block:: python @@ -628,14 +636,15 @@ def resnext101_64x4d(pretrained=False, **kwargs): def resnext152_32x4d(pretrained=False, **kwargs): """ResNeXt-152 32x4d model from - `"Aggregated Residual Transformations for Deep Neural Networks" `_ + `"Aggregated Residual Transformations for Deep Neural Networks" `_. Args: pretrained (bool, optional): Whether to load pre-trained weights. If True, returns a model pre-trained on ImageNet. Default: False. + **kwargs (optional): Additional keyword arguments. For details, please refer to :ref:`ResNet `. Returns: - ResNeXt-152 32x4d model. An instance of :ref:`api_fluid_dygraph_Layer`. + :ref:`api_paddle_nn_Layer`. An instance of ResNeXt-152 32x4d model. Examples: .. code-block:: python @@ -663,14 +672,15 @@ def resnext152_32x4d(pretrained=False, **kwargs): def resnext152_64x4d(pretrained=False, **kwargs): """ResNeXt-152 64x4d model from - `"Aggregated Residual Transformations for Deep Neural Networks" `_ + `"Aggregated Residual Transformations for Deep Neural Networks" `_. Args: pretrained (bool, optional): Whether to load pre-trained weights. If True, returns a model pre-trained on ImageNet. Default: False. + **kwargs (optional): Additional keyword arguments. For details, please refer to :ref:`ResNet `. Returns: - ResNeXt-152 64x4d model. An instance of :ref:`api_fluid_dygraph_Layer`. + :ref:`api_paddle_nn_Layer`. An instance of ResNeXt-152 64x4d model. Examples: .. code-block:: python @@ -703,9 +713,10 @@ def wide_resnet50_2(pretrained=False, **kwargs): Args: pretrained (bool, optional): Whether to load pre-trained weights. If True, returns a model pre-trained on ImageNet. Default: False. + **kwargs (optional): Additional keyword arguments. For details, please refer to :ref:`ResNet `. Returns: - Wide ResNet-50-2 model. An instance of :ref:`api_fluid_dygraph_Layer`. + :ref:`api_paddle_nn_Layer`. An instance of Wide ResNet-50-2 model. Examples: .. code-block:: python @@ -736,9 +747,10 @@ def wide_resnet101_2(pretrained=False, **kwargs): Args: pretrained (bool, optional): Whether to load pre-trained weights. If True, returns a model pre-trained on ImageNet. Default: False. + **kwargs (optional): Additional keyword arguments. For details, please refer to :ref:`ResNet `. Returns: - Wide ResNet-101-2 model. An instance of :ref:`api_fluid_dygraph_Layer`. + :ref:`api_paddle_nn_Layer`. An instance of Wide ResNet-101-2 model. Examples: .. code-block:: python diff --git a/python/paddle/vision/models/shufflenetv2.py b/python/paddle/vision/models/shufflenetv2.py index 60304b95498..900a1928304 100644 --- a/python/paddle/vision/models/shufflenetv2.py +++ b/python/paddle/vision/models/shufflenetv2.py @@ -190,14 +190,17 @@ class InvertedResidualDS(nn.Layer): class ShuffleNetV2(nn.Layer): """ShuffleNetV2 model from - `"ShuffleNet V2: Practical Guidelines for Efficient CNN Architecture Design" `_ + `"ShuffleNet V2: Practical Guidelines for Efficient CNN Architecture Design" `_. Args: - scale (float, optional) - scale of output channels. Default: True. - act (str, optional) - activation function of neural network. Default: "relu". - num_classes (int, optional): output dim of last fc layer. If num_classes <=0, last fc layer + scale (float, optional): Scale of output channels. Default: True. + act (str, optional): Activation function of neural network. Default: "relu". + num_classes (int, optional): Output dim of last fc layer. If num_classes <= 0, last fc layer will not be defined. Default: 1000. - with_pool (bool, optional): use pool before the last fc layer or not. Default: True. + with_pool (bool, optional): Use pool before the last fc layer or not. Default: True. + + Returns: + :ref:`api_paddle_nn_Layer`. An instance of ShuffleNetV2 model. Examples: .. code-block:: python @@ -209,7 +212,7 @@ class ShuffleNetV2(nn.Layer): x = paddle.rand([1, 3, 224, 224]) out = shufflenet_v2_swish(x) print(out.shape) - + # [1, 1000] """ def __init__(self, scale=1.0, act="relu", num_classes=1000, with_pool=True): @@ -315,10 +318,15 @@ def _shufflenet_v2(arch, pretrained=False, **kwargs): def shufflenet_v2_x0_25(pretrained=False, **kwargs): """ShuffleNetV2 with 0.25x output channels, as described in - `"ShuffleNet V2: Practical Guidelines for Ecient CNN Architecture Design" `_ 。 + `"ShuffleNet V2: Practical Guidelines for Ecient CNN Architecture Design" `_. Args: - pretrained (bool): If True, returns a model pre-trained on ImageNet. Default: False. + pretrained (bool, optional): Whether to load pre-trained weights. If True, returns a model pre-trained + on ImageNet. Default: False. + **kwargs (optional): Additional keyword arguments. For details, please refer to :ref:`ShuffleNetV2 `. + + Returns: + :ref:`api_paddle_nn_Layer`. An instance of ShuffleNetV2 with 0.25x output channels. Examples: .. code-block:: python @@ -336,7 +344,7 @@ def shufflenet_v2_x0_25(pretrained=False, **kwargs): out = model(x) print(out.shape) - + # [1, 1000] """ return _shufflenet_v2("shufflenet_v2_x0_25", scale=0.25, @@ -346,10 +354,15 @@ def shufflenet_v2_x0_25(pretrained=False, **kwargs): def shufflenet_v2_x0_33(pretrained=False, **kwargs): """ShuffleNetV2 with 0.33x output channels, as described in - `"ShuffleNet V2: Practical Guidelines for Ecient CNN Architecture Design" `_ 。 + `"ShuffleNet V2: Practical Guidelines for Ecient CNN Architecture Design" `_. Args: - pretrained (bool): If True, returns a model pre-trained on ImageNet. Default: False. + pretrained (bool, optional): Whether to load pre-trained weights. If True, returns a model pre-trained + on ImageNet. Default: False. + **kwargs (optional): Additional keyword arguments. For details, please refer to :ref:`ShuffleNetV2 `. + + Returns: + :ref:`api_paddle_nn_Layer`. An instance of ShuffleNetV2 with 0.33x output channels. Examples: .. code-block:: python @@ -367,7 +380,7 @@ def shufflenet_v2_x0_33(pretrained=False, **kwargs): out = model(x) print(out.shape) - + # [1, 1000] """ return _shufflenet_v2("shufflenet_v2_x0_33", scale=0.33, @@ -377,10 +390,15 @@ def shufflenet_v2_x0_33(pretrained=False, **kwargs): def shufflenet_v2_x0_5(pretrained=False, **kwargs): """ShuffleNetV2 with 0.5x output channels, as described in - `"ShuffleNet V2: Practical Guidelines for Ecient CNN Architecture Design" `_ 。 + `"ShuffleNet V2: Practical Guidelines for Ecient CNN Architecture Design" `_. Args: - pretrained (bool): If True, returns a model pre-trained on ImageNet. Default: False. + pretrained (bool, optional): Whether to load pre-trained weights. If True, returns a model pre-trained + on ImageNet. Default: False. + **kwargs (optional): Additional keyword arguments. For details, please refer to :ref:`ShuffleNetV2 `. + + Returns: + :ref:`api_paddle_nn_Layer`. An instance of ShuffleNetV2 with 0.5x output channels. Examples: .. code-block:: python @@ -398,7 +416,7 @@ def shufflenet_v2_x0_5(pretrained=False, **kwargs): out = model(x) print(out.shape) - + # [1, 1000] """ return _shufflenet_v2("shufflenet_v2_x0_5", scale=0.5, @@ -408,10 +426,15 @@ def shufflenet_v2_x0_5(pretrained=False, **kwargs): def shufflenet_v2_x1_0(pretrained=False, **kwargs): """ShuffleNetV2 with 1.0x output channels, as described in - `"ShuffleNet V2: Practical Guidelines for Ecient CNN Architecture Design" `_ 。 + `"ShuffleNet V2: Practical Guidelines for Ecient CNN Architecture Design" `_. Args: - pretrained (bool): If True, returns a model pre-trained on ImageNet. Default: False. + pretrained (bool, optional): Whether to load pre-trained weights. If True, returns a model pre-trained + on ImageNet. Default: False. + **kwargs (optional): Additional keyword arguments. For details, please refer to :ref:`ShuffleNetV2 `. + + Returns: + :ref:`api_paddle_nn_Layer`. An instance of ShuffleNetV2 with 1.0x output channels. Examples: .. code-block:: python @@ -429,7 +452,7 @@ def shufflenet_v2_x1_0(pretrained=False, **kwargs): out = model(x) print(out.shape) - + # [1, 1000] """ return _shufflenet_v2("shufflenet_v2_x1_0", scale=1.0, @@ -439,10 +462,15 @@ def shufflenet_v2_x1_0(pretrained=False, **kwargs): def shufflenet_v2_x1_5(pretrained=False, **kwargs): """ShuffleNetV2 with 1.5x output channels, as described in - `"ShuffleNet V2: Practical Guidelines for Ecient CNN Architecture Design" `_ 。 + `"ShuffleNet V2: Practical Guidelines for Ecient CNN Architecture Design" `_. Args: - pretrained (bool): If True, returns a model pre-trained on ImageNet. Default: False. + pretrained (bool, optional): Whether to load pre-trained weights. If True, returns a model pre-trained + on ImageNet. Default: False. + **kwargs (optional): Additional keyword arguments. For details, please refer to :ref:`ShuffleNetV2 `. + + Returns: + :ref:`api_paddle_nn_Layer`. An instance of ShuffleNetV2 with 1.5x output channels. Examples: .. code-block:: python @@ -460,7 +488,7 @@ def shufflenet_v2_x1_5(pretrained=False, **kwargs): out = model(x) print(out.shape) - + # [1, 1000] """ return _shufflenet_v2("shufflenet_v2_x1_5", scale=1.5, @@ -470,10 +498,15 @@ def shufflenet_v2_x1_5(pretrained=False, **kwargs): def shufflenet_v2_x2_0(pretrained=False, **kwargs): """ShuffleNetV2 with 2.0x output channels, as described in - `"ShuffleNet V2: Practical Guidelines for Ecient CNN Architecture Design" `_ 。 + `"ShuffleNet V2: Practical Guidelines for Ecient CNN Architecture Design" `_. Args: - pretrained (bool): If True, returns a model pre-trained on ImageNet. Default: False. + pretrained (bool, optional): Whether to load pre-trained weights. If True, returns a model pre-trained + on ImageNet. Default: False. + **kwargs (optional): Additional keyword arguments. For details, please refer to :ref:`ShuffleNetV2 `. + + Returns: + :ref:`api_paddle_nn_Layer`. An instance of ShuffleNetV2 with 2.0x output channels. Examples: .. code-block:: python @@ -491,7 +524,7 @@ def shufflenet_v2_x2_0(pretrained=False, **kwargs): out = model(x) print(out.shape) - + # [1, 1000] """ return _shufflenet_v2("shufflenet_v2_x2_0", scale=2.0, @@ -500,11 +533,16 @@ def shufflenet_v2_x2_0(pretrained=False, **kwargs): def shufflenet_v2_swish(pretrained=False, **kwargs): - """ShuffleNetV2 with 1.0x output channels and swish activation function, as described in - `"ShuffleNet V2: Practical Guidelines for Ecient CNN Architecture Design" `_ 。 + """ShuffleNetV2 with swish activation function, as described in + `"ShuffleNet V2: Practical Guidelines for Ecient CNN Architecture Design" `_. Args: - pretrained (bool): If True, returns a model pre-trained on ImageNet. Default: False. + pretrained (bool, optional): Whether to load pre-trained weights. If True, returns a model pre-trained + on ImageNet. Default: False. + **kwargs (optional): Additional keyword arguments. For details, please refer to :ref:`ShuffleNetV2 `. + + Returns: + :ref:`api_paddle_nn_Layer`. An instance of ShuffleNetV2 with swish activation function. Examples: .. code-block:: python @@ -522,7 +560,7 @@ def shufflenet_v2_swish(pretrained=False, **kwargs): out = model(x) print(out.shape) - + # [1, 1000] """ return _shufflenet_v2("shufflenet_v2_swish", scale=1.0, diff --git a/python/paddle/vision/models/squeezenet.py b/python/paddle/vision/models/squeezenet.py index b122a795286..997d50dca70 100644 --- a/python/paddle/vision/models/squeezenet.py +++ b/python/paddle/vision/models/squeezenet.py @@ -76,15 +76,20 @@ class MakeFire(nn.Layer): class SqueezeNet(nn.Layer): """SqueezeNet model from `"SqueezeNet: AlexNet-level accuracy with 50x fewer parameters and <0.5MB model size" - `_ + `_. Args: - version (str): version of squeezenet, which can be "1.0" or "1.1". - num_classes (int): output dim of last fc layer. Default: 1000. - with_pool (bool): use pool before the last fc layer or not. Default: True. + version (str): Version of SqueezeNet, which can be "1.0" or "1.1". + num_classes (int, optional): Output dim of last fc layer. If num_classes <= 0, last fc layer + will not be defined. Default: 1000. + with_pool (bool, optional): Use pool before the last fc layer or not. Default: True. + + Returns: + :ref:`api_paddle_nn_Layer`. An instance of SqueezeNet model. Examples: .. code-block:: python + import paddle from paddle.vision.models import SqueezeNet @@ -98,7 +103,7 @@ class SqueezeNet(nn.Layer): out = model(x) print(out.shape) - + # [1, 1000] """ def __init__(self, version, num_classes=1000, with_pool=True): @@ -205,14 +210,22 @@ def _squeezenet(arch, version, pretrained, **kwargs): def squeezenet1_0(pretrained=False, **kwargs): - """SqueezeNet v1.0 model + """SqueezeNet v1.0 model from + `"SqueezeNet: AlexNet-level accuracy with 50x fewer parameters and <0.5MB model size" + `_. Args: - pretrained (bool): If True, returns a model pre-trained on ImageNet. Default: False. + pretrained (bool, optional): Whether to load pre-trained weights. If True, returns a model pre-trained + on ImageNet. Default: False. + **kwargs (optional): Additional keyword arguments. For details, please refer to :ref:`SqueezeNet `. + + Returns: + :ref:`api_paddle_nn_Layer`. An instance of SqueezeNet v1.0 model. Examples: .. code-block:: python + import paddle from paddle.vision.models import squeezenet1_0 # build model @@ -220,19 +233,33 @@ def squeezenet1_0(pretrained=False, **kwargs): # build model and load imagenet pretrained weight # model = squeezenet1_0(pretrained=True) + + x = paddle.rand([1, 3, 224, 224]) + out = model(x) + + print(out.shape) + # [1, 1000] """ return _squeezenet('squeezenet1_0', '1.0', pretrained, **kwargs) def squeezenet1_1(pretrained=False, **kwargs): - """SqueezeNet v1.1 model + """SqueezeNet v1.1 model from + `"SqueezeNet: AlexNet-level accuracy with 50x fewer parameters and <0.5MB model size" + `_. Args: - pretrained (bool): If True, returns a model pre-trained on ImageNet. Default: False. + pretrained (bool, optional): Whether to load pre-trained weights. If True, returns a model pre-trained + on ImageNet. Default: False. + **kwargs (optional): Additional keyword arguments. For details, please refer to :ref:`SqueezeNet `. + + Returns: + :ref:`api_paddle_nn_Layer`. An instance of SqueezeNet v1.1 model. Examples: .. code-block:: python + import paddle from paddle.vision.models import squeezenet1_1 # build model @@ -240,5 +267,11 @@ def squeezenet1_1(pretrained=False, **kwargs): # build model and load imagenet pretrained weight # model = squeezenet1_1(pretrained=True) + + x = paddle.rand([1, 3, 224, 224]) + out = model(x) + + print(out.shape) + # [1, 1000] """ return _squeezenet('squeezenet1_1', '1.1', pretrained, **kwargs) diff --git a/python/paddle/vision/models/vgg.py b/python/paddle/vision/models/vgg.py index c7913ce7742..8fb0ea26005 100644 --- a/python/paddle/vision/models/vgg.py +++ b/python/paddle/vision/models/vgg.py @@ -29,17 +29,19 @@ model_urls = { class VGG(nn.Layer): """VGG model from - `"Very Deep Convolutional Networks For Large-Scale Image Recognition" `_ + `"Very Deep Convolutional Networks For Large-Scale Image Recognition" `_. Args: features (nn.Layer): Vgg features create by function make_layers. - num_classes (int, optional): Output dim of last fc layer. If num_classes <=0, last fc layer + num_classes (int, optional): Output dim of last fc layer. If num_classes <= 0, last fc layer will not be defined. Default: 1000. with_pool (bool, optional): Use pool before the last three fc layer or not. Default: True. + Returns: + :ref:`api_paddle_nn_Layer`. An instance of VGG model. + Examples: .. code-block:: python - :name: code-example import paddle from paddle.vision.models import VGG @@ -56,7 +58,6 @@ class VGG(nn.Layer): print(out.shape) # [1, 1000] - """ def __init__(self, features, num_classes=1000, with_pool=True): @@ -139,15 +140,22 @@ def _vgg(arch, cfg, batch_norm, pretrained, **kwargs): def vgg11(pretrained=False, batch_norm=False, **kwargs): - """VGG 11-layer model + """VGG 11-layer model from + `"Very Deep Convolutional Networks For Large-Scale Image Recognition" `_. Args: - pretrained (bool): If True, returns a model pre-trained on ImageNet. Default: False. - batch_norm (bool): If True, returns a model with batch_norm layer. Default: False. + pretrained (bool, optional): Whether to load pre-trained weights. If True, returns a model pre-trained + on ImageNet. Default: False. + batch_norm (bool, optional): If True, returns a model with batch_norm layer. Default: False. + **kwargs (optional): Additional keyword arguments. For details, please refer to :ref:`VGG `. + + Returns: + :ref:`api_paddle_nn_Layer`. An instance of VGG 11-layer model. Examples: .. code-block:: python + import paddle from paddle.vision.models import vgg11 # build model @@ -155,6 +163,12 @@ def vgg11(pretrained=False, batch_norm=False, **kwargs): # build vgg11 model with batch_norm model = vgg11(batch_norm=True) + + x = paddle.rand([1, 3, 224, 224]) + out = model(x) + + print(out.shape) + # [1, 1000] """ model_name = 'vgg11' if batch_norm: @@ -163,15 +177,22 @@ def vgg11(pretrained=False, batch_norm=False, **kwargs): def vgg13(pretrained=False, batch_norm=False, **kwargs): - """VGG 13-layer model + """VGG 13-layer model from + `"Very Deep Convolutional Networks For Large-Scale Image Recognition" `_. Args: - pretrained (bool): If True, returns a model pre-trained on ImageNet. Default: False. + pretrained (bool, optional): Whether to load pre-trained weights. If True, returns a model pre-trained + on ImageNet. Default: False. batch_norm (bool): If True, returns a model with batch_norm layer. Default: False. + **kwargs (optional): Additional keyword arguments. For details, please refer to :ref:`VGG `. + + Returns: + :ref:`api_paddle_nn_Layer`. An instance of VGG 13-layer model. Examples: .. code-block:: python + import paddle from paddle.vision.models import vgg13 # build model @@ -179,6 +200,12 @@ def vgg13(pretrained=False, batch_norm=False, **kwargs): # build vgg13 model with batch_norm model = vgg13(batch_norm=True) + + x = paddle.rand([1, 3, 224, 224]) + out = model(x) + + print(out.shape) + # [1, 1000] """ model_name = 'vgg13' if batch_norm: @@ -187,15 +214,22 @@ def vgg13(pretrained=False, batch_norm=False, **kwargs): def vgg16(pretrained=False, batch_norm=False, **kwargs): - """VGG 16-layer model + """VGG 16-layer model from + `"Very Deep Convolutional Networks For Large-Scale Image Recognition" `_. Args: - pretrained (bool): If True, returns a model pre-trained on ImageNet. Default: False. - batch_norm (bool): If True, returns a model with batch_norm layer. Default: False. + pretrained (bool, optional): Whether to load pre-trained weights. If True, returns a model pre-trained + on ImageNet. Default: False. + batch_norm (bool, optional): If True, returns a model with batch_norm layer. Default: False. + **kwargs (optional): Additional keyword arguments. For details, please refer to :ref:`VGG `. + + Returns: + :ref:`api_paddle_nn_Layer`. An instance of VGG 16-layer model. Examples: .. code-block:: python + import paddle from paddle.vision.models import vgg16 # build model @@ -203,6 +237,12 @@ def vgg16(pretrained=False, batch_norm=False, **kwargs): # build vgg16 model with batch_norm model = vgg16(batch_norm=True) + + x = paddle.rand([1, 3, 224, 224]) + out = model(x) + + print(out.shape) + # [1, 1000] """ model_name = 'vgg16' if batch_norm: @@ -211,15 +251,22 @@ def vgg16(pretrained=False, batch_norm=False, **kwargs): def vgg19(pretrained=False, batch_norm=False, **kwargs): - """VGG 19-layer model + """VGG 19-layer model from + `"Very Deep Convolutional Networks For Large-Scale Image Recognition" `_. Args: - pretrained (bool): If True, returns a model pre-trained on ImageNet. Default: False. - batch_norm (bool): If True, returns a model with batch_norm layer. Default: False. + pretrained (bool, optional): Whether to load pre-trained weights. If True, returns a model pre-trained + on ImageNet. Default: False. + batch_norm (bool, optional): If True, returns a model with batch_norm layer. Default: False. + **kwargs (optional): Additional keyword arguments. For details, please refer to :ref:`VGG `. + + Returns: + :ref:`api_paddle_nn_Layer`. An instance of VGG 19-layer model. Examples: .. code-block:: python + import paddle from paddle.vision.models import vgg19 # build model @@ -227,6 +274,12 @@ def vgg19(pretrained=False, batch_norm=False, **kwargs): # build vgg19 model with batch_norm model = vgg19(batch_norm=True) + + x = paddle.rand([1, 3, 224, 224]) + out = model(x) + + print(out.shape) + # [1, 1000] """ model_name = 'vgg19' if batch_norm: -- GitLab