From 7fbe34245c698fe4f79346259b4a264e2ba1e78e Mon Sep 17 00:00:00 2001 From: David Nicolas <37790151+liyongchao911@users.noreply.github.com> Date: Mon, 21 Aug 2023 11:58:28 +0800 Subject: [PATCH] [xdoctest] No.161-162 update models docstring for doc xdoctest (#56422) --- python/paddle/vision/models/resnet.py | 290 ++++++++++---------- python/paddle/vision/models/shufflenetv2.py | 156 +++++------ 2 files changed, 223 insertions(+), 223 deletions(-) diff --git a/python/paddle/vision/models/resnet.py b/python/paddle/vision/models/resnet.py index 00f49201aea..d91cd66f04f 100644 --- a/python/paddle/vision/models/resnet.py +++ b/python/paddle/vision/models/resnet.py @@ -210,27 +210,27 @@ class ResNet(nn.Layer): Examples: .. code-block:: python - import paddle - from paddle.vision.models import ResNet - from paddle.vision.models.resnet import BottleneckBlock, BasicBlock + >>> import paddle + >>> from paddle.vision.models import ResNet + >>> from paddle.vision.models.resnet import BottleneckBlock, BasicBlock - # build ResNet with 18 layers - resnet18 = ResNet(BasicBlock, 18) + >>> # build ResNet with 18 layers + >>> resnet18 = ResNet(BasicBlock, 18) - # build ResNet with 50 layers - resnet50 = ResNet(BottleneckBlock, 50) + >>> # build ResNet with 50 layers + >>> resnet50 = ResNet(BottleneckBlock, 50) - # build Wide ResNet model - wide_resnet50_2 = ResNet(BottleneckBlock, 50, width=64*2) + >>> # build Wide ResNet model + >>> wide_resnet50_2 = ResNet(BottleneckBlock, 50, width=64*2) - # build ResNeXt model - resnext50_32x4d = ResNet(BottleneckBlock, 50, width=4, groups=32) + >>> # build ResNeXt model + >>> resnext50_32x4d = ResNet(BottleneckBlock, 50, width=4, groups=32) - x = paddle.rand([1, 3, 224, 224]) - out = resnet18(x) + >>> x = paddle.rand([1, 3, 224, 224]) + >>> out = resnet18(x) - print(out.shape) - # [1, 1000] + >>> print(out.shape) + [1, 1000] """ def __init__( @@ -380,20 +380,20 @@ def resnet18(pretrained=False, **kwargs): Examples: .. code-block:: python - import paddle - from paddle.vision.models import resnet18 + >>> import paddle + >>> from paddle.vision.models import resnet18 - # build model - model = resnet18() + >>> # build model + >>> model = resnet18() - # build model and load imagenet pretrained weight - # model = resnet18(pretrained=True) + >>> # build model and load imagenet pretrained weight + >>> # model = resnet18(pretrained=True) - x = paddle.rand([1, 3, 224, 224]) - out = model(x) + >>> x = paddle.rand([1, 3, 224, 224]) + >>> out = model(x) - print(out.shape) - # [1, 1000] + >>> print(out.shape) + [1, 1000] """ return _resnet('resnet18', BasicBlock, 18, pretrained, **kwargs) @@ -413,20 +413,20 @@ def resnet34(pretrained=False, **kwargs): Examples: .. code-block:: python - import paddle - from paddle.vision.models import resnet34 + >>> import paddle + >>> from paddle.vision.models import resnet34 - # build model - model = resnet34() + >>> # build model + >>> model = resnet34() - # build model and load imagenet pretrained weight - # model = resnet34(pretrained=True) + >>> # build model and load imagenet pretrained weight + >>> # model = resnet34(pretrained=True) - x = paddle.rand([1, 3, 224, 224]) - out = model(x) + >>> x = paddle.rand([1, 3, 224, 224]) + >>> out = model(x) - print(out.shape) - # [1, 1000] + >>> print(out.shape) + [1, 1000] """ return _resnet('resnet34', BasicBlock, 34, pretrained, **kwargs) @@ -446,20 +446,20 @@ def resnet50(pretrained=False, **kwargs): Examples: .. code-block:: python - import paddle - from paddle.vision.models import resnet50 + >>> import paddle + >>> from paddle.vision.models import resnet50 - # build model - model = resnet50() + >>> # build model + >>> model = resnet50() - # build model and load imagenet pretrained weight - # model = resnet50(pretrained=True) + >>> # build model and load imagenet pretrained weight + >>> # model = resnet50(pretrained=True) - x = paddle.rand([1, 3, 224, 224]) - out = model(x) + >>> x = paddle.rand([1, 3, 224, 224]) + >>> out = model(x) - print(out.shape) - # [1, 1000] + >>> print(out.shape) + [1, 1000] """ return _resnet('resnet50', BottleneckBlock, 50, pretrained, **kwargs) @@ -479,20 +479,20 @@ def resnet101(pretrained=False, **kwargs): Examples: .. code-block:: python - import paddle - from paddle.vision.models import resnet101 + >>> import paddle + >>> from paddle.vision.models import resnet101 - # build model - model = resnet101() + >>> # build model + >>> model = resnet101() - # build model and load imagenet pretrained weight - # model = resnet101(pretrained=True) + >>> # build model and load imagenet pretrained weight + >>> # model = resnet101(pretrained=True) - x = paddle.rand([1, 3, 224, 224]) - out = model(x) + >>> x = paddle.rand([1, 3, 224, 224]) + >>> out = model(x) - print(out.shape) - # [1, 1000] + >>> print(out.shape) + [1, 1000] """ return _resnet('resnet101', BottleneckBlock, 101, pretrained, **kwargs) @@ -512,20 +512,20 @@ def resnet152(pretrained=False, **kwargs): Examples: .. code-block:: python - import paddle - from paddle.vision.models import resnet152 + >>> import paddle + >>> from paddle.vision.models import resnet152 - # build model - model = resnet152() + >>> # build model + >>> model = resnet152() - # build model and load imagenet pretrained weight - # model = resnet152(pretrained=True) + >>> # build model and load imagenet pretrained weight + >>> # model = resnet152(pretrained=True) - x = paddle.rand([1, 3, 224, 224]) - out = model(x) + >>> x = paddle.rand([1, 3, 224, 224]) + >>> out = model(x) - print(out.shape) - # [1, 1000] + >>> print(out.shape) + [1, 1000] """ return _resnet('resnet152', BottleneckBlock, 152, pretrained, **kwargs) @@ -545,20 +545,20 @@ def resnext50_32x4d(pretrained=False, **kwargs): Examples: .. code-block:: python - import paddle - from paddle.vision.models import resnext50_32x4d + >>> import paddle + >>> from paddle.vision.models import resnext50_32x4d - # build model - model = resnext50_32x4d() + >>> # build model + >>> model = resnext50_32x4d() - # build model and load imagenet pretrained weight - # model = resnext50_32x4d(pretrained=True) + >>> # build model and load imagenet pretrained weight + >>> # model = resnext50_32x4d(pretrained=True) - x = paddle.rand([1, 3, 224, 224]) - out = model(x) + >>> x = paddle.rand([1, 3, 224, 224]) + >>> out = model(x) - print(out.shape) - # [1, 1000] + >>> print(out.shape) + [1, 1000] """ kwargs['groups'] = 32 kwargs['width'] = 4 @@ -580,20 +580,20 @@ def resnext50_64x4d(pretrained=False, **kwargs): Examples: .. code-block:: python - import paddle - from paddle.vision.models import resnext50_64x4d + >>> import paddle + >>> from paddle.vision.models import resnext50_64x4d - # build model - model = resnext50_64x4d() + >>> # build model + >>> model = resnext50_64x4d() - # build model and load imagenet pretrained weight - # model = resnext50_64x4d(pretrained=True) + >>> # build model and load imagenet pretrained weight + >>> # model = resnext50_64x4d(pretrained=True) - x = paddle.rand([1, 3, 224, 224]) - out = model(x) + >>> x = paddle.rand([1, 3, 224, 224]) + >>> out = model(x) - print(out.shape) - # [1, 1000] + >>> print(out.shape) + [1, 1000] """ kwargs['groups'] = 64 kwargs['width'] = 4 @@ -615,20 +615,20 @@ def resnext101_32x4d(pretrained=False, **kwargs): Examples: .. code-block:: python - import paddle - from paddle.vision.models import resnext101_32x4d + >>> import paddle + >>> from paddle.vision.models import resnext101_32x4d - # build model - model = resnext101_32x4d() + >>> # build model + >>> model = resnext101_32x4d() - # build model and load imagenet pretrained weight - # model = resnext101_32x4d(pretrained=True) + >>> # build model and load imagenet pretrained weight + >>> # model = resnext101_32x4d(pretrained=True) - x = paddle.rand([1, 3, 224, 224]) - out = model(x) + >>> x = paddle.rand([1, 3, 224, 224]) + >>> out = model(x) - print(out.shape) - # [1, 1000] + >>> print(out.shape) + [1, 1000] """ kwargs['groups'] = 32 kwargs['width'] = 4 @@ -652,20 +652,20 @@ def resnext101_64x4d(pretrained=False, **kwargs): Examples: .. code-block:: python - import paddle - from paddle.vision.models import resnext101_64x4d + >>> import paddle + >>> from paddle.vision.models import resnext101_64x4d - # build model - model = resnext101_64x4d() + >>> # build model + >>> model = resnext101_64x4d() - # build model and load imagenet pretrained weight - # model = resnext101_64x4d(pretrained=True) + >>> # build model and load imagenet pretrained weight + >>> # model = resnext101_64x4d(pretrained=True) - x = paddle.rand([1, 3, 224, 224]) - out = model(x) + >>> x = paddle.rand([1, 3, 224, 224]) + >>> out = model(x) - print(out.shape) - # [1, 1000] + >>> print(out.shape) + [1, 1000] """ kwargs['groups'] = 64 kwargs['width'] = 4 @@ -689,20 +689,20 @@ def resnext152_32x4d(pretrained=False, **kwargs): Examples: .. code-block:: python - import paddle - from paddle.vision.models import resnext152_32x4d + >>> import paddle + >>> from paddle.vision.models import resnext152_32x4d - # build model - model = resnext152_32x4d() + >>> # build model + >>> model = resnext152_32x4d() - # build model and load imagenet pretrained weight - # model = resnext152_32x4d(pretrained=True) + >>> # build model and load imagenet pretrained weight + >>> # model = resnext152_32x4d(pretrained=True) - x = paddle.rand([1, 3, 224, 224]) - out = model(x) + >>> x = paddle.rand([1, 3, 224, 224]) + >>> out = model(x) - print(out.shape) - # [1, 1000] + >>> print(out.shape) + [1, 1000] """ kwargs['groups'] = 32 kwargs['width'] = 4 @@ -726,20 +726,20 @@ def resnext152_64x4d(pretrained=False, **kwargs): Examples: .. code-block:: python - import paddle - from paddle.vision.models import resnext152_64x4d + >>> import paddle + >>> from paddle.vision.models import resnext152_64x4d - # build model - model = resnext152_64x4d() + >>> # build model + >>> model = resnext152_64x4d() - # build model and load imagenet pretrained weight - # model = resnext152_64x4d(pretrained=True) + >>> # build model and load imagenet pretrained weight + >>> # model = resnext152_64x4d(pretrained=True) - x = paddle.rand([1, 3, 224, 224]) - out = model(x) + >>> x = paddle.rand([1, 3, 224, 224]) + >>> out = model(x) - print(out.shape) - # [1, 1000] + >>> print(out.shape) + [1, 1000] """ kwargs['groups'] = 64 kwargs['width'] = 4 @@ -763,20 +763,20 @@ def wide_resnet50_2(pretrained=False, **kwargs): Examples: .. code-block:: python - import paddle - from paddle.vision.models import wide_resnet50_2 + >>> import paddle + >>> from paddle.vision.models import wide_resnet50_2 - # build model - model = wide_resnet50_2() + >>> # build model + >>> model = wide_resnet50_2() - # build model and load imagenet pretrained weight - # model = wide_resnet50_2(pretrained=True) + >>> # build model and load imagenet pretrained weight + >>> # model = wide_resnet50_2(pretrained=True) - x = paddle.rand([1, 3, 224, 224]) - out = model(x) + >>> x = paddle.rand([1, 3, 224, 224]) + >>> out = model(x) - print(out.shape) - # [1, 1000] + >>> print(out.shape) + [1, 1000] """ kwargs['width'] = 64 * 2 return _resnet('wide_resnet50_2', BottleneckBlock, 50, pretrained, **kwargs) @@ -797,20 +797,20 @@ def wide_resnet101_2(pretrained=False, **kwargs): Examples: .. code-block:: python - import paddle - from paddle.vision.models import wide_resnet101_2 + >>> import paddle + >>> from paddle.vision.models import wide_resnet101_2 - # build model - model = wide_resnet101_2() + >>> # build model + >>> model = wide_resnet101_2() - # build model and load imagenet pretrained weight - # model = wide_resnet101_2(pretrained=True) + >>> # build model and load imagenet pretrained weight + >>> # model = wide_resnet101_2(pretrained=True) - x = paddle.rand([1, 3, 224, 224]) - out = model(x) + >>> x = paddle.rand([1, 3, 224, 224]) + >>> out = model(x) - print(out.shape) - # [1, 1000] + >>> print(out.shape) + [1, 1000] """ kwargs['width'] = 64 * 2 return _resnet( diff --git a/python/paddle/vision/models/shufflenetv2.py b/python/paddle/vision/models/shufflenetv2.py index c146bb88ddc..4725798b1e6 100644 --- a/python/paddle/vision/models/shufflenetv2.py +++ b/python/paddle/vision/models/shufflenetv2.py @@ -209,14 +209,14 @@ class ShuffleNetV2(nn.Layer): Examples: .. code-block:: python - import paddle - from paddle.vision.models import ShuffleNetV2 - - shufflenet_v2_swish = ShuffleNetV2(scale=1.0, act="swish") - x = paddle.rand([1, 3, 224, 224]) - out = shufflenet_v2_swish(x) - print(out.shape) - # [1, 1000] + >>> import paddle + >>> from paddle.vision.models import ShuffleNetV2 + + >>> shufflenet_v2_swish = ShuffleNetV2(scale=1.0, act="swish") + >>> 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): @@ -345,20 +345,20 @@ def shufflenet_v2_x0_25(pretrained=False, **kwargs): Examples: .. code-block:: python - import paddle - from paddle.vision.models import shufflenet_v2_x0_25 + >>> import paddle + >>> from paddle.vision.models import shufflenet_v2_x0_25 - # build model - model = shufflenet_v2_x0_25() + >>> # build model + >>> model = shufflenet_v2_x0_25() - # build model and load imagenet pretrained weight - # model = shufflenet_v2_x0_25(pretrained=True) + >>> # build model and load imagenet pretrained weight + >>> # model = shufflenet_v2_x0_25(pretrained=True) - x = paddle.rand([1, 3, 224, 224]) - out = model(x) + >>> x = paddle.rand([1, 3, 224, 224]) + >>> out = model(x) - print(out.shape) - # [1, 1000] + >>> print(out.shape) + [1, 1000] """ return _shufflenet_v2( "shufflenet_v2_x0_25", scale=0.25, pretrained=pretrained, **kwargs @@ -380,20 +380,20 @@ def shufflenet_v2_x0_33(pretrained=False, **kwargs): Examples: .. code-block:: python - import paddle - from paddle.vision.models import shufflenet_v2_x0_33 + >>> import paddle + >>> from paddle.vision.models import shufflenet_v2_x0_33 - # build model - model = shufflenet_v2_x0_33() + >>> # build model + >>> model = shufflenet_v2_x0_33() - # build model and load imagenet pretrained weight - # model = shufflenet_v2_x0_33(pretrained=True) + >>> # build model and load imagenet pretrained weight + >>> # model = shufflenet_v2_x0_33(pretrained=True) - x = paddle.rand([1, 3, 224, 224]) - out = model(x) + >>> x = paddle.rand([1, 3, 224, 224]) + >>> out = model(x) - print(out.shape) - # [1, 1000] + >>> print(out.shape) + [1, 1000] """ return _shufflenet_v2( "shufflenet_v2_x0_33", scale=0.33, pretrained=pretrained, **kwargs @@ -415,20 +415,20 @@ def shufflenet_v2_x0_5(pretrained=False, **kwargs): Examples: .. code-block:: python - import paddle - from paddle.vision.models import shufflenet_v2_x0_5 + >>> import paddle + >>> from paddle.vision.models import shufflenet_v2_x0_5 - # build model - model = shufflenet_v2_x0_5() + >>> # build model + >>> model = shufflenet_v2_x0_5() - # build model and load imagenet pretrained weight - # model = shufflenet_v2_x0_5(pretrained=True) + >>> # build model and load imagenet pretrained weight + >>> # model = shufflenet_v2_x0_5(pretrained=True) - x = paddle.rand([1, 3, 224, 224]) - out = model(x) + >>> x = paddle.rand([1, 3, 224, 224]) + >>> out = model(x) - print(out.shape) - # [1, 1000] + >>> print(out.shape) + [1, 1000] """ return _shufflenet_v2( "shufflenet_v2_x0_5", scale=0.5, pretrained=pretrained, **kwargs @@ -450,20 +450,20 @@ def shufflenet_v2_x1_0(pretrained=False, **kwargs): Examples: .. code-block:: python - import paddle - from paddle.vision.models import shufflenet_v2_x1_0 + >>> import paddle + >>> from paddle.vision.models import shufflenet_v2_x1_0 - # build model - model = shufflenet_v2_x1_0() + >>> # build model + >>> model = shufflenet_v2_x1_0() - # build model and load imagenet pretrained weight - # model = shufflenet_v2_x1_0(pretrained=True) + >>> # build model and load imagenet pretrained weight + >>> # model = shufflenet_v2_x1_0(pretrained=True) - x = paddle.rand([1, 3, 224, 224]) - out = model(x) + >>> x = paddle.rand([1, 3, 224, 224]) + >>> out = model(x) - print(out.shape) - # [1, 1000] + >>> print(out.shape) + [1, 1000] """ return _shufflenet_v2( "shufflenet_v2_x1_0", scale=1.0, pretrained=pretrained, **kwargs @@ -485,20 +485,20 @@ def shufflenet_v2_x1_5(pretrained=False, **kwargs): Examples: .. code-block:: python - import paddle - from paddle.vision.models import shufflenet_v2_x1_5 + >>> import paddle + >>> from paddle.vision.models import shufflenet_v2_x1_5 - # build model - model = shufflenet_v2_x1_5() + >>> # build model + >>> model = shufflenet_v2_x1_5() - # build model and load imagenet pretrained weight - # model = shufflenet_v2_x1_5(pretrained=True) + >>> # build model and load imagenet pretrained weight + >>> # model = shufflenet_v2_x1_5(pretrained=True) - x = paddle.rand([1, 3, 224, 224]) - out = model(x) + >>> x = paddle.rand([1, 3, 224, 224]) + >>> out = model(x) - print(out.shape) - # [1, 1000] + >>> print(out.shape) + [1, 1000] """ return _shufflenet_v2( "shufflenet_v2_x1_5", scale=1.5, pretrained=pretrained, **kwargs @@ -520,20 +520,20 @@ def shufflenet_v2_x2_0(pretrained=False, **kwargs): Examples: .. code-block:: python - import paddle - from paddle.vision.models import shufflenet_v2_x2_0 + >>> import paddle + >>> from paddle.vision.models import shufflenet_v2_x2_0 - # build model - model = shufflenet_v2_x2_0() + >>> # build model + >>> model = shufflenet_v2_x2_0() - # build model and load imagenet pretrained weight - # model = shufflenet_v2_x2_0(pretrained=True) + >>> # build model and load imagenet pretrained weight + >>> # model = shufflenet_v2_x2_0(pretrained=True) - x = paddle.rand([1, 3, 224, 224]) - out = model(x) + >>> x = paddle.rand([1, 3, 224, 224]) + >>> out = model(x) - print(out.shape) - # [1, 1000] + >>> print(out.shape) + [1, 1000] """ return _shufflenet_v2( "shufflenet_v2_x2_0", scale=2.0, pretrained=pretrained, **kwargs @@ -555,20 +555,20 @@ def shufflenet_v2_swish(pretrained=False, **kwargs): Examples: .. code-block:: python - import paddle - from paddle.vision.models import shufflenet_v2_swish + >>> import paddle + >>> from paddle.vision.models import shufflenet_v2_swish - # build model - model = shufflenet_v2_swish() + >>> # build model + >>> model = shufflenet_v2_swish() - # build model and load imagenet pretrained weight - # model = shufflenet_v2_swish(pretrained=True) + >>> # build model and load imagenet pretrained weight + >>> # model = shufflenet_v2_swish(pretrained=True) - x = paddle.rand([1, 3, 224, 224]) - out = model(x) + >>> x = paddle.rand([1, 3, 224, 224]) + >>> out = model(x) - print(out.shape) - # [1, 1000] + >>> print(out.shape) + [1, 1000] """ return _shufflenet_v2( "shufflenet_v2_swish", -- GitLab