From aea18ccde88f4309f1795d429997e299a37af556 Mon Sep 17 00:00:00 2001 From: liyongchao911 <11_258@163.com> Date: Tue, 22 Aug 2023 11:37:02 +0800 Subject: [PATCH 1/5] [Doctest]fix No.163,164,166, test=docs_preview --- python/paddle/vision/models/squeezenet.py | 54 +-- python/paddle/vision/models/vgg.py | 100 +++--- python/paddle/vision/transforms/functional.py | 321 ++++++++++-------- 3 files changed, 247 insertions(+), 228 deletions(-) diff --git a/python/paddle/vision/models/squeezenet.py b/python/paddle/vision/models/squeezenet.py index 97b1eefe45941..bca23cade983b 100644 --- a/python/paddle/vision/models/squeezenet.py +++ b/python/paddle/vision/models/squeezenet.py @@ -90,19 +90,19 @@ class SqueezeNet(nn.Layer): Examples: .. code-block:: python - import paddle - from paddle.vision.models import SqueezeNet + >>> import paddle + >>> from paddle.vision.models import SqueezeNet - # build v1.0 model - model = SqueezeNet(version='1.0') + >>> # build v1.0 model + >>> model = SqueezeNet(version='1.0') - # build v1.1 model - # model = SqueezeNet(version='1.1') + >>> # build v1.1 model + >>> # model = SqueezeNet(version='1.1') - x = paddle.rand([1, 3, 224, 224]) - out = model(x) + >>> x = paddle.rand([1, 3, 224, 224]) + >>> out = model(x) - print(out.shape) + >>> print(out.shape) # [1, 1000] """ @@ -233,19 +233,19 @@ def squeezenet1_0(pretrained=False, **kwargs): Examples: .. code-block:: python - import paddle - from paddle.vision.models import squeezenet1_0 + >>> import paddle + >>> from paddle.vision.models import squeezenet1_0 - # build model - model = squeezenet1_0() + >>> # build model + >>> model = squeezenet1_0() - # build model and load imagenet pretrained weight - # model = squeezenet1_0(pretrained=True) + >>> # build model and load imagenet pretrained weight + >>> # model = squeezenet1_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) + >>> print(out.shape) # [1, 1000] """ return _squeezenet('squeezenet1_0', '1.0', pretrained, **kwargs) @@ -267,19 +267,19 @@ def squeezenet1_1(pretrained=False, **kwargs): Examples: .. code-block:: python - import paddle - from paddle.vision.models import squeezenet1_1 + >>> import paddle + >>> from paddle.vision.models import squeezenet1_1 - # build model - model = squeezenet1_1() + >>> # build model + >>> model = squeezenet1_1() - # build model and load imagenet pretrained weight - # model = squeezenet1_1(pretrained=True) + >>> # build model and load imagenet pretrained weight + >>> # model = squeezenet1_1(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) + >>> 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 b0b62f445d0b4..b354089025e51 100644 --- a/python/paddle/vision/models/vgg.py +++ b/python/paddle/vision/models/vgg.py @@ -46,21 +46,21 @@ class VGG(nn.Layer): Examples: .. code-block:: python - import paddle - from paddle.vision.models import VGG - from paddle.vision.models.vgg import make_layers + >>> import paddle + >>> from paddle.vision.models import VGG + >>> from paddle.vision.models.vgg import make_layers - vgg11_cfg = [64, 'M', 128, 'M', 256, 256, 'M', 512, 512, 'M', 512, 512, 'M'] + >>> vgg11_cfg = [64, 'M', 128, 'M', 256, 256, 'M', 512, 512, 'M', 512, 512, 'M'] - features = make_layers(vgg11_cfg) + >>> features = make_layers(vgg11_cfg) - vgg11 = VGG(features) + >>> vgg11 = VGG(features) - x = paddle.rand([1, 3, 224, 224]) - out = vgg11(x) + >>> x = paddle.rand([1, 3, 224, 224]) + >>> out = vgg11(x) - print(out.shape) - # [1, 1000] + >>> print(out.shape) + [1, 1000] """ def __init__(self, features, num_classes=1000, with_pool=True): @@ -212,20 +212,20 @@ def vgg11(pretrained=False, batch_norm=False, **kwargs): Examples: .. code-block:: python - import paddle - from paddle.vision.models import vgg11 + >>> import paddle + >>> from paddle.vision.models import vgg11 - # build model - model = vgg11() + >>> # build model + >>> model = vgg11() - # build vgg11 model with batch_norm - model = vgg11(batch_norm=True) + >>> # build vgg11 model with batch_norm + >>> model = vgg11(batch_norm=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] """ model_name = 'vgg11' if batch_norm: @@ -249,20 +249,20 @@ def vgg13(pretrained=False, batch_norm=False, **kwargs): Examples: .. code-block:: python - import paddle - from paddle.vision.models import vgg13 + >>> import paddle + >>> from paddle.vision.models import vgg13 - # build model - model = vgg13() + >>> # build model + >>> model = vgg13() - # build vgg13 model with batch_norm - model = vgg13(batch_norm=True) + >>> # build vgg13 model with batch_norm + >>> model = vgg13(batch_norm=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] """ model_name = 'vgg13' if batch_norm: @@ -286,20 +286,20 @@ def vgg16(pretrained=False, batch_norm=False, **kwargs): Examples: .. code-block:: python - import paddle - from paddle.vision.models import vgg16 + >>> import paddle + >>> from paddle.vision.models import vgg16 - # build model - model = vgg16() + >>> # build model + >>> model = vgg16() - # build vgg16 model with batch_norm - model = vgg16(batch_norm=True) + >>> # build vgg16 model with batch_norm + >>> model = vgg16(batch_norm=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] """ model_name = 'vgg16' if batch_norm: @@ -323,20 +323,20 @@ def vgg19(pretrained=False, batch_norm=False, **kwargs): Examples: .. code-block:: python - import paddle - from paddle.vision.models import vgg19 + >>> import paddle + >>> from paddle.vision.models import vgg19 - # build model - model = vgg19() + >>> # build model + >>> model = vgg19() - # build vgg19 model with batch_norm - model = vgg19(batch_norm=True) + >>> # build vgg19 model with batch_norm + >>> model = vgg19(batch_norm=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] """ model_name = 'vgg19' if batch_norm: diff --git a/python/paddle/vision/transforms/functional.py b/python/paddle/vision/transforms/functional.py index cde720e828383..cbdf23fc7db83 100644 --- a/python/paddle/vision/transforms/functional.py +++ b/python/paddle/vision/transforms/functional.py @@ -70,16 +70,17 @@ def to_tensor(pic, data_format='CHW'): Examples: .. code-block:: python - import numpy as np - from PIL import Image - from paddle.vision.transforms import functional as F + >>> import numpy as np + >>> from PIL import Image + >>> from paddle.vision.transforms import functional as F - fake_img = (np.random.rand(256, 300, 3) * 255.).astype('uint8') + >>> fake_img = (np.random.rand(256, 300, 3) * 255.).astype('uint8') - fake_img = Image.fromarray(fake_img) + >>> fake_img = Image.fromarray(fake_img) - tensor = F.to_tensor(fake_img) - print(tensor.shape) + >>> tensor = F.to_tensor(fake_img) + >>> print(tensor.shape) + [3, 256, 300] """ if not ( @@ -127,21 +128,21 @@ def resize(img, size, interpolation='bilinear'): Examples: .. code-block:: python - import numpy as np - from PIL import Image - from paddle.vision.transforms import functional as F + >>> import numpy as np + >>> from PIL import Image + >>> from paddle.vision.transforms import functional as F - fake_img = (np.random.rand(256, 300, 3) * 255.).astype('uint8') + >>> fake_img = (np.random.rand(256, 300, 3) * 255.).astype('uint8') - fake_img = Image.fromarray(fake_img) + >>> fake_img = Image.fromarray(fake_img) - converted_img = F.resize(fake_img, 224) - print(converted_img.size) - # (262, 224) + >>> converted_img = F.resize(fake_img, 224) + >>> print(converted_img.size) + (262, 224) - converted_img = F.resize(fake_img, (200, 150)) - print(converted_img.size) - # (150, 200) + >>> converted_img = F.resize(fake_img, (200, 150)) + >>> print(converted_img.size) + (150, 200) """ if not ( _is_pil_image(img) or _is_numpy_image(img) or _is_tensor_image(img) @@ -196,19 +197,21 @@ def pad(img, padding, fill=0, padding_mode='constant'): Examples: .. code-block:: python - import numpy as np - from PIL import Image - from paddle.vision.transforms import functional as F + >>> import numpy as np + >>> from PIL import Image + >>> from paddle.vision.transforms import functional as F - fake_img = (np.random.rand(256, 300, 3) * 255.).astype('uint8') + >>> fake_img = (np.random.rand(256, 300, 3) * 255.).astype('uint8') - fake_img = Image.fromarray(fake_img) + >>> fake_img = Image.fromarray(fake_img) - padded_img = F.pad(fake_img, padding=1) - print(padded_img.size) + >>> padded_img = F.pad(fake_img, padding=1) + >>> print(padded_img.size) + (302, 258) - padded_img = F.pad(fake_img, padding=(2, 1)) - print(padded_img.size) + >>> padded_img = F.pad(fake_img, padding=(2, 1)) + >>> print(padded_img.size) + (304, 258) """ if not ( _is_pil_image(img) or _is_numpy_image(img) or _is_tensor_image(img) @@ -244,16 +247,17 @@ def crop(img, top, left, height, width): Examples: .. code-block:: python - import numpy as np - from PIL import Image - from paddle.vision.transforms import functional as F + >>> import numpy as np + >>> from PIL import Image + >>> from paddle.vision.transforms import functional as F - fake_img = (np.random.rand(256, 300, 3) * 255.).astype('uint8') + >>> fake_img = (np.random.rand(256, 300, 3) * 255.).astype('uint8') - fake_img = Image.fromarray(fake_img) + >>> fake_img = Image.fromarray(fake_img) - cropped_img = F.crop(fake_img, 56, 150, 200, 100) - print(cropped_img.size) + >>> cropped_img = F.crop(fake_img, 56, 150, 200, 100) + >>> print(cropped_img.size) + (100, 200) """ if not ( @@ -287,16 +291,17 @@ def center_crop(img, output_size): Examples: .. code-block:: python - import numpy as np - from PIL import Image - from paddle.vision.transforms import functional as F + >>> import numpy as np + >>> from PIL import Image + >>> from paddle.vision.transforms import functional as F - fake_img = (np.random.rand(256, 300, 3) * 255.).astype('uint8') + >>> fake_img = (np.random.rand(256, 300, 3) * 255.).astype('uint8') - fake_img = Image.fromarray(fake_img) + >>> fake_img = Image.fromarray(fake_img) - cropped_img = F.center_crop(fake_img, (150, 100)) - print(cropped_img.size) + >>> cropped_img = F.center_crop(fake_img, (150, 100)) + >>> print(cropped_img.size) + (100, 150) """ if not ( _is_pil_image(img) or _is_numpy_image(img) or _is_tensor_image(img) @@ -327,16 +332,17 @@ def hflip(img): Examples: .. code-block:: python - import numpy as np - from PIL import Image - from paddle.vision.transforms import functional as F + >>> import numpy as np + >>> from PIL import Image + >>> from paddle.vision.transforms import functional as F - fake_img = (np.random.rand(256, 300, 3) * 255.).astype('uint8') + >>> fake_img = (np.random.rand(256, 300, 3) * 255.).astype('uint8') - fake_img = Image.fromarray(fake_img) + >>> fake_img = Image.fromarray(fake_img) - flpped_img = F.hflip(fake_img) - print(flpped_img.size) + >>> flpped_img = F.hflip(fake_img) + >>> print(flpped_img.size) + (300, 256) """ if not ( @@ -368,16 +374,17 @@ def vflip(img): Examples: .. code-block:: python - import numpy as np - from PIL import Image - from paddle.vision.transforms import functional as F + >>> import numpy as np + >>> from PIL import Image + >>> from paddle.vision.transforms import functional as F - fake_img = (np.random.rand(256, 300, 3) * 255.).astype('uint8') + >>> fake_img = (np.random.rand(256, 300, 3) * 255.).astype('uint8') - fake_img = Image.fromarray(fake_img) + >>> fake_img = Image.fromarray(fake_img) - flpped_img = F.vflip(fake_img) - print(flpped_img.size) + >>> flpped_img = F.vflip(fake_img) + >>> print(flpped_img.size) + (300, 256) """ if not ( @@ -411,20 +418,27 @@ def adjust_brightness(img, brightness_factor): Examples: .. code-block:: python - :name: code-example1 + :name: code-example1 - import numpy as np - from PIL import Image - from paddle.vision.transforms import functional as F + >>> import numpy as np + >>> from PIL import Image + >>> from paddle.vision.transforms import functional as F + >>> # doctest: +SKIP('random sample') - fake_img = (np.random.rand(256, 300, 3) * 255.).astype('uint8') + >>> fake_img = (np.random.rand(256, 300, 3) * 255.).astype('uint8') + >>> fake_img = Image.fromarray(fake_img) + + >>> print(fake_img.load()[1,1]) + (95, 127, 202) + >>> converted_img = F.adjust_brightness(fake_img, 0.5) + >>> print(converted_img.load()[1,1]) + (47, 63, 101) + >>> # doctest: -SKIP + >>> print(fake_img.size) + (300, 256) + >>> print(converted_img.size) + (300, 256) - fake_img = Image.fromarray(fake_img) - print(fake_img.size) # (300, 256) - print(fake_img.load()[1,1]) # (95, 127, 202) - converted_img = F.adjust_brightness(fake_img, 0.5) - print(converted_img.size) # (300, 256) - print(converted_img.load()[1,1]) # (47, 63, 101) """ @@ -460,16 +474,17 @@ def adjust_contrast(img, contrast_factor): Examples: .. code-block:: python - import numpy as np - from PIL import Image - from paddle.vision.transforms import functional as F + >>> import numpy as np + >>> from PIL import Image + >>> from paddle.vision.transforms import functional as F - fake_img = (np.random.rand(256, 300, 3) * 255.).astype('uint8') + >>> fake_img = (np.random.rand(256, 300, 3) * 255.).astype('uint8') - fake_img = Image.fromarray(fake_img) + >>> fake_img = Image.fromarray(fake_img) - converted_img = F.adjust_contrast(fake_img, 0.4) - print(converted_img.size) + >>> converted_img = F.adjust_contrast(fake_img, 0.4) + >>> print(converted_img.size) + (300, 256) """ if not ( _is_pil_image(img) or _is_numpy_image(img) or _is_tensor_image(img) @@ -503,16 +518,17 @@ def adjust_saturation(img, saturation_factor): Examples: .. code-block:: python - import numpy as np - from PIL import Image - from paddle.vision.transforms import functional as F + >>> import numpy as np + >>> from PIL import Image + >>> from paddle.vision.transforms import functional as F - fake_img = (np.random.rand(256, 300, 3) * 255.).astype('uint8') + >>> fake_img = (np.random.rand(256, 300, 3) * 255.).astype('uint8') - fake_img = Image.fromarray(fake_img) + >>> fake_img = Image.fromarray(fake_img) - converted_img = F.adjust_saturation(fake_img, 0.4) - print(converted_img.size) + >>> converted_img = F.adjust_saturation(fake_img, 0.4) + >>> print(converted_img.size) + (300, 256) """ if not ( @@ -556,16 +572,17 @@ def adjust_hue(img, hue_factor): Examples: .. code-block:: python - import numpy as np - from PIL import Image - from paddle.vision.transforms import functional as F + >>> import numpy as np + >>> from PIL import Image + >>> from paddle.vision.transforms import functional as F - fake_img = (np.random.rand(256, 300, 3) * 255.).astype('uint8') + >>> fake_img = (np.random.rand(256, 300, 3) * 255.).astype('uint8') - fake_img = Image.fromarray(fake_img) + >>> fake_img = Image.fromarray(fake_img) - converted_img = F.adjust_hue(fake_img, 0.4) - print(converted_img.size) + >>> converted_img = F.adjust_hue(fake_img, 0.4) + >>> print(converted_img.size) + (300, 256) """ if not ( @@ -657,13 +674,14 @@ def affine( Examples: .. code-block:: python - import paddle - from paddle.vision.transforms import functional as F + >>> import paddle + >>> from paddle.vision.transforms import functional as F - fake_img = paddle.randn((3, 256, 300)).astype(paddle.float32) + >>> fake_img = paddle.randn((3, 256, 300)).astype(paddle.float32) - affined_img = F.affine(fake_img, 45, translate=[0.2, 0.2], scale=0.5, shear=[-10, 10]) - print(affined_img.shape) + >>> affined_img = F.affine(fake_img, 45, translate=[0.2, 0.2], scale=0.5, shear=[-10, 10]) + >>> print(affined_img.shape) + [3, 256, 300] """ if not ( @@ -789,16 +807,17 @@ def rotate( Examples: .. code-block:: python - import numpy as np - from PIL import Image - from paddle.vision.transforms import functional as F + >>> import numpy as np + >>> from PIL import Image + >>> from paddle.vision.transforms import functional as F - fake_img = (np.random.rand(256, 300, 3) * 255.).astype('uint8') + >>> fake_img = (np.random.rand(256, 300, 3) * 255.).astype('uint8') - fake_img = Image.fromarray(fake_img) + >>> fake_img = Image.fromarray(fake_img) - rotated_img = F.rotate(fake_img, 90) - print(rotated_img.size) + >>> rotated_img = F.rotate(fake_img, 90) + >>> print(rotated_img.size) + (300, 256) """ if not ( @@ -897,16 +916,17 @@ def perspective(img, startpoints, endpoints, interpolation='nearest', fill=0): Examples: .. code-block:: python - import paddle - from paddle.vision.transforms import functional as F + >>> import paddle + >>> from paddle.vision.transforms import functional as F - fake_img = paddle.randn((3, 256, 300)).astype(paddle.float32) + >>> fake_img = paddle.randn((3, 256, 300)).astype(paddle.float32) - startpoints = [[0, 0], [33, 0], [33, 25], [0, 25]] - endpoints = [[3, 2], [32, 3], [30, 24], [2, 25]] + >>> startpoints = [[0, 0], [33, 0], [33, 25], [0, 25]] + >>> endpoints = [[3, 2], [32, 3], [30, 24], [2, 25]] - perspectived_img = F.perspective(fake_img, startpoints, endpoints) - print(perspectived_img.shape) + >>> perspectived_img = F.perspective(fake_img, startpoints, endpoints) + >>> print(perspectived_img.shape) + [3, 256, 300] """ if not ( @@ -946,16 +966,16 @@ def to_grayscale(img, num_output_channels=1): Examples: .. code-block:: python - import numpy as np - from PIL import Image - from paddle.vision.transforms import functional as F + >>> import numpy as np + >>> from PIL import Image + >>> from paddle.vision.transforms import functional as F - fake_img = (np.random.rand(256, 300, 3) * 255.).astype('uint8') + >>> fake_img = (np.random.rand(256, 300, 3) * 255.).astype('uint8') - fake_img = Image.fromarray(fake_img) + >>> fake_img = Image.fromarray(fake_img) - gray_img = F.to_grayscale(fake_img) - print(gray_img.size) + >>> gray_img = F.to_grayscale(fake_img) + >>> print(gray_img.size) """ if not ( @@ -993,19 +1013,20 @@ def normalize(img, mean, std, data_format='CHW', to_rgb=False): Examples: .. code-block:: python - import numpy as np - from PIL import Image - from paddle.vision.transforms import functional as F + >>> import numpy as np + >>> from PIL import Image + >>> from paddle.vision.transforms import functional as F - fake_img = (np.random.rand(256, 300, 3) * 255.).astype('uint8') + >>> fake_img = (np.random.rand(256, 300, 3) * 255.).astype('uint8') - fake_img = Image.fromarray(fake_img) + >>> fake_img = Image.fromarray(fake_img) - mean = [127.5, 127.5, 127.5] - std = [127.5, 127.5, 127.5] + >>> mean = [127.5, 127.5, 127.5] + >>> std = [127.5, 127.5, 127.5] - normalized_img = F.normalize(fake_img, mean, std, data_format='HWC') - print(normalized_img.max(), normalized_img.min()) + >>> normalized_img = F.normalize(fake_img, mean, std, data_format='HWC') + >>> print(normalized_img.max(), normalized_img.min()) + (300, 256) """ @@ -1039,35 +1060,33 @@ def erase(img, i, j, h, w, v, inplace=False): Examples: .. code-block:: python - import paddle - - fake_img = paddle.randn((3, 2, 4)).astype(paddle.float32) - print(fake_img) - - #Tensor(shape=[3, 2, 4], dtype=float32, place=Place(gpu:0), stop_gradient=True, - # [[[ 0.02169025, -0.97859967, -1.39175487, -1.07478464], - # [ 0.20654772, 1.74624777, 0.32268861, -0.13857445]], - # - # [[-0.14993843, 1.10793507, -0.40056887, -1.94395220], - # [ 0.41686651, 0.44551995, -0.09356714, -0.60898107]], - # - # [[-0.24998808, -1.47699273, -0.88838995, 0.42629015], - # [ 0.56948012, -0.96200180, 0.53355658, 3.20450878]]]) - - values = paddle.zeros((1,1,1), dtype=paddle.float32) - result = paddle.vision.transforms.erase(fake_img, 0, 1, 1, 2, values) - - print(result) - - #Tensor(shape=[3, 2, 4], dtype=float32, place=Place(gpu:0), stop_gradient=True, - # [[[ 0.02169025, 0. , 0. , -1.07478464], - # [ 0.20654772, 1.74624777, 0.32268861, -0.13857445]], - # - # [[-0.14993843, 0. , 0. , -1.94395220], - # [ 0.41686651, 0.44551995, -0.09356714, -0.60898107]], - # - # [[-0.24998808, 0. , 0. , 0.42629015], - # [ 0.56948012, -0.96200180, 0.53355658, 3.20450878]]]) + >>> import paddle + >>> # doctest: +SKIP('random sample') + >>> fake_img = paddle.randn((3, 2, 4)).astype(paddle.float32) + >>> print(fake_img) + + Tensor(shape=[3, 2, 4], dtype=float32, place=Place(gpu:0), stop_gradient=True, + [[[ 0.02169025, -0.97859967, -1.39175487, -1.07478464], + [ 0.20654772, 1.74624777, 0.32268861, -0.13857445]], + [[-0.14993843, 1.10793507, -0.40056887, -1.94395220], + [ 0.41686651, 0.44551995, -0.09356714, -0.60898107]], + [[-0.24998808, -1.47699273, -0.88838995, 0.42629015], + [ 0.56948012, -0.96200180, 0.53355658, 3.20450878]]]) + + >>> values = paddle.zeros((1,1,1), dtype=paddle.float32) + >>> result = paddle.vision.transforms.erase(fake_img, 0, 1, 1, 2, values) + + >>> print(result) + + Tensor(shape=[3, 2, 4], dtype=float32, place=Place(gpu:0), stop_gradient=True, + [[[ 0.02169025, 0. , 0. , -1.07478464], + [ 0.20654772, 1.74624777, 0.32268861, -0.13857445]], + + [[-0.14993843, 0. , 0. , -1.94395220], + [ 0.41686651, 0.44551995, -0.09356714, -0.60898107]], + + [[-0.24998808, 0. , 0. , 0.42629015], + [ 0.56948012, -0.96200180, 0.53355658, 3.20450878]]]) """ if _is_tensor_image(img): From f21ecd4a73918339cbbbc181bec6c2a7f373bd6b Mon Sep 17 00:00:00 2001 From: liyongchao911 <11_258@163.com> Date: Tue, 22 Aug 2023 11:44:32 +0800 Subject: [PATCH 2/5] update --- python/paddle/vision/models/squeezenet.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/python/paddle/vision/models/squeezenet.py b/python/paddle/vision/models/squeezenet.py index bca23cade983b..08cc1a6463324 100644 --- a/python/paddle/vision/models/squeezenet.py +++ b/python/paddle/vision/models/squeezenet.py @@ -103,7 +103,7 @@ class SqueezeNet(nn.Layer): >>> out = model(x) >>> print(out.shape) - # [1, 1000] + [1, 1000] """ def __init__(self, version, num_classes=1000, with_pool=True): @@ -246,7 +246,7 @@ def squeezenet1_0(pretrained=False, **kwargs): >>> out = model(x) >>> print(out.shape) - # [1, 1000] + [1, 1000] """ return _squeezenet('squeezenet1_0', '1.0', pretrained, **kwargs) @@ -280,6 +280,6 @@ def squeezenet1_1(pretrained=False, **kwargs): >>> out = model(x) >>> print(out.shape) - # [1, 1000] + [1, 1000] """ return _squeezenet('squeezenet1_1', '1.1', pretrained, **kwargs) From e5a2876f46ce788b67cc13531eaa1f16c2719c9a Mon Sep 17 00:00:00 2001 From: liyongchao911 <11_258@163.com> Date: Sun, 27 Aug 2023 10:54:19 +0800 Subject: [PATCH 3/5] update --- python/paddle/vision/transforms/functional.py | 62 +++++++++---------- 1 file changed, 30 insertions(+), 32 deletions(-) diff --git a/python/paddle/vision/transforms/functional.py b/python/paddle/vision/transforms/functional.py index cbdf23fc7db83..5f0b1aad5862c 100644 --- a/python/paddle/vision/transforms/functional.py +++ b/python/paddle/vision/transforms/functional.py @@ -340,8 +340,8 @@ def hflip(img): >>> fake_img = Image.fromarray(fake_img) - >>> flpped_img = F.hflip(fake_img) - >>> print(flpped_img.size) + >>> flipped_img = F.hflip(fake_img) + >>> print(flipped_img.size) (300, 256) """ @@ -382,8 +382,8 @@ def vflip(img): >>> fake_img = Image.fromarray(fake_img) - >>> flpped_img = F.vflip(fake_img) - >>> print(flpped_img.size) + >>> flipped_img = F.vflip(fake_img) + >>> print(flipped_img.size) (300, 256) """ @@ -423,21 +423,21 @@ def adjust_brightness(img, brightness_factor): >>> import numpy as np >>> from PIL import Image >>> from paddle.vision.transforms import functional as F - >>> # doctest: +SKIP('random sample') + >>> np.random.seed(2023) >>> fake_img = (np.random.rand(256, 300, 3) * 255.).astype('uint8') >>> fake_img = Image.fromarray(fake_img) - + >>> print(fake_img.size) + (300, 256) >>> print(fake_img.load()[1,1]) - (95, 127, 202) + (61, 155, 171) >>> converted_img = F.adjust_brightness(fake_img, 0.5) - >>> print(converted_img.load()[1,1]) - (47, 63, 101) - >>> # doctest: -SKIP - >>> print(fake_img.size) - (300, 256) >>> print(converted_img.size) (300, 256) + >>> print(converted_img.load()[1,1]) + (30, 77, 85) + + @@ -971,11 +971,10 @@ def to_grayscale(img, num_output_channels=1): >>> from paddle.vision.transforms import functional as F >>> fake_img = (np.random.rand(256, 300, 3) * 255.).astype('uint8') - >>> fake_img = Image.fromarray(fake_img) - >>> gray_img = F.to_grayscale(fake_img) >>> print(gray_img.size) + (300, 256) """ if not ( @@ -1026,7 +1025,7 @@ def normalize(img, mean, std, data_format='CHW', to_rgb=False): >>> normalized_img = F.normalize(fake_img, mean, std, data_format='HWC') >>> print(normalized_img.max(), normalized_img.min()) - (300, 256) + (0.99215686 -1.0) """ @@ -1061,32 +1060,31 @@ def erase(img, i, j, h, w, v, inplace=False): .. code-block:: python >>> import paddle - >>> # doctest: +SKIP('random sample') + >>> paddle.seed(2023) >>> fake_img = paddle.randn((3, 2, 4)).astype(paddle.float32) >>> print(fake_img) + Tensor(shape=[3, 2, 4], dtype=float32, place=Place(cpu), stop_gradient=True, + [[[ 0.06132207, 1.11349595, 0.41906244, -0.24858207], + [-1.85169315, -1.50370061, 1.73954511, 0.13331604]], - Tensor(shape=[3, 2, 4], dtype=float32, place=Place(gpu:0), stop_gradient=True, - [[[ 0.02169025, -0.97859967, -1.39175487, -1.07478464], - [ 0.20654772, 1.74624777, 0.32268861, -0.13857445]], - [[-0.14993843, 1.10793507, -0.40056887, -1.94395220], - [ 0.41686651, 0.44551995, -0.09356714, -0.60898107]], - [[-0.24998808, -1.47699273, -0.88838995, 0.42629015], - [ 0.56948012, -0.96200180, 0.53355658, 3.20450878]]]) + [[ 1.66359663, -0.55764782, -0.59911072, -0.57773495], + [-1.03176904, -0.33741450, -0.29695082, -1.50258386]], + + [[ 0.67233968, -1.07747352, 0.80170447, -0.06695852], + [-1.85003340, -0.23008066, 0.65083790, 0.75387722]]]) >>> values = paddle.zeros((1,1,1), dtype=paddle.float32) >>> result = paddle.vision.transforms.erase(fake_img, 0, 1, 1, 2, values) - >>> print(result) + Tensor(shape=[3, 2, 4], dtype=float32, place=Place(cpu), stop_gradient=True, + [[[ 0.06132207, 0. , 0. , -0.24858207], + [-1.85169315, -1.50370061, 1.73954511, 0.13331604]], - Tensor(shape=[3, 2, 4], dtype=float32, place=Place(gpu:0), stop_gradient=True, - [[[ 0.02169025, 0. , 0. , -1.07478464], - [ 0.20654772, 1.74624777, 0.32268861, -0.13857445]], - - [[-0.14993843, 0. , 0. , -1.94395220], - [ 0.41686651, 0.44551995, -0.09356714, -0.60898107]], + [[ 1.66359663, 0. , 0. , -0.57773495], + [-1.03176904, -0.33741450, -0.29695082, -1.50258386]], - [[-0.24998808, 0. , 0. , 0.42629015], - [ 0.56948012, -0.96200180, 0.53355658, 3.20450878]]]) + [[ 0.67233968, 0. , 0. , -0.06695852], + [-1.85003340, -0.23008066, 0.65083790, 0.75387722]]]) """ if _is_tensor_image(img): From fa4db29da7d82865393cd94ac3cfdde9122415bb Mon Sep 17 00:00:00 2001 From: liyongchao911 <11_258@163.com> Date: Tue, 29 Aug 2023 15:21:19 +0800 Subject: [PATCH 4/5] update --- python/paddle/vision/transforms/functional.py | 20 ++++++++----------- 1 file changed, 8 insertions(+), 12 deletions(-) diff --git a/python/paddle/vision/transforms/functional.py b/python/paddle/vision/transforms/functional.py index 5f0b1aad5862c..aa532173aad79 100644 --- a/python/paddle/vision/transforms/functional.py +++ b/python/paddle/vision/transforms/functional.py @@ -427,7 +427,7 @@ def adjust_brightness(img, brightness_factor): >>> fake_img = (np.random.rand(256, 300, 3) * 255.).astype('uint8') >>> fake_img = Image.fromarray(fake_img) - >>> print(fake_img.size) + >>> print(fake_img.size) (300, 256) >>> print(fake_img.load()[1,1]) (61, 155, 171) @@ -1025,7 +1025,7 @@ def normalize(img, mean, std, data_format='CHW', to_rgb=False): >>> normalized_img = F.normalize(fake_img, mean, std, data_format='HWC') >>> print(normalized_img.max(), normalized_img.min()) - (0.99215686 -1.0) + 0.99215686 -1.0 """ @@ -1065,26 +1065,22 @@ def erase(img, i, j, h, w, v, inplace=False): >>> print(fake_img) Tensor(shape=[3, 2, 4], dtype=float32, place=Place(cpu), stop_gradient=True, [[[ 0.06132207, 1.11349595, 0.41906244, -0.24858207], - [-1.85169315, -1.50370061, 1.73954511, 0.13331604]], - + [-1.85169315, -1.50370061, 1.73954511, 0.13331604]], [[ 1.66359663, -0.55764782, -0.59911072, -0.57773495], - [-1.03176904, -0.33741450, -0.29695082, -1.50258386]], - + [-1.03176904, -0.33741450, -0.29695082, -1.50258386]], [[ 0.67233968, -1.07747352, 0.80170447, -0.06695852], - [-1.85003340, -0.23008066, 0.65083790, 0.75387722]]]) + [-1.85003340, -0.23008066, 0.65083790, 0.75387722]]]) >>> values = paddle.zeros((1,1,1), dtype=paddle.float32) >>> result = paddle.vision.transforms.erase(fake_img, 0, 1, 1, 2, values) >>> print(result) Tensor(shape=[3, 2, 4], dtype=float32, place=Place(cpu), stop_gradient=True, [[[ 0.06132207, 0. , 0. , -0.24858207], - [-1.85169315, -1.50370061, 1.73954511, 0.13331604]], - + [-1.85169315, -1.50370061, 1.73954511, 0.13331604]], [[ 1.66359663, 0. , 0. , -0.57773495], - [-1.03176904, -0.33741450, -0.29695082, -1.50258386]], - + [-1.03176904, -0.33741450, -0.29695082, -1.50258386]], [[ 0.67233968, 0. , 0. , -0.06695852], - [-1.85003340, -0.23008066, 0.65083790, 0.75387722]]]) + [-1.85003340, -0.23008066, 0.65083790, 0.75387722]]]) """ if _is_tensor_image(img): From 89351d96dd21019c888b0fbe81d4295194db9f10 Mon Sep 17 00:00:00 2001 From: liyongchao911 <11_258@163.com> Date: Thu, 31 Aug 2023 11:32:29 +0800 Subject: [PATCH 5/5] udpate --- python/paddle/vision/transforms/functional.py | 44 ------------------- 1 file changed, 44 deletions(-) diff --git a/python/paddle/vision/transforms/functional.py b/python/paddle/vision/transforms/functional.py index aa532173aad79..40a708da5b1f6 100644 --- a/python/paddle/vision/transforms/functional.py +++ b/python/paddle/vision/transforms/functional.py @@ -73,11 +73,8 @@ def to_tensor(pic, data_format='CHW'): >>> import numpy as np >>> from PIL import Image >>> from paddle.vision.transforms import functional as F - >>> fake_img = (np.random.rand(256, 300, 3) * 255.).astype('uint8') - >>> fake_img = Image.fromarray(fake_img) - >>> tensor = F.to_tensor(fake_img) >>> print(tensor.shape) [3, 256, 300] @@ -131,11 +128,8 @@ def resize(img, size, interpolation='bilinear'): >>> import numpy as np >>> from PIL import Image >>> from paddle.vision.transforms import functional as F - >>> fake_img = (np.random.rand(256, 300, 3) * 255.).astype('uint8') - >>> fake_img = Image.fromarray(fake_img) - >>> converted_img = F.resize(fake_img, 224) >>> print(converted_img.size) (262, 224) @@ -200,11 +194,8 @@ def pad(img, padding, fill=0, padding_mode='constant'): >>> import numpy as np >>> from PIL import Image >>> from paddle.vision.transforms import functional as F - >>> fake_img = (np.random.rand(256, 300, 3) * 255.).astype('uint8') - >>> fake_img = Image.fromarray(fake_img) - >>> padded_img = F.pad(fake_img, padding=1) >>> print(padded_img.size) (302, 258) @@ -250,11 +241,8 @@ def crop(img, top, left, height, width): >>> import numpy as np >>> from PIL import Image >>> from paddle.vision.transforms import functional as F - >>> fake_img = (np.random.rand(256, 300, 3) * 255.).astype('uint8') - >>> fake_img = Image.fromarray(fake_img) - >>> cropped_img = F.crop(fake_img, 56, 150, 200, 100) >>> print(cropped_img.size) (100, 200) @@ -294,11 +282,8 @@ def center_crop(img, output_size): >>> import numpy as np >>> from PIL import Image >>> from paddle.vision.transforms import functional as F - >>> fake_img = (np.random.rand(256, 300, 3) * 255.).astype('uint8') - >>> fake_img = Image.fromarray(fake_img) - >>> cropped_img = F.center_crop(fake_img, (150, 100)) >>> print(cropped_img.size) (100, 150) @@ -335,11 +320,8 @@ def hflip(img): >>> import numpy as np >>> from PIL import Image >>> from paddle.vision.transforms import functional as F - >>> fake_img = (np.random.rand(256, 300, 3) * 255.).astype('uint8') - >>> fake_img = Image.fromarray(fake_img) - >>> flipped_img = F.hflip(fake_img) >>> print(flipped_img.size) (300, 256) @@ -377,11 +359,8 @@ def vflip(img): >>> import numpy as np >>> from PIL import Image >>> from paddle.vision.transforms import functional as F - >>> fake_img = (np.random.rand(256, 300, 3) * 255.).astype('uint8') - >>> fake_img = Image.fromarray(fake_img) - >>> flipped_img = F.vflip(fake_img) >>> print(flipped_img.size) (300, 256) @@ -424,7 +403,6 @@ def adjust_brightness(img, brightness_factor): >>> from PIL import Image >>> from paddle.vision.transforms import functional as F >>> np.random.seed(2023) - >>> fake_img = (np.random.rand(256, 300, 3) * 255.).astype('uint8') >>> fake_img = Image.fromarray(fake_img) >>> print(fake_img.size) @@ -477,11 +455,8 @@ def adjust_contrast(img, contrast_factor): >>> import numpy as np >>> from PIL import Image >>> from paddle.vision.transforms import functional as F - >>> fake_img = (np.random.rand(256, 300, 3) * 255.).astype('uint8') - >>> fake_img = Image.fromarray(fake_img) - >>> converted_img = F.adjust_contrast(fake_img, 0.4) >>> print(converted_img.size) (300, 256) @@ -521,11 +496,8 @@ def adjust_saturation(img, saturation_factor): >>> import numpy as np >>> from PIL import Image >>> from paddle.vision.transforms import functional as F - >>> fake_img = (np.random.rand(256, 300, 3) * 255.).astype('uint8') - >>> fake_img = Image.fromarray(fake_img) - >>> converted_img = F.adjust_saturation(fake_img, 0.4) >>> print(converted_img.size) (300, 256) @@ -575,11 +547,8 @@ def adjust_hue(img, hue_factor): >>> import numpy as np >>> from PIL import Image >>> from paddle.vision.transforms import functional as F - >>> fake_img = (np.random.rand(256, 300, 3) * 255.).astype('uint8') - >>> fake_img = Image.fromarray(fake_img) - >>> converted_img = F.adjust_hue(fake_img, 0.4) >>> print(converted_img.size) (300, 256) @@ -676,9 +645,7 @@ def affine( >>> import paddle >>> from paddle.vision.transforms import functional as F - >>> fake_img = paddle.randn((3, 256, 300)).astype(paddle.float32) - >>> affined_img = F.affine(fake_img, 45, translate=[0.2, 0.2], scale=0.5, shear=[-10, 10]) >>> print(affined_img.shape) [3, 256, 300] @@ -810,11 +777,8 @@ def rotate( >>> import numpy as np >>> from PIL import Image >>> from paddle.vision.transforms import functional as F - >>> fake_img = (np.random.rand(256, 300, 3) * 255.).astype('uint8') - >>> fake_img = Image.fromarray(fake_img) - >>> rotated_img = F.rotate(fake_img, 90) >>> print(rotated_img.size) (300, 256) @@ -918,12 +882,9 @@ def perspective(img, startpoints, endpoints, interpolation='nearest', fill=0): >>> import paddle >>> from paddle.vision.transforms import functional as F - >>> fake_img = paddle.randn((3, 256, 300)).astype(paddle.float32) - >>> startpoints = [[0, 0], [33, 0], [33, 25], [0, 25]] >>> endpoints = [[3, 2], [32, 3], [30, 24], [2, 25]] - >>> perspectived_img = F.perspective(fake_img, startpoints, endpoints) >>> print(perspectived_img.shape) [3, 256, 300] @@ -969,7 +930,6 @@ def to_grayscale(img, num_output_channels=1): >>> import numpy as np >>> from PIL import Image >>> from paddle.vision.transforms import functional as F - >>> fake_img = (np.random.rand(256, 300, 3) * 255.).astype('uint8') >>> fake_img = Image.fromarray(fake_img) >>> gray_img = F.to_grayscale(fake_img) @@ -1015,14 +975,10 @@ def normalize(img, mean, std, data_format='CHW', to_rgb=False): >>> import numpy as np >>> from PIL import Image >>> from paddle.vision.transforms import functional as F - >>> fake_img = (np.random.rand(256, 300, 3) * 255.).astype('uint8') - >>> fake_img = Image.fromarray(fake_img) - >>> mean = [127.5, 127.5, 127.5] >>> std = [127.5, 127.5, 127.5] - >>> normalized_img = F.normalize(fake_img, mean, std, data_format='HWC') >>> print(normalized_img.max(), normalized_img.min()) 0.99215686 -1.0