未验证 提交 fdcb57fb 编写于 作者: N Nyakku Shigure 提交者: GitHub

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
上级 f80cee11
...@@ -74,18 +74,28 @@ class ConvPoolLayer(nn.Layer): ...@@ -74,18 +74,28 @@ class ConvPoolLayer(nn.Layer):
class AlexNet(nn.Layer): class AlexNet(nn.Layer):
"""AlexNet model from """AlexNet model from
`"ImageNet Classification with Deep Convolutional Neural Networks" `"ImageNet Classification with Deep Convolutional Neural Networks"
<https://proceedings.neurips.cc/paper/2012/file/c399862d3b9d6b76c8436e924a68c45b-Paper.pdf>`_ <https://proceedings.neurips.cc/paper/2012/file/c399862d3b9d6b76c8436e924a68c45b-Paper.pdf>`_.
Args: 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: Examples:
.. code-block:: python .. code-block:: python
import paddle
from paddle.vision.models import AlexNet from paddle.vision.models import AlexNet
alexnet = AlexNet() alexnet = AlexNet()
x = paddle.rand([1, 3, 224, 224])
out = alexnet(x)
print(out.shape)
# [1, 1000]
""" """
def __init__(self, num_classes=1000): def __init__(self, num_classes=1000):
...@@ -175,19 +185,21 @@ def _alexnet(arch, pretrained, **kwargs): ...@@ -175,19 +185,21 @@ def _alexnet(arch, pretrained, **kwargs):
def alexnet(pretrained=False, **kwargs): def alexnet(pretrained=False, **kwargs):
""" """AlexNet model from
AlexNet model `"ImageNet Classification with Deep Convolutional Neural Networks"
<https://proceedings.neurips.cc/paper/2012/file/c399862d3b9d6b76c8436e924a68c45b-Paper.pdf>`_.
Args: Args:
pretrained (bool, optional): 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
**kwargs: Additional keyword arguments,For details, please refer to :ref:`AlexNet <api_paddle_vision_models_AlexNet>`. on ImageNet. Default: False.
**kwargs (optional): Additional keyword arguments. For details, please refer to :ref:`AlexNet <api_paddle_vision_AlexNet>`.
Returns: Returns:
the model of alexnet. :ref:`api_paddle_nn_Layer`. An instance of AlexNet model.
Examples: Examples:
.. code-block:: python .. code-block:: python
:name: code-example
import paddle import paddle
from paddle.vision.models import alexnet from paddle.vision.models import alexnet
......
...@@ -185,14 +185,18 @@ class ConvBNLayer(nn.Layer): ...@@ -185,14 +185,18 @@ class ConvBNLayer(nn.Layer):
class DenseNet(nn.Layer): class DenseNet(nn.Layer):
"""DenseNet model from """DenseNet model from
`"Densely Connected Convolutional Networks" <https://arxiv.org/pdf/1608.06993.pdf>`_ `"Densely Connected Convolutional Networks" <https://arxiv.org/pdf/1608.06993.pdf>`_.
Args: Args:
layers (int): layers of densenet. Default: 121. layers (int, optional): Layers of DenseNet. Default: 121.
bn_size (int): expansion of growth rate in the middle layer. Default: 4. bn_size (int, optional): Expansion of growth rate in the middle layer. Default: 4.
dropout (float): dropout rate. Default: 0.. dropout (float, optional): Dropout rate. Default: :math:`0.0`.
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
with_pool (bool): use pool before the last fc layer or not. Default: True. 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: Examples:
.. code-block:: python .. code-block:: python
...@@ -207,6 +211,7 @@ class DenseNet(nn.Layer): ...@@ -207,6 +211,7 @@ class DenseNet(nn.Layer):
out = densenet(x) out = densenet(x)
print(out.shape) print(out.shape)
# [1, 1000]
""" """
def __init__(self, def __init__(self,
...@@ -314,14 +319,21 @@ def _densenet(arch, layers, pretrained, **kwargs): ...@@ -314,14 +319,21 @@ def _densenet(arch, layers, pretrained, **kwargs):
def densenet121(pretrained=False, **kwargs): def densenet121(pretrained=False, **kwargs):
"""DenseNet 121-layer model """DenseNet 121-layer model from
`"Densely Connected Convolutional Networks" <https://arxiv.org/pdf/1608.06993.pdf>`_.
Args: 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 <api_paddle_vision_DenseNet>`.
Returns:
:ref:`api_paddle_nn_Layer`. An instance of DenseNet 121-layer model.
Examples: Examples:
.. code-block:: python .. code-block:: python
import paddle
from paddle.vision.models import densenet121 from paddle.vision.models import densenet121
# build model # build model
...@@ -329,15 +341,27 @@ def densenet121(pretrained=False, **kwargs): ...@@ -329,15 +341,27 @@ def densenet121(pretrained=False, **kwargs):
# build model and load imagenet pretrained weight # build model and load imagenet pretrained weight
# model = densenet121(pretrained=True) # 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) return _densenet('densenet121', 121, pretrained, **kwargs)
def densenet161(pretrained=False, **kwargs): def densenet161(pretrained=False, **kwargs):
"""DenseNet 161-layer model """DenseNet 161-layer model from
`"Densely Connected Convolutional Networks" <https://arxiv.org/pdf/1608.06993.pdf>`_.
Args: 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 <api_paddle_vision_DenseNet>`.
Returns:
:ref:`api_paddle_nn_Layer`. An instance of DenseNet 161-layer model.
Examples: Examples:
.. code-block:: python .. code-block:: python
...@@ -354,14 +378,21 @@ def densenet161(pretrained=False, **kwargs): ...@@ -354,14 +378,21 @@ def densenet161(pretrained=False, **kwargs):
def densenet169(pretrained=False, **kwargs): def densenet169(pretrained=False, **kwargs):
"""DenseNet 169-layer model """DenseNet 169-layer model from
`"Densely Connected Convolutional Networks" <https://arxiv.org/pdf/1608.06993.pdf>`_.
Args: 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 <api_paddle_vision_DenseNet>`.
Returns:
:ref:`api_paddle_nn_Layer`. An instance of DenseNet 169-layer model.
Examples: Examples:
.. code-block:: python .. code-block:: python
import paddle
from paddle.vision.models import densenet169 from paddle.vision.models import densenet169
# build model # build model
...@@ -369,19 +400,32 @@ def densenet169(pretrained=False, **kwargs): ...@@ -369,19 +400,32 @@ def densenet169(pretrained=False, **kwargs):
# build model and load imagenet pretrained weight # build model and load imagenet pretrained weight
# model = densenet169(pretrained=True) # 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) return _densenet('densenet169', 169, pretrained, **kwargs)
def densenet201(pretrained=False, **kwargs): def densenet201(pretrained=False, **kwargs):
"""DenseNet 201-layer model """DenseNet 201-layer model from
`"Densely Connected Convolutional Networks" <https://arxiv.org/pdf/1608.06993.pdf>`_.
Args: 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 <api_paddle_vision_DenseNet>`.
Returns:
:ref:`api_paddle_nn_Layer`. An instance of DenseNet 201-layer model.
Examples: Examples:
.. code-block:: python .. code-block:: python
import paddle
from paddle.vision.models import densenet201 from paddle.vision.models import densenet201
# build model # build model
...@@ -389,19 +433,31 @@ def densenet201(pretrained=False, **kwargs): ...@@ -389,19 +433,31 @@ def densenet201(pretrained=False, **kwargs):
# build model and load imagenet pretrained weight # build model and load imagenet pretrained weight
# model = densenet201(pretrained=True) # 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) return _densenet('densenet201', 201, pretrained, **kwargs)
def densenet264(pretrained=False, **kwargs): def densenet264(pretrained=False, **kwargs):
"""DenseNet 264-layer model """DenseNet 264-layer model from
`"Densely Connected Convolutional Networks" <https://arxiv.org/pdf/1608.06993.pdf>`_.
Args: 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 <api_paddle_vision_DenseNet>`.
Returns:
:ref:`api_paddle_nn_Layer`. An instance of DenseNet 264-layer model.
Examples: Examples:
.. code-block:: python .. code-block:: python
import paddle
from paddle.vision.models import densenet264 from paddle.vision.models import densenet264
# build model # build model
...@@ -409,5 +465,11 @@ def densenet264(pretrained=False, **kwargs): ...@@ -409,5 +465,11 @@ def densenet264(pretrained=False, **kwargs):
# build model and load imagenet pretrained weight # build model and load imagenet pretrained weight
# model = densenet264(pretrained=True) # 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) return _densenet('densenet264', 264, pretrained, **kwargs)
...@@ -97,12 +97,15 @@ class Inception(nn.Layer): ...@@ -97,12 +97,15 @@ class Inception(nn.Layer):
class GoogLeNet(nn.Layer): class GoogLeNet(nn.Layer):
"""GoogLeNet (Inception v1) model architecture from """GoogLeNet (Inception v1) model architecture from
`"Going Deeper with Convolutions" <https://arxiv.org/pdf/1409.4842.pdf>`_ `"Going Deeper with Convolutions" <https://arxiv.org/pdf/1409.4842.pdf>`_.
Args: 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. 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: Examples:
.. code-block:: python .. code-block:: python
...@@ -116,7 +119,8 @@ class GoogLeNet(nn.Layer): ...@@ -116,7 +119,8 @@ class GoogLeNet(nn.Layer):
x = paddle.rand([1, 3, 224, 224]) x = paddle.rand([1, 3, 224, 224])
out, out1, out2 = model(x) 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): def __init__(self, num_classes=1000, with_pool=True):
...@@ -219,10 +223,15 @@ class GoogLeNet(nn.Layer): ...@@ -219,10 +223,15 @@ class GoogLeNet(nn.Layer):
def googlenet(pretrained=False, **kwargs): def googlenet(pretrained=False, **kwargs):
"""GoogLeNet (Inception v1) model architecture from """GoogLeNet (Inception v1) model architecture from
`"Going Deeper with Convolutions" <https://arxiv.org/pdf/1409.4842.pdf>`_ `"Going Deeper with Convolutions" <https://arxiv.org/pdf/1409.4842.pdf>`_.
Args: 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 <api_paddle_vision_GoogLeNet>`.
Returns:
:ref:`api_paddle_nn_Layer`. An instance of GoogLeNet (Inception v1) model.
Examples: Examples:
.. code-block:: python .. code-block:: python
...@@ -239,7 +248,8 @@ def googlenet(pretrained=False, **kwargs): ...@@ -239,7 +248,8 @@ def googlenet(pretrained=False, **kwargs):
x = paddle.rand([1, 3, 224, 224]) x = paddle.rand([1, 3, 224, 224])
out, out1, out2 = model(x) out, out1, out2 = model(x)
print(out.shape) print(out.shape, out1.shape, out2.shape)
# [1, 1000] [1, 1000] [1, 1000]
""" """
model = GoogLeNet(**kwargs) model = GoogLeNet(**kwargs)
arch = "googlenet" arch = "googlenet"
......
...@@ -413,12 +413,16 @@ class InceptionE(nn.Layer): ...@@ -413,12 +413,16 @@ class InceptionE(nn.Layer):
class InceptionV3(nn.Layer): class InceptionV3(nn.Layer):
""" """Inception v3 model from
InceptionV3 `"Rethinking the Inception Architecture for Computer Vision" <https://arxiv.org/pdf/1512.00567.pdf>`_.
Args: Args:
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. 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 Inception v3 model.
Examples: Examples:
.. code-block:: python .. code-block:: python
...@@ -432,6 +436,7 @@ class InceptionV3(nn.Layer): ...@@ -432,6 +436,7 @@ class InceptionV3(nn.Layer):
out = inception_v3(x) out = inception_v3(x)
print(out.shape) print(out.shape)
# [1, 1000]
""" """
def __init__(self, num_classes=1000, with_pool=True): def __init__(self, num_classes=1000, with_pool=True):
...@@ -505,13 +510,17 @@ class InceptionV3(nn.Layer): ...@@ -505,13 +510,17 @@ class InceptionV3(nn.Layer):
def inception_v3(pretrained=False, **kwargs): def inception_v3(pretrained=False, **kwargs):
""" """Inception v3 model from
InceptionV3 model from `"Rethinking the Inception Architecture for Computer Vision" <https://arxiv.org/pdf/1512.00567.pdf>`_.
`"Rethinking the Inception Architecture for Computer Vision" <https://arxiv.org/pdf/1512.00567.pdf>`_
Args: 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 <api_paddle_vision_InceptionV3>`.
Returns:
:ref:`api_paddle_nn_Layer`. An instance of Inception v3 model.
Examples: Examples:
.. code-block:: python .. code-block:: python
...@@ -528,6 +537,7 @@ def inception_v3(pretrained=False, **kwargs): ...@@ -528,6 +537,7 @@ def inception_v3(pretrained=False, **kwargs):
out = model(x) out = model(x)
print(out.shape) print(out.shape)
# [1, 1000]
""" """
model = InceptionV3(**kwargs) model = InceptionV3(**kwargs)
arch = "inception_v3" arch = "inception_v3"
......
...@@ -20,18 +20,28 @@ __all__ = [] ...@@ -20,18 +20,28 @@ __all__ = []
class LeNet(nn.Layer): class LeNet(nn.Layer):
"""LeNet model from """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" <https://ieeexplore.ieee.org/document/726791>`_.
Args: 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. will not be defined. Default: 10.
Returns:
:ref:`api_paddle_nn_Layer`. An instance of LeNet model.
Examples: Examples:
.. code-block:: python .. code-block:: python
import paddle
from paddle.vision.models import LeNet from paddle.vision.models import LeNet
model = LeNet() model = LeNet()
x = paddle.rand([1, 1, 28, 28])
out = model(x)
print(out.shape)
# [1, 10]
""" """
def __init__(self, num_classes=10): def __init__(self, num_classes=10):
......
...@@ -58,14 +58,17 @@ class MobileNetV1(nn.Layer): ...@@ -58,14 +58,17 @@ class MobileNetV1(nn.Layer):
`"MobileNets: Efficient Convolutional Neural Networks for Mobile Vision Applications" <https://arxiv.org/abs/1704.04861>`_. `"MobileNets: Efficient Convolutional Neural Networks for Mobile Vision Applications" <https://arxiv.org/abs/1704.04861>`_.
Args: Args:
scale (float, optional): scale of channels in each layer. Default: 1.0. 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. 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: Examples:
.. code-block:: python .. code-block:: python
:name: code-example1
import paddle import paddle
from paddle.vision.models import MobileNetV1 from paddle.vision.models import MobileNetV1
...@@ -217,11 +220,17 @@ def _mobilenet(arch, pretrained=False, **kwargs): ...@@ -217,11 +220,17 @@ def _mobilenet(arch, pretrained=False, **kwargs):
def mobilenet_v1(pretrained=False, scale=1.0, **kwargs): def mobilenet_v1(pretrained=False, scale=1.0, **kwargs):
"""MobileNetV1 """MobileNetV1 from
`"MobileNets: Efficient Convolutional Neural Networks for Mobile Vision Applications" <https://arxiv.org/abs/1704.04861>`_.
Args: 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
scale: (float): scale of channels in each layer. Default: 1.0. 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 <api_paddle_vision_MobileNetV1>`.
Returns:
:ref:`api_paddle_nn_Layer`. An instance of MobileNetV1 model.
Examples: Examples:
.. code-block:: python .. code-block:: python
...@@ -242,6 +251,7 @@ def mobilenet_v1(pretrained=False, scale=1.0, **kwargs): ...@@ -242,6 +251,7 @@ def mobilenet_v1(pretrained=False, scale=1.0, **kwargs):
out = model(x) out = model(x)
print(out.shape) print(out.shape)
# [1, 1000]
""" """
model = _mobilenet('mobilenetv1_' + str(scale), model = _mobilenet('mobilenetv1_' + str(scale),
pretrained, pretrained,
......
...@@ -75,14 +75,17 @@ class MobileNetV2(nn.Layer): ...@@ -75,14 +75,17 @@ class MobileNetV2(nn.Layer):
`"MobileNetV2: Inverted Residuals and Linear Bottlenecks" <https://arxiv.org/abs/1801.04381>`_. `"MobileNetV2: Inverted Residuals and Linear Bottlenecks" <https://arxiv.org/abs/1801.04381>`_.
Args: Args:
scale (float, optional): scale of channels in each layer. Default: 1.0. 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. 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: Examples:
.. code-block:: python .. code-block:: python
:name: code-example1
import paddle import paddle
from paddle.vision.models import MobileNetV2 from paddle.vision.models import MobileNetV2
...@@ -181,11 +184,17 @@ def _mobilenet(arch, pretrained=False, **kwargs): ...@@ -181,11 +184,17 @@ def _mobilenet(arch, pretrained=False, **kwargs):
def mobilenet_v2(pretrained=False, scale=1.0, **kwargs): def mobilenet_v2(pretrained=False, scale=1.0, **kwargs):
"""MobileNetV2 """MobileNetV2 from
`"MobileNetV2: Inverted Residuals and Linear Bottlenecks" <https://arxiv.org/abs/1801.04381>`_.
Args: 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
scale: (float): scale of channels in each layer. Default: 1.0. 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 <api_paddle_vision_MobileNetV2>`.
Returns:
:ref:`api_paddle_nn_Layer`. An instance of MobileNetV2 model.
Examples: Examples:
.. code-block:: python .. code-block:: python
...@@ -206,6 +215,7 @@ def mobilenet_v2(pretrained=False, scale=1.0, **kwargs): ...@@ -206,6 +215,7 @@ def mobilenet_v2(pretrained=False, scale=1.0, **kwargs):
out = model(x) out = model(x)
print(out.shape) print(out.shape)
# [1, 1000]
""" """
model = _mobilenet('mobilenetv2_' + str(scale), model = _mobilenet('mobilenetv2_' + str(scale),
pretrained, pretrained,
......
...@@ -254,10 +254,13 @@ class MobileNetV3Small(MobileNetV3): ...@@ -254,10 +254,13 @@ class MobileNetV3Small(MobileNetV3):
Args: Args:
scale (float, optional): Scale of channels in each layer. Default: 1.0. 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. 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 MobileNetV3 Small architecture model.
Examples: Examples:
.. code-block:: python .. code-block:: python
...@@ -271,6 +274,7 @@ class MobileNetV3Small(MobileNetV3): ...@@ -271,6 +274,7 @@ class MobileNetV3Small(MobileNetV3):
out = model(x) out = model(x)
print(out.shape) print(out.shape)
# [1, 1000]
""" """
def __init__(self, scale=1.0, num_classes=1000, with_pool=True): def __init__(self, scale=1.0, num_classes=1000, with_pool=True):
...@@ -301,10 +305,13 @@ class MobileNetV3Large(MobileNetV3): ...@@ -301,10 +305,13 @@ class MobileNetV3Large(MobileNetV3):
Args: Args:
scale (float, optional): Scale of channels in each layer. Default: 1.0. 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. 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 MobileNetV3 Large architecture model.
Examples: Examples:
.. code-block:: python .. code-block:: python
...@@ -318,6 +325,7 @@ class MobileNetV3Large(MobileNetV3): ...@@ -318,6 +325,7 @@ class MobileNetV3Large(MobileNetV3):
out = model(x) out = model(x)
print(out.shape) print(out.shape)
# [1, 1000]
""" """
def __init__(self, scale=1.0, num_classes=1000, with_pool=True): 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): ...@@ -379,8 +387,13 @@ def mobilenet_v3_small(pretrained=False, scale=1.0, **kwargs):
`"Searching for MobileNetV3" <https://arxiv.org/abs/1905.02244>`_. `"Searching for MobileNetV3" <https://arxiv.org/abs/1905.02244>`_.
Args: 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. scale (float, optional): Scale of channels in each layer. Default: 1.0.
**kwargs (optional): Additional keyword arguments. For details, please refer to :ref:`MobileNetV3Small <api_paddle_vision_MobileNetV3Small>`.
Returns:
:ref:`api_paddle_nn_Layer`. An instance of MobileNetV3 Small architecture model.
Examples: Examples:
.. code-block:: python .. code-block:: python
...@@ -401,7 +414,7 @@ def mobilenet_v3_small(pretrained=False, scale=1.0, **kwargs): ...@@ -401,7 +414,7 @@ def mobilenet_v3_small(pretrained=False, scale=1.0, **kwargs):
out = model(x) out = model(x)
print(out.shape) print(out.shape)
# [1, 1000]
""" """
model = _mobilenet_v3("mobilenet_v3_small", model = _mobilenet_v3("mobilenet_v3_small",
scale=scale, scale=scale,
...@@ -415,8 +428,13 @@ def mobilenet_v3_large(pretrained=False, scale=1.0, **kwargs): ...@@ -415,8 +428,13 @@ def mobilenet_v3_large(pretrained=False, scale=1.0, **kwargs):
`"Searching for MobileNetV3" <https://arxiv.org/abs/1905.02244>`_. `"Searching for MobileNetV3" <https://arxiv.org/abs/1905.02244>`_.
Args: 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. scale (float, optional): Scale of channels in each layer. Default: 1.0.
**kwargs (optional): Additional keyword arguments. For details, please refer to :ref:`MobileNetV3Large <api_paddle_vision_MobileNetV3Large>`.
Returns:
:ref:`api_paddle_nn_Layer`. An instance of MobileNetV3 Large architecture model.
Examples: Examples:
.. code-block:: python .. code-block:: python
...@@ -437,7 +455,7 @@ def mobilenet_v3_large(pretrained=False, scale=1.0, **kwargs): ...@@ -437,7 +455,7 @@ def mobilenet_v3_large(pretrained=False, scale=1.0, **kwargs):
out = model(x) out = model(x)
print(out.shape) print(out.shape)
# [1, 1000]
""" """
model = _mobilenet_v3("mobilenet_v3_large", model = _mobilenet_v3("mobilenet_v3_large",
scale=scale, scale=scale,
......
...@@ -177,19 +177,19 @@ class BottleneckBlock(nn.Layer): ...@@ -177,19 +177,19 @@ class BottleneckBlock(nn.Layer):
class ResNet(nn.Layer): class ResNet(nn.Layer):
"""ResNet model from """ResNet model from
`"Deep Residual Learning for Image Recognition" <https://arxiv.org/pdf/1512.03385.pdf>`_ `"Deep Residual Learning for Image Recognition" <https://arxiv.org/pdf/1512.03385.pdf>`_.
Args: Args:
Block (BasicBlock|BottleneckBlock): block module of model. Block (BasicBlock|BottleneckBlock): Block module of model.
depth (int, optional): layers of ResNet, Default: 50. depth (int, optional): Layers of ResNet, Default: 50.
width (int, optional): base width per convolution group for each convolution block, Default: 64. 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 num_classes (int, optional): Output dim of last fc layer. If num_classes <= 0, last fc layer
will not be defined. Default: 1000. 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.
groups (int, optional): number of groups for each convolution block, Default: 1. groups (int, optional): Number of groups for each convolution block, Default: 1.
Returns: Returns:
ResNet model. An instance of :ref:`api_fluid_dygraph_Layer`. :ref:`api_paddle_nn_Layer`. An instance of ResNet model.
Examples: Examples:
.. code-block:: python .. code-block:: python
...@@ -215,7 +215,6 @@ class ResNet(nn.Layer): ...@@ -215,7 +215,6 @@ class ResNet(nn.Layer):
print(out.shape) print(out.shape)
# [1, 1000] # [1, 1000]
""" """
def __init__(self, def __init__(self,
...@@ -330,14 +329,15 @@ def _resnet(arch, Block, depth, pretrained, **kwargs): ...@@ -330,14 +329,15 @@ def _resnet(arch, Block, depth, pretrained, **kwargs):
def resnet18(pretrained=False, **kwargs): def resnet18(pretrained=False, **kwargs):
"""ResNet 18-layer model from """ResNet 18-layer model from
`"Deep Residual Learning for Image Recognition" <https://arxiv.org/pdf/1512.03385.pdf>`_ `"Deep Residual Learning for Image Recognition" <https://arxiv.org/pdf/1512.03385.pdf>`_.
Args: Args:
pretrained (bool, optional): Whether to load pre-trained weights. If True, returns a model pre-trained pretrained (bool, optional): Whether to load pre-trained weights. If True, returns a model pre-trained
on ImageNet. Default: False. on ImageNet. Default: False.
**kwargs (optional): Additional keyword arguments. For details, please refer to :ref:`ResNet <api_paddle_vision_ResNet>`.
Returns: 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: Examples:
.. code-block:: python .. code-block:: python
...@@ -362,14 +362,15 @@ def resnet18(pretrained=False, **kwargs): ...@@ -362,14 +362,15 @@ def resnet18(pretrained=False, **kwargs):
def resnet34(pretrained=False, **kwargs): def resnet34(pretrained=False, **kwargs):
"""ResNet 34-layer model from """ResNet 34-layer model from
`"Deep Residual Learning for Image Recognition" <https://arxiv.org/pdf/1512.03385.pdf>`_ `"Deep Residual Learning for Image Recognition" <https://arxiv.org/pdf/1512.03385.pdf>`_.
Args: Args:
pretrained (bool, optional): Whether to load pre-trained weights. If True, returns a model pre-trained pretrained (bool, optional): Whether to load pre-trained weights. If True, returns a model pre-trained
on ImageNet. Default: False. on ImageNet. Default: False.
**kwargs (optional): Additional keyword arguments. For details, please refer to :ref:`ResNet <api_paddle_vision_ResNet>`.
Returns: 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: Examples:
.. code-block:: python .. code-block:: python
...@@ -394,14 +395,15 @@ def resnet34(pretrained=False, **kwargs): ...@@ -394,14 +395,15 @@ def resnet34(pretrained=False, **kwargs):
def resnet50(pretrained=False, **kwargs): def resnet50(pretrained=False, **kwargs):
"""ResNet 50-layer model from """ResNet 50-layer model from
`"Deep Residual Learning for Image Recognition" <https://arxiv.org/pdf/1512.03385.pdf>`_ `"Deep Residual Learning for Image Recognition" <https://arxiv.org/pdf/1512.03385.pdf>`_.
Args: Args:
pretrained (bool, optional): Whether to load pre-trained weights. If True, returns a model pre-trained pretrained (bool, optional): Whether to load pre-trained weights. If True, returns a model pre-trained
on ImageNet. Default: False. on ImageNet. Default: False.
**kwargs (optional): Additional keyword arguments. For details, please refer to :ref:`ResNet <api_paddle_vision_ResNet>`.
Returns: 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: Examples:
.. code-block:: python .. code-block:: python
...@@ -426,14 +428,15 @@ def resnet50(pretrained=False, **kwargs): ...@@ -426,14 +428,15 @@ def resnet50(pretrained=False, **kwargs):
def resnet101(pretrained=False, **kwargs): def resnet101(pretrained=False, **kwargs):
"""ResNet 101-layer model from """ResNet 101-layer model from
`"Deep Residual Learning for Image Recognition" <https://arxiv.org/pdf/1512.03385.pdf>`_ `"Deep Residual Learning for Image Recognition" <https://arxiv.org/pdf/1512.03385.pdf>`_.
Args: Args:
pretrained (bool, optional): Whether to load pre-trained weights. If True, returns a model pre-trained pretrained (bool, optional): Whether to load pre-trained weights. If True, returns a model pre-trained
on ImageNet. Default: False. on ImageNet. Default: False.
**kwargs (optional): Additional keyword arguments. For details, please refer to :ref:`ResNet <api_paddle_vision_ResNet>`.
Returns: Returns:
ResNet 101-layer. An instance of :ref:`api_fluid_dygraph_Layer`. :ref:`api_paddle_nn_Layer`. An instance of ResNet 101-layer.
Examples: Examples:
.. code-block:: python .. code-block:: python
...@@ -458,14 +461,15 @@ def resnet101(pretrained=False, **kwargs): ...@@ -458,14 +461,15 @@ def resnet101(pretrained=False, **kwargs):
def resnet152(pretrained=False, **kwargs): def resnet152(pretrained=False, **kwargs):
"""ResNet 152-layer model from """ResNet 152-layer model from
`"Deep Residual Learning for Image Recognition" <https://arxiv.org/pdf/1512.03385.pdf>`_ `"Deep Residual Learning for Image Recognition" <https://arxiv.org/pdf/1512.03385.pdf>`_.
Args: Args:
pretrained (bool, optional): Whether to load pre-trained weights. If True, returns a model pre-trained pretrained (bool, optional): Whether to load pre-trained weights. If True, returns a model pre-trained
on ImageNet. Default: False. on ImageNet. Default: False.
**kwargs (optional): Additional keyword arguments. For details, please refer to :ref:`ResNet <api_paddle_vision_ResNet>`.
Returns: 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: Examples:
.. code-block:: python .. code-block:: python
...@@ -490,14 +494,15 @@ def resnet152(pretrained=False, **kwargs): ...@@ -490,14 +494,15 @@ def resnet152(pretrained=False, **kwargs):
def resnext50_32x4d(pretrained=False, **kwargs): def resnext50_32x4d(pretrained=False, **kwargs):
"""ResNeXt-50 32x4d model from """ResNeXt-50 32x4d model from
`"Aggregated Residual Transformations for Deep Neural Networks" <https://arxiv.org/pdf/1611.05431.pdf>`_ `"Aggregated Residual Transformations for Deep Neural Networks" <https://arxiv.org/pdf/1611.05431.pdf>`_.
Args: Args:
pretrained (bool, optional): Whether to load pre-trained weights. If True, returns a model pre-trained pretrained (bool, optional): Whether to load pre-trained weights. If True, returns a model pre-trained
on ImageNet. Default: False. on ImageNet. Default: False.
**kwargs (optional): Additional keyword arguments. For details, please refer to :ref:`ResNet <api_paddle_vision_ResNet>`.
Returns: 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: Examples:
.. code-block:: python .. code-block:: python
...@@ -524,14 +529,15 @@ def resnext50_32x4d(pretrained=False, **kwargs): ...@@ -524,14 +529,15 @@ def resnext50_32x4d(pretrained=False, **kwargs):
def resnext50_64x4d(pretrained=False, **kwargs): def resnext50_64x4d(pretrained=False, **kwargs):
"""ResNeXt-50 64x4d model from """ResNeXt-50 64x4d model from
`"Aggregated Residual Transformations for Deep Neural Networks" <https://arxiv.org/pdf/1611.05431.pdf>`_ `"Aggregated Residual Transformations for Deep Neural Networks" <https://arxiv.org/pdf/1611.05431.pdf>`_.
Args: Args:
pretrained (bool, optional): Whether to load pre-trained weights. If True, returns a model pre-trained pretrained (bool, optional): Whether to load pre-trained weights. If True, returns a model pre-trained
on ImageNet. Default: False. on ImageNet. Default: False.
**kwargs (optional): Additional keyword arguments. For details, please refer to :ref:`ResNet <api_paddle_vision_ResNet>`.
Returns: 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: Examples:
.. code-block:: python .. code-block:: python
...@@ -558,14 +564,15 @@ def resnext50_64x4d(pretrained=False, **kwargs): ...@@ -558,14 +564,15 @@ def resnext50_64x4d(pretrained=False, **kwargs):
def resnext101_32x4d(pretrained=False, **kwargs): def resnext101_32x4d(pretrained=False, **kwargs):
"""ResNeXt-101 32x4d model from """ResNeXt-101 32x4d model from
`"Aggregated Residual Transformations for Deep Neural Networks" <https://arxiv.org/pdf/1611.05431.pdf>`_ `"Aggregated Residual Transformations for Deep Neural Networks" <https://arxiv.org/pdf/1611.05431.pdf>`_.
Args: Args:
pretrained (bool, optional): Whether to load pre-trained weights. If True, returns a model pre-trained pretrained (bool, optional): Whether to load pre-trained weights. If True, returns a model pre-trained
on ImageNet. Default: False. on ImageNet. Default: False.
**kwargs (optional): Additional keyword arguments. For details, please refer to :ref:`ResNet <api_paddle_vision_ResNet>`.
Returns: 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: Examples:
.. code-block:: python .. code-block:: python
...@@ -593,14 +600,15 @@ def resnext101_32x4d(pretrained=False, **kwargs): ...@@ -593,14 +600,15 @@ def resnext101_32x4d(pretrained=False, **kwargs):
def resnext101_64x4d(pretrained=False, **kwargs): def resnext101_64x4d(pretrained=False, **kwargs):
"""ResNeXt-101 64x4d model from """ResNeXt-101 64x4d model from
`"Aggregated Residual Transformations for Deep Neural Networks" <https://arxiv.org/pdf/1611.05431.pdf>`_ `"Aggregated Residual Transformations for Deep Neural Networks" <https://arxiv.org/pdf/1611.05431.pdf>`_.
Args: Args:
pretrained (bool, optional): Whether to load pre-trained weights. If True, returns a model pre-trained pretrained (bool, optional): Whether to load pre-trained weights. If True, returns a model pre-trained
on ImageNet. Default: False. on ImageNet. Default: False.
**kwargs (optional): Additional keyword arguments. For details, please refer to :ref:`ResNet <api_paddle_vision_ResNet>`.
Returns: 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: Examples:
.. code-block:: python .. code-block:: python
...@@ -628,14 +636,15 @@ def resnext101_64x4d(pretrained=False, **kwargs): ...@@ -628,14 +636,15 @@ def resnext101_64x4d(pretrained=False, **kwargs):
def resnext152_32x4d(pretrained=False, **kwargs): def resnext152_32x4d(pretrained=False, **kwargs):
"""ResNeXt-152 32x4d model from """ResNeXt-152 32x4d model from
`"Aggregated Residual Transformations for Deep Neural Networks" <https://arxiv.org/pdf/1611.05431.pdf>`_ `"Aggregated Residual Transformations for Deep Neural Networks" <https://arxiv.org/pdf/1611.05431.pdf>`_.
Args: Args:
pretrained (bool, optional): Whether to load pre-trained weights. If True, returns a model pre-trained pretrained (bool, optional): Whether to load pre-trained weights. If True, returns a model pre-trained
on ImageNet. Default: False. on ImageNet. Default: False.
**kwargs (optional): Additional keyword arguments. For details, please refer to :ref:`ResNet <api_paddle_vision_ResNet>`.
Returns: 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: Examples:
.. code-block:: python .. code-block:: python
...@@ -663,14 +672,15 @@ def resnext152_32x4d(pretrained=False, **kwargs): ...@@ -663,14 +672,15 @@ def resnext152_32x4d(pretrained=False, **kwargs):
def resnext152_64x4d(pretrained=False, **kwargs): def resnext152_64x4d(pretrained=False, **kwargs):
"""ResNeXt-152 64x4d model from """ResNeXt-152 64x4d model from
`"Aggregated Residual Transformations for Deep Neural Networks" <https://arxiv.org/pdf/1611.05431.pdf>`_ `"Aggregated Residual Transformations for Deep Neural Networks" <https://arxiv.org/pdf/1611.05431.pdf>`_.
Args: Args:
pretrained (bool, optional): Whether to load pre-trained weights. If True, returns a model pre-trained pretrained (bool, optional): Whether to load pre-trained weights. If True, returns a model pre-trained
on ImageNet. Default: False. on ImageNet. Default: False.
**kwargs (optional): Additional keyword arguments. For details, please refer to :ref:`ResNet <api_paddle_vision_ResNet>`.
Returns: 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: Examples:
.. code-block:: python .. code-block:: python
...@@ -703,9 +713,10 @@ def wide_resnet50_2(pretrained=False, **kwargs): ...@@ -703,9 +713,10 @@ def wide_resnet50_2(pretrained=False, **kwargs):
Args: Args:
pretrained (bool, optional): Whether to load pre-trained weights. If True, returns a model pre-trained pretrained (bool, optional): Whether to load pre-trained weights. If True, returns a model pre-trained
on ImageNet. Default: False. on ImageNet. Default: False.
**kwargs (optional): Additional keyword arguments. For details, please refer to :ref:`ResNet <api_paddle_vision_ResNet>`.
Returns: 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: Examples:
.. code-block:: python .. code-block:: python
...@@ -736,9 +747,10 @@ def wide_resnet101_2(pretrained=False, **kwargs): ...@@ -736,9 +747,10 @@ def wide_resnet101_2(pretrained=False, **kwargs):
Args: Args:
pretrained (bool, optional): Whether to load pre-trained weights. If True, returns a model pre-trained pretrained (bool, optional): Whether to load pre-trained weights. If True, returns a model pre-trained
on ImageNet. Default: False. on ImageNet. Default: False.
**kwargs (optional): Additional keyword arguments. For details, please refer to :ref:`ResNet <api_paddle_vision_ResNet>`.
Returns: 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: Examples:
.. code-block:: python .. code-block:: python
......
...@@ -190,14 +190,17 @@ class InvertedResidualDS(nn.Layer): ...@@ -190,14 +190,17 @@ class InvertedResidualDS(nn.Layer):
class ShuffleNetV2(nn.Layer): class ShuffleNetV2(nn.Layer):
"""ShuffleNetV2 model from """ShuffleNetV2 model from
`"ShuffleNet V2: Practical Guidelines for Efficient CNN Architecture Design" <https://arxiv.org/pdf/1807.11164.pdf>`_ `"ShuffleNet V2: Practical Guidelines for Efficient CNN Architecture Design" <https://arxiv.org/pdf/1807.11164.pdf>`_.
Args: Args:
scale (float, optional) - scale of output channels. Default: True. scale (float, optional): Scale of output channels. Default: True.
act (str, optional) - activation function of neural network. Default: "relu". 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 num_classes (int, optional): Output dim of last fc layer. If num_classes <= 0, last fc layer
will not be defined. Default: 1000. 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: Examples:
.. code-block:: python .. code-block:: python
...@@ -209,7 +212,7 @@ class ShuffleNetV2(nn.Layer): ...@@ -209,7 +212,7 @@ class ShuffleNetV2(nn.Layer):
x = paddle.rand([1, 3, 224, 224]) x = paddle.rand([1, 3, 224, 224])
out = shufflenet_v2_swish(x) out = shufflenet_v2_swish(x)
print(out.shape) print(out.shape)
# [1, 1000]
""" """
def __init__(self, scale=1.0, act="relu", num_classes=1000, with_pool=True): 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): ...@@ -315,10 +318,15 @@ def _shufflenet_v2(arch, pretrained=False, **kwargs):
def shufflenet_v2_x0_25(pretrained=False, **kwargs): def shufflenet_v2_x0_25(pretrained=False, **kwargs):
"""ShuffleNetV2 with 0.25x output channels, as described in """ShuffleNetV2 with 0.25x output channels, as described in
`"ShuffleNet V2: Practical Guidelines for Ecient CNN Architecture Design" <https://arxiv.org/pdf/1807.11164.pdf>`_ `"ShuffleNet V2: Practical Guidelines for Ecient CNN Architecture Design" <https://arxiv.org/pdf/1807.11164.pdf>`_.
Args: 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 <api_paddle_vision_ShuffleNetV2>`.
Returns:
:ref:`api_paddle_nn_Layer`. An instance of ShuffleNetV2 with 0.25x output channels.
Examples: Examples:
.. code-block:: python .. code-block:: python
...@@ -336,7 +344,7 @@ def shufflenet_v2_x0_25(pretrained=False, **kwargs): ...@@ -336,7 +344,7 @@ def shufflenet_v2_x0_25(pretrained=False, **kwargs):
out = model(x) out = model(x)
print(out.shape) print(out.shape)
# [1, 1000]
""" """
return _shufflenet_v2("shufflenet_v2_x0_25", return _shufflenet_v2("shufflenet_v2_x0_25",
scale=0.25, scale=0.25,
...@@ -346,10 +354,15 @@ def shufflenet_v2_x0_25(pretrained=False, **kwargs): ...@@ -346,10 +354,15 @@ def shufflenet_v2_x0_25(pretrained=False, **kwargs):
def shufflenet_v2_x0_33(pretrained=False, **kwargs): def shufflenet_v2_x0_33(pretrained=False, **kwargs):
"""ShuffleNetV2 with 0.33x output channels, as described in """ShuffleNetV2 with 0.33x output channels, as described in
`"ShuffleNet V2: Practical Guidelines for Ecient CNN Architecture Design" <https://arxiv.org/pdf/1807.11164.pdf>`_ `"ShuffleNet V2: Practical Guidelines for Ecient CNN Architecture Design" <https://arxiv.org/pdf/1807.11164.pdf>`_.
Args: 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 <api_paddle_vision_ShuffleNetV2>`.
Returns:
:ref:`api_paddle_nn_Layer`. An instance of ShuffleNetV2 with 0.33x output channels.
Examples: Examples:
.. code-block:: python .. code-block:: python
...@@ -367,7 +380,7 @@ def shufflenet_v2_x0_33(pretrained=False, **kwargs): ...@@ -367,7 +380,7 @@ def shufflenet_v2_x0_33(pretrained=False, **kwargs):
out = model(x) out = model(x)
print(out.shape) print(out.shape)
# [1, 1000]
""" """
return _shufflenet_v2("shufflenet_v2_x0_33", return _shufflenet_v2("shufflenet_v2_x0_33",
scale=0.33, scale=0.33,
...@@ -377,10 +390,15 @@ def shufflenet_v2_x0_33(pretrained=False, **kwargs): ...@@ -377,10 +390,15 @@ def shufflenet_v2_x0_33(pretrained=False, **kwargs):
def shufflenet_v2_x0_5(pretrained=False, **kwargs): def shufflenet_v2_x0_5(pretrained=False, **kwargs):
"""ShuffleNetV2 with 0.5x output channels, as described in """ShuffleNetV2 with 0.5x output channels, as described in
`"ShuffleNet V2: Practical Guidelines for Ecient CNN Architecture Design" <https://arxiv.org/pdf/1807.11164.pdf>`_ `"ShuffleNet V2: Practical Guidelines for Ecient CNN Architecture Design" <https://arxiv.org/pdf/1807.11164.pdf>`_.
Args: 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 <api_paddle_vision_ShuffleNetV2>`.
Returns:
:ref:`api_paddle_nn_Layer`. An instance of ShuffleNetV2 with 0.5x output channels.
Examples: Examples:
.. code-block:: python .. code-block:: python
...@@ -398,7 +416,7 @@ def shufflenet_v2_x0_5(pretrained=False, **kwargs): ...@@ -398,7 +416,7 @@ def shufflenet_v2_x0_5(pretrained=False, **kwargs):
out = model(x) out = model(x)
print(out.shape) print(out.shape)
# [1, 1000]
""" """
return _shufflenet_v2("shufflenet_v2_x0_5", return _shufflenet_v2("shufflenet_v2_x0_5",
scale=0.5, scale=0.5,
...@@ -408,10 +426,15 @@ def shufflenet_v2_x0_5(pretrained=False, **kwargs): ...@@ -408,10 +426,15 @@ def shufflenet_v2_x0_5(pretrained=False, **kwargs):
def shufflenet_v2_x1_0(pretrained=False, **kwargs): def shufflenet_v2_x1_0(pretrained=False, **kwargs):
"""ShuffleNetV2 with 1.0x output channels, as described in """ShuffleNetV2 with 1.0x output channels, as described in
`"ShuffleNet V2: Practical Guidelines for Ecient CNN Architecture Design" <https://arxiv.org/pdf/1807.11164.pdf>`_ `"ShuffleNet V2: Practical Guidelines for Ecient CNN Architecture Design" <https://arxiv.org/pdf/1807.11164.pdf>`_.
Args: 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 <api_paddle_vision_ShuffleNetV2>`.
Returns:
:ref:`api_paddle_nn_Layer`. An instance of ShuffleNetV2 with 1.0x output channels.
Examples: Examples:
.. code-block:: python .. code-block:: python
...@@ -429,7 +452,7 @@ def shufflenet_v2_x1_0(pretrained=False, **kwargs): ...@@ -429,7 +452,7 @@ def shufflenet_v2_x1_0(pretrained=False, **kwargs):
out = model(x) out = model(x)
print(out.shape) print(out.shape)
# [1, 1000]
""" """
return _shufflenet_v2("shufflenet_v2_x1_0", return _shufflenet_v2("shufflenet_v2_x1_0",
scale=1.0, scale=1.0,
...@@ -439,10 +462,15 @@ def shufflenet_v2_x1_0(pretrained=False, **kwargs): ...@@ -439,10 +462,15 @@ def shufflenet_v2_x1_0(pretrained=False, **kwargs):
def shufflenet_v2_x1_5(pretrained=False, **kwargs): def shufflenet_v2_x1_5(pretrained=False, **kwargs):
"""ShuffleNetV2 with 1.5x output channels, as described in """ShuffleNetV2 with 1.5x output channels, as described in
`"ShuffleNet V2: Practical Guidelines for Ecient CNN Architecture Design" <https://arxiv.org/pdf/1807.11164.pdf>`_ `"ShuffleNet V2: Practical Guidelines for Ecient CNN Architecture Design" <https://arxiv.org/pdf/1807.11164.pdf>`_.
Args: 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 <api_paddle_vision_ShuffleNetV2>`.
Returns:
:ref:`api_paddle_nn_Layer`. An instance of ShuffleNetV2 with 1.5x output channels.
Examples: Examples:
.. code-block:: python .. code-block:: python
...@@ -460,7 +488,7 @@ def shufflenet_v2_x1_5(pretrained=False, **kwargs): ...@@ -460,7 +488,7 @@ def shufflenet_v2_x1_5(pretrained=False, **kwargs):
out = model(x) out = model(x)
print(out.shape) print(out.shape)
# [1, 1000]
""" """
return _shufflenet_v2("shufflenet_v2_x1_5", return _shufflenet_v2("shufflenet_v2_x1_5",
scale=1.5, scale=1.5,
...@@ -470,10 +498,15 @@ def shufflenet_v2_x1_5(pretrained=False, **kwargs): ...@@ -470,10 +498,15 @@ def shufflenet_v2_x1_5(pretrained=False, **kwargs):
def shufflenet_v2_x2_0(pretrained=False, **kwargs): def shufflenet_v2_x2_0(pretrained=False, **kwargs):
"""ShuffleNetV2 with 2.0x output channels, as described in """ShuffleNetV2 with 2.0x output channels, as described in
`"ShuffleNet V2: Practical Guidelines for Ecient CNN Architecture Design" <https://arxiv.org/pdf/1807.11164.pdf>`_ `"ShuffleNet V2: Practical Guidelines for Ecient CNN Architecture Design" <https://arxiv.org/pdf/1807.11164.pdf>`_.
Args: 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 <api_paddle_vision_ShuffleNetV2>`.
Returns:
:ref:`api_paddle_nn_Layer`. An instance of ShuffleNetV2 with 2.0x output channels.
Examples: Examples:
.. code-block:: python .. code-block:: python
...@@ -491,7 +524,7 @@ def shufflenet_v2_x2_0(pretrained=False, **kwargs): ...@@ -491,7 +524,7 @@ def shufflenet_v2_x2_0(pretrained=False, **kwargs):
out = model(x) out = model(x)
print(out.shape) print(out.shape)
# [1, 1000]
""" """
return _shufflenet_v2("shufflenet_v2_x2_0", return _shufflenet_v2("shufflenet_v2_x2_0",
scale=2.0, scale=2.0,
...@@ -500,11 +533,16 @@ def shufflenet_v2_x2_0(pretrained=False, **kwargs): ...@@ -500,11 +533,16 @@ def shufflenet_v2_x2_0(pretrained=False, **kwargs):
def shufflenet_v2_swish(pretrained=False, **kwargs): def shufflenet_v2_swish(pretrained=False, **kwargs):
"""ShuffleNetV2 with 1.0x output channels and swish activation function, as described in """ShuffleNetV2 with swish activation function, as described in
`"ShuffleNet V2: Practical Guidelines for Ecient CNN Architecture Design" <https://arxiv.org/pdf/1807.11164.pdf>`_ `"ShuffleNet V2: Practical Guidelines for Ecient CNN Architecture Design" <https://arxiv.org/pdf/1807.11164.pdf>`_.
Args: 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 <api_paddle_vision_ShuffleNetV2>`.
Returns:
:ref:`api_paddle_nn_Layer`. An instance of ShuffleNetV2 with swish activation function.
Examples: Examples:
.. code-block:: python .. code-block:: python
...@@ -522,7 +560,7 @@ def shufflenet_v2_swish(pretrained=False, **kwargs): ...@@ -522,7 +560,7 @@ def shufflenet_v2_swish(pretrained=False, **kwargs):
out = model(x) out = model(x)
print(out.shape) print(out.shape)
# [1, 1000]
""" """
return _shufflenet_v2("shufflenet_v2_swish", return _shufflenet_v2("shufflenet_v2_swish",
scale=1.0, scale=1.0,
......
...@@ -76,15 +76,20 @@ class MakeFire(nn.Layer): ...@@ -76,15 +76,20 @@ class MakeFire(nn.Layer):
class SqueezeNet(nn.Layer): class SqueezeNet(nn.Layer):
"""SqueezeNet model from """SqueezeNet model from
`"SqueezeNet: AlexNet-level accuracy with 50x fewer parameters and <0.5MB model size" `"SqueezeNet: AlexNet-level accuracy with 50x fewer parameters and <0.5MB model size"
<https://arxiv.org/pdf/1602.07360.pdf>`_ <https://arxiv.org/pdf/1602.07360.pdf>`_.
Args: Args:
version (str): version of squeezenet, which can be "1.0" or "1.1". version (str): Version of SqueezeNet, which can be "1.0" or "1.1".
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
with_pool (bool): use pool before the last fc layer or not. Default: True. 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: Examples:
.. code-block:: python .. code-block:: python
import paddle import paddle
from paddle.vision.models import SqueezeNet from paddle.vision.models import SqueezeNet
...@@ -98,7 +103,7 @@ class SqueezeNet(nn.Layer): ...@@ -98,7 +103,7 @@ class SqueezeNet(nn.Layer):
out = model(x) out = model(x)
print(out.shape) print(out.shape)
# [1, 1000]
""" """
def __init__(self, version, num_classes=1000, with_pool=True): def __init__(self, version, num_classes=1000, with_pool=True):
...@@ -205,14 +210,22 @@ def _squeezenet(arch, version, pretrained, **kwargs): ...@@ -205,14 +210,22 @@ def _squeezenet(arch, version, pretrained, **kwargs):
def squeezenet1_0(pretrained=False, **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"
<https://arxiv.org/pdf/1602.07360.pdf>`_.
Args: 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 <api_paddle_vision_SqueezeNet>`.
Returns:
:ref:`api_paddle_nn_Layer`. An instance of SqueezeNet v1.0 model.
Examples: Examples:
.. code-block:: python .. code-block:: python
import paddle
from paddle.vision.models import squeezenet1_0 from paddle.vision.models import squeezenet1_0
# build model # build model
...@@ -220,19 +233,33 @@ def squeezenet1_0(pretrained=False, **kwargs): ...@@ -220,19 +233,33 @@ def squeezenet1_0(pretrained=False, **kwargs):
# build model and load imagenet pretrained weight # build model and load imagenet pretrained weight
# model = squeezenet1_0(pretrained=True) # 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) return _squeezenet('squeezenet1_0', '1.0', pretrained, **kwargs)
def squeezenet1_1(pretrained=False, **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"
<https://arxiv.org/pdf/1602.07360.pdf>`_.
Args: 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 <api_paddle_vision_SqueezeNet>`.
Returns:
:ref:`api_paddle_nn_Layer`. An instance of SqueezeNet v1.1 model.
Examples: Examples:
.. code-block:: python .. code-block:: python
import paddle
from paddle.vision.models import squeezenet1_1 from paddle.vision.models import squeezenet1_1
# build model # build model
...@@ -240,5 +267,11 @@ def squeezenet1_1(pretrained=False, **kwargs): ...@@ -240,5 +267,11 @@ def squeezenet1_1(pretrained=False, **kwargs):
# build model and load imagenet pretrained weight # build model and load imagenet pretrained weight
# model = squeezenet1_1(pretrained=True) # 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) return _squeezenet('squeezenet1_1', '1.1', pretrained, **kwargs)
...@@ -29,17 +29,19 @@ model_urls = { ...@@ -29,17 +29,19 @@ model_urls = {
class VGG(nn.Layer): class VGG(nn.Layer):
"""VGG model from """VGG model from
`"Very Deep Convolutional Networks For Large-Scale Image Recognition" <https://arxiv.org/pdf/1409.1556.pdf>`_ `"Very Deep Convolutional Networks For Large-Scale Image Recognition" <https://arxiv.org/pdf/1409.1556.pdf>`_.
Args: Args:
features (nn.Layer): Vgg features create by function make_layers. 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. will not be defined. Default: 1000.
with_pool (bool, optional): Use pool before the last three fc layer or not. Default: True. 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: Examples:
.. code-block:: python .. code-block:: python
:name: code-example
import paddle import paddle
from paddle.vision.models import VGG from paddle.vision.models import VGG
...@@ -56,7 +58,6 @@ class VGG(nn.Layer): ...@@ -56,7 +58,6 @@ class VGG(nn.Layer):
print(out.shape) print(out.shape)
# [1, 1000] # [1, 1000]
""" """
def __init__(self, features, num_classes=1000, with_pool=True): def __init__(self, features, num_classes=1000, with_pool=True):
...@@ -139,15 +140,22 @@ def _vgg(arch, cfg, batch_norm, pretrained, **kwargs): ...@@ -139,15 +140,22 @@ def _vgg(arch, cfg, batch_norm, pretrained, **kwargs):
def vgg11(pretrained=False, batch_norm=False, **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" <https://arxiv.org/pdf/1409.1556.pdf>`_.
Args: 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
batch_norm (bool): If True, returns a model with batch_norm layer. Default: False. 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 <api_paddle_vision_VGG>`.
Returns:
:ref:`api_paddle_nn_Layer`. An instance of VGG 11-layer model.
Examples: Examples:
.. code-block:: python .. code-block:: python
import paddle
from paddle.vision.models import vgg11 from paddle.vision.models import vgg11
# build model # build model
...@@ -155,6 +163,12 @@ def vgg11(pretrained=False, batch_norm=False, **kwargs): ...@@ -155,6 +163,12 @@ def vgg11(pretrained=False, batch_norm=False, **kwargs):
# build vgg11 model with batch_norm # build vgg11 model with batch_norm
model = vgg11(batch_norm=True) model = vgg11(batch_norm=True)
x = paddle.rand([1, 3, 224, 224])
out = model(x)
print(out.shape)
# [1, 1000]
""" """
model_name = 'vgg11' model_name = 'vgg11'
if batch_norm: if batch_norm:
...@@ -163,15 +177,22 @@ def vgg11(pretrained=False, batch_norm=False, **kwargs): ...@@ -163,15 +177,22 @@ def vgg11(pretrained=False, batch_norm=False, **kwargs):
def vgg13(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" <https://arxiv.org/pdf/1409.1556.pdf>`_.
Args: 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. 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 <api_paddle_vision_VGG>`.
Returns:
:ref:`api_paddle_nn_Layer`. An instance of VGG 13-layer model.
Examples: Examples:
.. code-block:: python .. code-block:: python
import paddle
from paddle.vision.models import vgg13 from paddle.vision.models import vgg13
# build model # build model
...@@ -179,6 +200,12 @@ def vgg13(pretrained=False, batch_norm=False, **kwargs): ...@@ -179,6 +200,12 @@ def vgg13(pretrained=False, batch_norm=False, **kwargs):
# build vgg13 model with batch_norm # build vgg13 model with batch_norm
model = vgg13(batch_norm=True) model = vgg13(batch_norm=True)
x = paddle.rand([1, 3, 224, 224])
out = model(x)
print(out.shape)
# [1, 1000]
""" """
model_name = 'vgg13' model_name = 'vgg13'
if batch_norm: if batch_norm:
...@@ -187,15 +214,22 @@ def vgg13(pretrained=False, batch_norm=False, **kwargs): ...@@ -187,15 +214,22 @@ def vgg13(pretrained=False, batch_norm=False, **kwargs):
def vgg16(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" <https://arxiv.org/pdf/1409.1556.pdf>`_.
Args: 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
batch_norm (bool): If True, returns a model with batch_norm layer. Default: False. 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 <api_paddle_vision_VGG>`.
Returns:
:ref:`api_paddle_nn_Layer`. An instance of VGG 16-layer model.
Examples: Examples:
.. code-block:: python .. code-block:: python
import paddle
from paddle.vision.models import vgg16 from paddle.vision.models import vgg16
# build model # build model
...@@ -203,6 +237,12 @@ def vgg16(pretrained=False, batch_norm=False, **kwargs): ...@@ -203,6 +237,12 @@ def vgg16(pretrained=False, batch_norm=False, **kwargs):
# build vgg16 model with batch_norm # build vgg16 model with batch_norm
model = vgg16(batch_norm=True) model = vgg16(batch_norm=True)
x = paddle.rand([1, 3, 224, 224])
out = model(x)
print(out.shape)
# [1, 1000]
""" """
model_name = 'vgg16' model_name = 'vgg16'
if batch_norm: if batch_norm:
...@@ -211,15 +251,22 @@ def vgg16(pretrained=False, batch_norm=False, **kwargs): ...@@ -211,15 +251,22 @@ def vgg16(pretrained=False, batch_norm=False, **kwargs):
def vgg19(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" <https://arxiv.org/pdf/1409.1556.pdf>`_.
Args: 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
batch_norm (bool): If True, returns a model with batch_norm layer. Default: False. 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 <api_paddle_vision_VGG>`.
Returns:
:ref:`api_paddle_nn_Layer`. An instance of VGG 19-layer model.
Examples: Examples:
.. code-block:: python .. code-block:: python
import paddle
from paddle.vision.models import vgg19 from paddle.vision.models import vgg19
# build model # build model
...@@ -227,6 +274,12 @@ def vgg19(pretrained=False, batch_norm=False, **kwargs): ...@@ -227,6 +274,12 @@ def vgg19(pretrained=False, batch_norm=False, **kwargs):
# build vgg19 model with batch_norm # build vgg19 model with batch_norm
model = vgg19(batch_norm=True) model = vgg19(batch_norm=True)
x = paddle.rand([1, 3, 224, 224])
out = model(x)
print(out.shape)
# [1, 1000]
""" """
model_name = 'vgg19' model_name = 'vgg19'
if batch_norm: if batch_norm:
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册