Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
Paddle
提交
a277fe4d
P
Paddle
项目概览
PaddlePaddle
/
Paddle
大约 2 年 前同步成功
通知
2325
Star
20933
Fork
5424
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
1423
列表
看板
标记
里程碑
合并请求
543
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
P
Paddle
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
1,423
Issue
1,423
列表
看板
标记
里程碑
合并请求
543
合并请求
543
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
未验证
提交
a277fe4d
编写于
9月 01, 2023
作者:
D
David Nicolas
提交者:
GitHub
9月 01, 2023
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
[Doctest]fix No.163,164,166, test=docs_preview (#56527)
上级
0213a19c
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
247 addition
and
278 deletion
+247
-278
python/paddle/vision/models/squeezenet.py
python/paddle/vision/models/squeezenet.py
+30
-30
python/paddle/vision/models/vgg.py
python/paddle/vision/models/vgg.py
+50
-50
python/paddle/vision/transforms/functional.py
python/paddle/vision/transforms/functional.py
+167
-198
未找到文件。
python/paddle/vision/models/squeezenet.py
浏览文件 @
a277fe4d
...
@@ -90,20 +90,20 @@ class SqueezeNet(nn.Layer):
...
@@ -90,20 +90,20 @@ class SqueezeNet(nn.Layer):
Examples:
Examples:
.. code-block:: python
.. code-block:: python
import paddle
>>>
import paddle
from paddle.vision.models import SqueezeNet
>>>
from paddle.vision.models import SqueezeNet
# build v1.0 model
>>>
# build v1.0 model
model = SqueezeNet(version='1.0')
>>>
model = SqueezeNet(version='1.0')
# build v1.1 model
>>>
# build v1.1 model
# model = SqueezeNet(version='1.1')
>>>
# model = SqueezeNet(version='1.1')
x = paddle.rand([1, 3, 224, 224])
>>>
x = paddle.rand([1, 3, 224, 224])
out = model(x)
>>>
out = model(x)
print(out.shape)
>>>
print(out.shape)
#
[1, 1000]
[1, 1000]
"""
"""
def
__init__
(
self
,
version
,
num_classes
=
1000
,
with_pool
=
True
):
def
__init__
(
self
,
version
,
num_classes
=
1000
,
with_pool
=
True
):
...
@@ -233,20 +233,20 @@ def squeezenet1_0(pretrained=False, **kwargs):
...
@@ -233,20 +233,20 @@ def squeezenet1_0(pretrained=False, **kwargs):
Examples:
Examples:
.. code-block:: python
.. code-block:: python
import paddle
>>>
import paddle
from paddle.vision.models import squeezenet1_0
>>>
from paddle.vision.models import squeezenet1_0
# build model
>>>
# build model
model = squeezenet1_0()
>>>
model = squeezenet1_0()
# 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])
>>>
x = paddle.rand([1, 3, 224, 224])
out = model(x)
>>>
out = model(x)
print(out.shape)
>>>
print(out.shape)
#
[1, 1000]
[1, 1000]
"""
"""
return
_squeezenet
(
'squeezenet1_0'
,
'1.0'
,
pretrained
,
**
kwargs
)
return
_squeezenet
(
'squeezenet1_0'
,
'1.0'
,
pretrained
,
**
kwargs
)
...
@@ -267,19 +267,19 @@ def squeezenet1_1(pretrained=False, **kwargs):
...
@@ -267,19 +267,19 @@ def squeezenet1_1(pretrained=False, **kwargs):
Examples:
Examples:
.. code-block:: python
.. code-block:: python
import paddle
>>>
import paddle
from paddle.vision.models import squeezenet1_1
>>>
from paddle.vision.models import squeezenet1_1
# build model
>>>
# build model
model = squeezenet1_1()
>>>
model = squeezenet1_1()
# 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])
>>>
x = paddle.rand([1, 3, 224, 224])
out = model(x)
>>>
out = model(x)
print(out.shape)
>>>
print(out.shape)
#
[1, 1000]
[1, 1000]
"""
"""
return
_squeezenet
(
'squeezenet1_1'
,
'1.1'
,
pretrained
,
**
kwargs
)
return
_squeezenet
(
'squeezenet1_1'
,
'1.1'
,
pretrained
,
**
kwargs
)
python/paddle/vision/models/vgg.py
浏览文件 @
a277fe4d
...
@@ -46,21 +46,21 @@ class VGG(nn.Layer):
...
@@ -46,21 +46,21 @@ class VGG(nn.Layer):
Examples:
Examples:
.. code-block:: python
.. code-block:: python
import paddle
>>>
import paddle
from paddle.vision.models import VGG
>>>
from paddle.vision.models import VGG
from paddle.vision.models.vgg import make_layers
>>>
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])
>>>
x = paddle.rand([1, 3, 224, 224])
out = vgg11(x)
>>>
out = vgg11(x)
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
):
...
@@ -212,20 +212,20 @@ def vgg11(pretrained=False, batch_norm=False, **kwargs):
...
@@ -212,20 +212,20 @@ def vgg11(pretrained=False, batch_norm=False, **kwargs):
Examples:
Examples:
.. code-block:: python
.. code-block:: python
import paddle
>>>
import paddle
from paddle.vision.models import vgg11
>>>
from paddle.vision.models import vgg11
# build model
>>>
# build model
model = vgg11()
>>>
model = vgg11()
# 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])
>>>
x = paddle.rand([1, 3, 224, 224])
out = model(x)
>>>
out = model(x)
print(out.shape)
>>>
print(out.shape)
#
[1, 1000]
[1, 1000]
"""
"""
model_name
=
'vgg11'
model_name
=
'vgg11'
if
batch_norm
:
if
batch_norm
:
...
@@ -249,20 +249,20 @@ def vgg13(pretrained=False, batch_norm=False, **kwargs):
...
@@ -249,20 +249,20 @@ def vgg13(pretrained=False, batch_norm=False, **kwargs):
Examples:
Examples:
.. code-block:: python
.. code-block:: python
import paddle
>>>
import paddle
from paddle.vision.models import vgg13
>>>
from paddle.vision.models import vgg13
# build model
>>>
# build model
model = vgg13()
>>>
model = vgg13()
# 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])
>>>
x = paddle.rand([1, 3, 224, 224])
out = model(x)
>>>
out = model(x)
print(out.shape)
>>>
print(out.shape)
#
[1, 1000]
[1, 1000]
"""
"""
model_name
=
'vgg13'
model_name
=
'vgg13'
if
batch_norm
:
if
batch_norm
:
...
@@ -286,20 +286,20 @@ def vgg16(pretrained=False, batch_norm=False, **kwargs):
...
@@ -286,20 +286,20 @@ def vgg16(pretrained=False, batch_norm=False, **kwargs):
Examples:
Examples:
.. code-block:: python
.. code-block:: python
import paddle
>>>
import paddle
from paddle.vision.models import vgg16
>>>
from paddle.vision.models import vgg16
# build model
>>>
# build model
model = vgg16()
>>>
model = vgg16()
# 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])
>>>
x = paddle.rand([1, 3, 224, 224])
out = model(x)
>>>
out = model(x)
print(out.shape)
>>>
print(out.shape)
#
[1, 1000]
[1, 1000]
"""
"""
model_name
=
'vgg16'
model_name
=
'vgg16'
if
batch_norm
:
if
batch_norm
:
...
@@ -323,20 +323,20 @@ def vgg19(pretrained=False, batch_norm=False, **kwargs):
...
@@ -323,20 +323,20 @@ def vgg19(pretrained=False, batch_norm=False, **kwargs):
Examples:
Examples:
.. code-block:: python
.. code-block:: python
import paddle
>>>
import paddle
from paddle.vision.models import vgg19
>>>
from paddle.vision.models import vgg19
# build model
>>>
# build model
model = vgg19()
>>>
model = vgg19()
# 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])
>>>
x = paddle.rand([1, 3, 224, 224])
out = model(x)
>>>
out = model(x)
print(out.shape)
>>>
print(out.shape)
#
[1, 1000]
[1, 1000]
"""
"""
model_name
=
'vgg19'
model_name
=
'vgg19'
if
batch_norm
:
if
batch_norm
:
...
...
python/paddle/vision/transforms/functional.py
浏览文件 @
a277fe4d
...
@@ -70,16 +70,14 @@ def to_tensor(pic, data_format='CHW'):
...
@@ -70,16 +70,14 @@ def to_tensor(pic, data_format='CHW'):
Examples:
Examples:
.. code-block:: python
.. code-block:: python
import numpy as np
>>> import numpy as np
from PIL import Image
>>> from PIL import Image
from paddle.vision.transforms import functional as F
>>> 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)
>>> tensor = F.to_tensor(fake_img)
fake_img = Image.fromarray(fake_img)
>>> print(tensor.shape)
[3, 256, 300]
tensor = F.to_tensor(fake_img)
print(tensor.shape)
"""
"""
if
not
(
if
not
(
...
@@ -127,21 +125,18 @@ def resize(img, size, interpolation='bilinear'):
...
@@ -127,21 +125,18 @@ def resize(img, size, interpolation='bilinear'):
Examples:
Examples:
.. code-block:: python
.. code-block:: python
import numpy as np
>>> import numpy as np
from PIL import Image
>>> from PIL import Image
from paddle.vision.transforms import functional as F
>>> 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)
>>> converted_img = F.resize(fake_img, 224)
fake_img = Image.fromarray(fake_img)
>>> print(converted_img.size)
(262, 224)
converted_img = F.resize(fake_img, 224)
print(converted_img.size)
>>> converted_img = F.resize(fake_img, (200, 150))
# (262, 224)
>>> print(converted_img.size)
(150, 200)
converted_img = F.resize(fake_img, (200, 150))
print(converted_img.size)
# (150, 200)
"""
"""
if
not
(
if
not
(
_is_pil_image
(
img
)
or
_is_numpy_image
(
img
)
or
_is_tensor_image
(
img
)
_is_pil_image
(
img
)
or
_is_numpy_image
(
img
)
or
_is_tensor_image
(
img
)
...
@@ -196,19 +191,18 @@ def pad(img, padding, fill=0, padding_mode='constant'):
...
@@ -196,19 +191,18 @@ def pad(img, padding, fill=0, padding_mode='constant'):
Examples:
Examples:
.. code-block:: python
.. code-block:: python
import numpy as np
>>> import numpy as np
from PIL import Image
>>> from PIL import Image
from paddle.vision.transforms import functional as F
>>> 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)
>>> padded_img = F.pad(fake_img, padding=1)
fake_img = Image.fromarray(fake_img)
>>> print(padded_img.size)
(302, 258)
padded_img = F.pad(fake_img, padding=1)
print(padded_img.size)
>>> padded_img = F.pad(fake_img, padding=(2, 1))
>>> print(padded_img.size)
padded_img = F.pad(fake_img, padding=(2, 1))
(304, 258)
print(padded_img.size)
"""
"""
if
not
(
if
not
(
_is_pil_image
(
img
)
or
_is_numpy_image
(
img
)
or
_is_tensor_image
(
img
)
_is_pil_image
(
img
)
or
_is_numpy_image
(
img
)
or
_is_tensor_image
(
img
)
...
@@ -244,16 +238,14 @@ def crop(img, top, left, height, width):
...
@@ -244,16 +238,14 @@ def crop(img, top, left, height, width):
Examples:
Examples:
.. code-block:: python
.. code-block:: python
import numpy as np
>>> import numpy as np
from PIL import Image
>>> from PIL import Image
from paddle.vision.transforms import functional as F
>>> 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)
>>> cropped_img = F.crop(fake_img, 56, 150, 200, 100)
fake_img = Image.fromarray(fake_img)
>>> print(cropped_img.size)
(100, 200)
cropped_img = F.crop(fake_img, 56, 150, 200, 100)
print(cropped_img.size)
"""
"""
if
not
(
if
not
(
...
@@ -287,16 +279,14 @@ def center_crop(img, output_size):
...
@@ -287,16 +279,14 @@ def center_crop(img, output_size):
Examples:
Examples:
.. code-block:: python
.. code-block:: python
import numpy as np
>>> import numpy as np
from PIL import Image
>>> from PIL import Image
from paddle.vision.transforms import functional as F
>>> 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)
>>> cropped_img = F.center_crop(fake_img, (150, 100))
fake_img = Image.fromarray(fake_img)
>>> print(cropped_img.size)
(100, 150)
cropped_img = F.center_crop(fake_img, (150, 100))
print(cropped_img.size)
"""
"""
if
not
(
if
not
(
_is_pil_image
(
img
)
or
_is_numpy_image
(
img
)
or
_is_tensor_image
(
img
)
_is_pil_image
(
img
)
or
_is_numpy_image
(
img
)
or
_is_tensor_image
(
img
)
...
@@ -327,16 +317,14 @@ def hflip(img):
...
@@ -327,16 +317,14 @@ def hflip(img):
Examples:
Examples:
.. code-block:: python
.. code-block:: python
import numpy as np
>>> import numpy as np
from PIL import Image
>>> from PIL import Image
from paddle.vision.transforms import functional as F
>>> 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)
>>> flipped_img = F.hflip(fake_img)
fake_img = Image.fromarray(fake_img)
>>> print(flipped_img.size)
(300, 256)
flpped_img = F.hflip(fake_img)
print(flpped_img.size)
"""
"""
if
not
(
if
not
(
...
@@ -368,16 +356,14 @@ def vflip(img):
...
@@ -368,16 +356,14 @@ def vflip(img):
Examples:
Examples:
.. code-block:: python
.. code-block:: python
import numpy as np
>>> import numpy as np
from PIL import Image
>>> from PIL import Image
from paddle.vision.transforms import functional as F
>>> 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)
>>> flipped_img = F.vflip(fake_img)
fake_img = Image.fromarray(fake_img)
>>> print(flipped_img.size)
(300, 256)
flpped_img = F.vflip(fake_img)
print(flpped_img.size)
"""
"""
if
not
(
if
not
(
...
@@ -411,20 +397,26 @@ def adjust_brightness(img, brightness_factor):
...
@@ -411,20 +397,26 @@ def adjust_brightness(img, brightness_factor):
Examples:
Examples:
.. code-block:: python
.. 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
>>> 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])
(61, 155, 171)
>>> converted_img = F.adjust_brightness(fake_img, 0.5)
>>> print(converted_img.size)
(300, 256)
>>> print(converted_img.load()[1,1])
(30, 77, 85)
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)
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 +452,14 @@ def adjust_contrast(img, contrast_factor):
...
@@ -460,16 +452,14 @@ def adjust_contrast(img, contrast_factor):
Examples:
Examples:
.. code-block:: python
.. code-block:: python
import numpy as np
>>> import numpy as np
from PIL import Image
>>> from PIL import Image
from paddle.vision.transforms import functional as F
>>> 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)
>>> converted_img = F.adjust_contrast(fake_img, 0.4)
fake_img = Image.fromarray(fake_img)
>>> print(converted_img.size)
(300, 256)
converted_img = F.adjust_contrast(fake_img, 0.4)
print(converted_img.size)
"""
"""
if
not
(
if
not
(
_is_pil_image
(
img
)
or
_is_numpy_image
(
img
)
or
_is_tensor_image
(
img
)
_is_pil_image
(
img
)
or
_is_numpy_image
(
img
)
or
_is_tensor_image
(
img
)
...
@@ -503,16 +493,14 @@ def adjust_saturation(img, saturation_factor):
...
@@ -503,16 +493,14 @@ def adjust_saturation(img, saturation_factor):
Examples:
Examples:
.. code-block:: python
.. code-block:: python
import numpy as np
>>> import numpy as np
from PIL import Image
>>> from PIL import Image
from paddle.vision.transforms import functional as F
>>> 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)
>>> converted_img = F.adjust_saturation(fake_img, 0.4)
fake_img = Image.fromarray(fake_img)
>>> print(converted_img.size)
(300, 256)
converted_img = F.adjust_saturation(fake_img, 0.4)
print(converted_img.size)
"""
"""
if
not
(
if
not
(
...
@@ -556,16 +544,14 @@ def adjust_hue(img, hue_factor):
...
@@ -556,16 +544,14 @@ def adjust_hue(img, hue_factor):
Examples:
Examples:
.. code-block:: python
.. code-block:: python
import numpy as np
>>> import numpy as np
from PIL import Image
>>> from PIL import Image
from paddle.vision.transforms import functional as F
>>> 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)
>>> converted_img = F.adjust_hue(fake_img, 0.4)
fake_img = Image.fromarray(fake_img)
>>> print(converted_img.size)
(300, 256)
converted_img = F.adjust_hue(fake_img, 0.4)
print(converted_img.size)
"""
"""
if
not
(
if
not
(
...
@@ -657,13 +643,12 @@ def affine(
...
@@ -657,13 +643,12 @@ def affine(
Examples:
Examples:
.. code-block:: python
.. code-block:: python
import paddle
>>> import paddle
from paddle.vision.transforms import functional as F
>>> 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])
[3, 256, 300]
print(affined_img.shape)
"""
"""
if
not
(
if
not
(
...
@@ -789,16 +774,14 @@ def rotate(
...
@@ -789,16 +774,14 @@ def rotate(
Examples:
Examples:
.. code-block:: python
.. code-block:: python
import numpy as np
>>> import numpy as np
from PIL import Image
>>> from PIL import Image
from paddle.vision.transforms import functional as F
>>> 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)
>>> rotated_img = F.rotate(fake_img, 90)
fake_img = Image.fromarray(fake_img)
>>> print(rotated_img.size)
(300, 256)
rotated_img = F.rotate(fake_img, 90)
print(rotated_img.size)
"""
"""
if
not
(
if
not
(
...
@@ -897,16 +880,14 @@ def perspective(img, startpoints, endpoints, interpolation='nearest', fill=0):
...
@@ -897,16 +880,14 @@ def perspective(img, startpoints, endpoints, interpolation='nearest', fill=0):
Examples:
Examples:
.. code-block:: python
.. code-block:: python
import paddle
>>> import paddle
from paddle.vision.transforms import functional as F
>>> 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]]
>>> perspectived_img = F.perspective(fake_img, startpoints, endpoints)
endpoints = [[3, 2], [32, 3], [30, 24], [2, 25]]
>>> print(perspectived_img.shape)
[3, 256, 300]
perspectived_img = F.perspective(fake_img, startpoints, endpoints)
print(perspectived_img.shape)
"""
"""
if
not
(
if
not
(
...
@@ -946,16 +927,14 @@ def to_grayscale(img, num_output_channels=1):
...
@@ -946,16 +927,14 @@ def to_grayscale(img, num_output_channels=1):
Examples:
Examples:
.. code-block:: python
.. code-block:: python
import numpy as np
>>> import numpy as np
from PIL import Image
>>> from PIL import Image
from paddle.vision.transforms import functional as F
>>> 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)
>>> gray_img = F.to_grayscale(fake_img)
fake_img = Image.fromarray(fake_img)
>>> print(gray_img.size)
(300, 256)
gray_img = F.to_grayscale(fake_img)
print(gray_img.size)
"""
"""
if
not
(
if
not
(
...
@@ -993,19 +972,16 @@ def normalize(img, mean, std, data_format='CHW', to_rgb=False):
...
@@ -993,19 +972,16 @@ def normalize(img, mean, std, data_format='CHW', to_rgb=False):
Examples:
Examples:
.. code-block:: python
.. code-block:: python
import numpy as np
>>> import numpy as np
from PIL import Image
>>> from PIL import Image
from paddle.vision.transforms import functional as F
>>> 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)
>>> mean = [127.5, 127.5, 127.5]
fake_img = Image.fromarray(fake_img)
>>> std = [127.5, 127.5, 127.5]
>>> normalized_img = F.normalize(fake_img, mean, std, data_format='HWC')
mean = [127.5, 127.5, 127.5]
>>> print(normalized_img.max(), normalized_img.min())
std = [127.5, 127.5, 127.5]
0.99215686 -1.0
normalized_img = F.normalize(fake_img, mean, std, data_format='HWC')
print(normalized_img.max(), normalized_img.min())
"""
"""
...
@@ -1039,35 +1015,28 @@ def erase(img, i, j, h, w, v, inplace=False):
...
@@ -1039,35 +1015,28 @@ def erase(img, i, j, h, w, v, inplace=False):
Examples:
Examples:
.. code-block:: python
.. code-block:: python
import paddle
>>> import paddle
>>> paddle.seed(2023)
fake_img = paddle.randn((3, 2, 4)).astype(paddle.float32)
>>> fake_img = paddle.randn((3, 2, 4)).astype(paddle.float32)
print(fake_img)
>>> print(fake_img)
Tensor(shape=[3, 2, 4], dtype=float32, place=Place(cpu), stop_gradient=True,
#Tensor(shape=[3, 2, 4], dtype=float32, place=Place(gpu:0), stop_gradient=True,
[[[ 0.06132207, 1.11349595, 0.41906244, -0.24858207],
# [[[ 0.02169025, -0.97859967, -1.39175487, -1.07478464],
[-1.85169315, -1.50370061, 1.73954511, 0.13331604]],
# [ 0.20654772, 1.74624777, 0.32268861, -0.13857445]],
[[ 1.66359663, -0.55764782, -0.59911072, -0.57773495],
#
[-1.03176904, -0.33741450, -0.29695082, -1.50258386]],
# [[-0.14993843, 1.10793507, -0.40056887, -1.94395220],
[[ 0.67233968, -1.07747352, 0.80170447, -0.06695852],
# [ 0.41686651, 0.44551995, -0.09356714, -0.60898107]],
[-1.85003340, -0.23008066, 0.65083790, 0.75387722]]])
#
# [[-0.24998808, -1.47699273, -0.88838995, 0.42629015],
>>> values = paddle.zeros((1,1,1), dtype=paddle.float32)
# [ 0.56948012, -0.96200180, 0.53355658, 3.20450878]]])
>>> result = paddle.vision.transforms.erase(fake_img, 0, 1, 1, 2, values)
>>> print(result)
values = paddle.zeros((1,1,1), dtype=paddle.float32)
Tensor(shape=[3, 2, 4], dtype=float32, place=Place(cpu), stop_gradient=True,
result = paddle.vision.transforms.erase(fake_img, 0, 1, 1, 2, values)
[[[ 0.06132207, 0. , 0. , -0.24858207],
[-1.85169315, -1.50370061, 1.73954511, 0.13331604]],
print(result)
[[ 1.66359663, 0. , 0. , -0.57773495],
[-1.03176904, -0.33741450, -0.29695082, -1.50258386]],
#Tensor(shape=[3, 2, 4], dtype=float32, place=Place(gpu:0), stop_gradient=True,
[[ 0.67233968, 0. , 0. , -0.06695852],
# [[[ 0.02169025, 0. , 0. , -1.07478464],
[-1.85003340, -0.23008066, 0.65083790, 0.75387722]]])
# [ 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
):
if
_is_tensor_image
(
img
):
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录