Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
Paddle
提交
a277fe4d
P
Paddle
项目概览
PaddlePaddle
/
Paddle
1 年多 前同步成功
通知
2302
Star
20931
Fork
5422
代码
文件
提交
分支
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):
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)
#
[1, 1000]
>>>
print(out.shape)
[1, 1000]
"""
def
__init__
(
self
,
version
,
num_classes
=
1000
,
with_pool
=
True
):
...
...
@@ -233,20 +233,20 @@ 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)
#
[1, 1000]
>>>
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)
#
[1, 1000]
>>>
print(out.shape)
[1, 1000]
"""
return
_squeezenet
(
'squeezenet1_1'
,
'1.1'
,
pretrained
,
**
kwargs
)
python/paddle/vision/models/vgg.py
浏览文件 @
a277fe4d
...
...
@@ -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
:
...
...
python/paddle/vision/transforms/functional.py
浏览文件 @
a277fe4d
...
...
@@ -70,16 +70,14 @@ 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
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)
>>> 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]
"""
if
not
(
...
...
@@ -127,21 +125,18 @@ 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
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)
converted_img = F.resize(fake_img, (200, 150))
print(converted_img.size)
# (150, 200)
>>> 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)
>>> 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 +191,18 @@ 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
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)
padded_img = F.pad(fake_img, padding=(2, 1))
print(padded_img.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)
>>> 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)
(304, 258)
"""
if
not
(
_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):
Examples:
.. code-block:: python
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)
>>> 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)
"""
if
not
(
...
...
@@ -287,16 +279,14 @@ 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
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)
>>> 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)
"""
if
not
(
_is_pil_image
(
img
)
or
_is_numpy_image
(
img
)
or
_is_tensor_image
(
img
)
...
...
@@ -327,16 +317,14 @@ def hflip(img):
Examples:
.. code-block:: python
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)
flpped_img = F.hflip(fake_img)
print(flpped_img.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)
>>> flipped_img = F.hflip(fake_img)
>>> print(flipped_img.size)
(300, 256)
"""
if
not
(
...
...
@@ -368,16 +356,14 @@ def vflip(img):
Examples:
.. code-block:: python
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)
flpped_img = F.vflip(fake_img)
print(flpped_img.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)
>>> flipped_img = F.vflip(fake_img)
>>> print(flipped_img.size)
(300, 256)
"""
if
not
(
...
...
@@ -411,20 +397,26 @@ 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
>>> 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):
Examples:
.. code-block:: python
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)
>>> 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)
"""
if
not
(
_is_pil_image
(
img
)
or
_is_numpy_image
(
img
)
or
_is_tensor_image
(
img
)
...
...
@@ -503,16 +493,14 @@ 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
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)
>>> 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)
"""
if
not
(
...
...
@@ -556,16 +544,14 @@ 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
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)
>>> 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)
"""
if
not
(
...
...
@@ -657,13 +643,12 @@ def affine(
Examples:
.. code-block:: python
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)
>>> 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]
"""
if
not
(
...
...
@@ -789,16 +774,14 @@ def rotate(
Examples:
.. code-block:: python
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)
>>> 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)
"""
if
not
(
...
...
@@ -897,16 +880,14 @@ def perspective(img, startpoints, endpoints, interpolation='nearest', fill=0):
Examples:
.. code-block:: python
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)
>>> 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]
"""
if
not
(
...
...
@@ -946,16 +927,14 @@ 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
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)
>>> 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)
>>> print(gray_img.size)
(300, 256)
"""
if
not
(
...
...
@@ -993,19 +972,16 @@ 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
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())
>>> 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
"""
...
...
@@ -1039,35 +1015,28 @@ 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
>>> 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]],
[[ 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]],
[[ 1.66359663, 0. , 0. , -0.57773495],
[-1.03176904, -0.33741450, -0.29695082, -1.50258386]],
[[ 0.67233968, 0. , 0. , -0.06695852],
[-1.85003340, -0.23008066, 0.65083790, 0.75387722]]])
"""
if
_is_tensor_image
(
img
):
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录