Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
Paddle
提交
56a65abd
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看板
提交
56a65abd
编写于
7月 20, 2021
作者:
H
HexToString
提交者:
jzhang533
7月 21, 2021
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
fix crop_tensor op doc
上级
0f5e0ba1
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
39 addition
and
36 deletion
+39
-36
python/paddle/fluid/layers/nn.py
python/paddle/fluid/layers/nn.py
+39
-36
未找到文件。
python/paddle/fluid/layers/nn.py
浏览文件 @
56a65abd
...
@@ -9039,10 +9039,10 @@ def crop_tensor(x, shape=None, offsets=None, name=None):
...
@@ -9039,10 +9039,10 @@ def crop_tensor(x, shape=None, offsets=None, name=None):
[6, 7, 8]]]
[6, 7, 8]]]
Parameters:
Parameters:
x (
Variable
): 1-D to 6-D Tensor, the data type is float32, float64, int32 or int64.
x (
Tensor
): 1-D to 6-D Tensor, the data type is float32, float64, int32 or int64.
shape (list|tuple|
Variable
): The output shape is specified
shape (list|tuple|
Tensor
): The output shape is specified
by `shape`. Its data type is int32. If a list/tuple, it's length must be
by `shape`. Its data type is int32. If a list/tuple, it's length must be
the same as the dimension size of `x`. If a
Variable
, it should be a 1-D Tensor.
the same as the dimension size of `x`. If a
Tensor
, it should be a 1-D Tensor.
When it is a list, each element can be an integer or a Tensor of shape: [1].
When it is a list, each element can be an integer or a Tensor of shape: [1].
If Variable contained, it is suitable for the case that the shape may
If Variable contained, it is suitable for the case that the shape may
be changed each iteration.
be changed each iteration.
...
@@ -9056,51 +9056,54 @@ def crop_tensor(x, shape=None, offsets=None, name=None):
...
@@ -9056,51 +9056,54 @@ def crop_tensor(x, shape=None, offsets=None, name=None):
this property. For more information, please refer to :ref:`api_guide_Name` .
this property. For more information, please refer to :ref:`api_guide_Name` .
Returns:
Returns:
Variable
: The cropped Tensor has same data type with `x`.
Tensor
: The cropped Tensor has same data type with `x`.
Raises:
Raises:
TypeError: If the data type of `x` is not in: float32, float64, int32, int64.
TypeError: If the data type of `x` is not in: float32, float64, int32, int64.
TypeError: If `shape` is not a list, tuple or
Variable
.
TypeError: If `shape` is not a list, tuple or
Tensor
.
TypeError: If the data type of `shape` is not int32.
TypeError: If the data type of `shape` is not int32.
TypeError: If `offsets` is not None and not a list, tuple or
Variable
.
TypeError: If `offsets` is not None and not a list, tuple or
Tensor
.
TypeError: If the data type of `offsets` is not int32.
TypeError: If the data type of `offsets` is not int32.
ValueError: If the element in `offsets` is less than zero.
ValueError: If the element in `offsets` is less than zero.
Examples:
Examples:
.. code-block:: python
.. code-block:: python
:name: code-example1
import paddle.fluid as fluid
import paddle.fluid as fluid
import paddle
import paddle
paddle.enable_static()
import numpy as np
x = fluid.data(name="x", shape=[None, 3, 5], dtype="float32")
np_data_x = np.array([[1, 2, 3], [4, 5, 6], [7, 8, 9]]).astype('int32')
# x.shape = [-1, 3, 5], where -1 indicates batch size, and it will get the exact value in runtime.
x = paddle.to_tensor(np_data_x)
# x.shape = [3, 3]
# shape is a 1-D Tensor
# x = [[1, 2, 3], [4, 5, 6], [7, 8, 9]]
crop_shape = fluid.data(name="crop_shape", shape=[3], dtype="int32")
crop0 = fluid.layers.crop_tensor(x, shape=crop_shape)
# shape can be a 1-D Tensor or list or tuple.
# crop0.shape = [-1, -1, -1], it means crop0.shape[0] = x.shape[0] in runtime.
np_data_shape = np.array([2, 2]).astype('int32')
shape_tensor = paddle.to_tensor(np_data_shape)
# or shape is a list in which each element is a constant
# shape_list = [2, 2]
crop1 = fluid.layers.crop_tensor(x, shape=[-1, -1, 3], offsets=[0, 1, 0])
# shape_tuple = (2, 2)
# crop1.shape = [-1, 2, 3]
out = paddle.crop(x, shape_tensor)
# out = paddle.crop(x, shape_list)
# or shape is a list in which each element is a constant or Variable
# out = paddle.crop(x, shape_tuple)
y = fluid.data(name="y", shape=[3, 8, 8], dtype="float32")
np_out = out.numpy()
dim1 = fluid.data(name="dim1", shape=[1], dtype="int32")
print('out = ', np_out)
crop2 = fluid.layers.crop_tensor(y, shape=[3, dim1, 4])
# out.shape = [2, 2]
# crop2.shape = [3, -1, 4]
# out = [[1,2], [4,5]]
# offsets is a 1-D Tensor
# offsets can be a 1-D Tensor or list or tuple.
crop_offsets = fluid.data(name="crop_offsets", shape=[3], dtype="int32")
np_data_offsets = np.array([0, 1]).astype('int32')
crop3 = fluid.layers.crop_tensor(x, shape=[-1, 2, 3], offsets=crop_offsets)
offsets_tensor = paddle.to_tensor(np_data_offsets)
# crop3.shape = [-1, 2, 3]
# offsets_list = [1, 1]
# offsets_tuple = (0, 1)
# offsets is a list in which each element is a constant or Variable
out = paddle.crop(x, shape_tensor, offsets_tensor)
offsets_var = fluid.data(name="dim1", shape=[1], dtype="int32")
# out = paddle.crop(x, shape_tensor, offsets_list)
crop4 = fluid.layers.crop_tensor(x, shape=[-1, 2, 3], offsets=[0, 1, offsets_var])
# out = paddle.crop(x, shape_tensor, offsets_tuple)
# crop4.shape = [-1, 2, 3]
np_out = out.numpy()
print('out = ', np_out)
# out.shape = [2, 2]
# if offsets = [0, 1], out = [[2,3], [5,6]]
# if offsets = [1, 1], out = [[5,6], [8,9]]
"""
"""
helper = LayerHelper('crop_tensor', **locals())
helper = LayerHelper('crop_tensor', **locals())
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录