Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
Crayon鑫
Paddle
提交
df27c264
P
Paddle
项目概览
Crayon鑫
/
Paddle
与 Fork 源项目一致
Fork自
PaddlePaddle / Paddle
通知
1
Star
1
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
1
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
P
Paddle
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
1
Issue
1
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
未验证
提交
df27c264
编写于
7月 26, 2021
作者:
R
Roc
提交者:
GitHub
7月 26, 2021
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Fix and omptimize flip API (#34379)
上级
d3d174f7
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
19 addition
and
5 deletion
+19
-5
python/paddle/fluid/tests/unittests/test_flip.py
python/paddle/fluid/tests/unittests/test_flip.py
+9
-2
python/paddle/tensor/manipulation.py
python/paddle/tensor/manipulation.py
+10
-3
未找到文件。
python/paddle/fluid/tests/unittests/test_flip.py
浏览文件 @
df27c264
...
...
@@ -33,6 +33,8 @@ class TestFlipOp_API(unittest.TestCase):
axis
=
[
0
]
input
=
fluid
.
data
(
name
=
'input'
,
dtype
=
'float32'
,
shape
=
[
2
,
3
])
output
=
paddle
.
flip
(
input
,
axis
)
output
=
paddle
.
flip
(
output
,
-
1
)
output
=
output
.
flip
(
0
)
place
=
fluid
.
CPUPlace
()
if
fluid
.
core
.
is_compiled_with_cuda
():
place
=
fluid
.
CUDAPlace
(
0
)
...
...
@@ -43,7 +45,7 @@ class TestFlipOp_API(unittest.TestCase):
feed
=
{
'input'
:
img
},
fetch_list
=
[
output
])
out_np
=
np
.
array
(
res
[
0
])
out_ref
=
np
.
array
([[
4
,
5
,
6
],
[
1
,
2
,
3
]]).
astype
(
np
.
float32
)
out_ref
=
np
.
array
([[
3
,
2
,
1
],
[
6
,
5
,
4
]]).
astype
(
np
.
float32
)
self
.
assertTrue
(
(
out_np
==
out_ref
).
all
(),
msg
=
'flip output is wrong, out ='
+
str
(
out_np
))
...
...
@@ -53,7 +55,10 @@ class TestFlipOp_API(unittest.TestCase):
with
fluid
.
dygraph
.
guard
():
inputs
=
fluid
.
dygraph
.
to_variable
(
img
)
ret
=
paddle
.
flip
(
inputs
,
[
0
])
out_ref
=
np
.
array
([[
4
,
5
,
6
],
[
1
,
2
,
3
]]).
astype
(
np
.
float32
)
ret
=
ret
.
flip
(
0
)
ret
=
paddle
.
flip
(
ret
,
1
)
out_ref
=
np
.
array
([[
3
,
2
,
1
],
[
6
,
5
,
4
]]).
astype
(
np
.
float32
)
self
.
assertTrue
(
(
ret
.
numpy
()
==
out_ref
).
all
(),
msg
=
'flip output is wrong, out ='
+
str
(
ret
.
numpy
()))
...
...
@@ -82,6 +87,8 @@ class TestFlipOp(OpTest):
def
calc_ref_res
(
self
):
res
=
self
.
inputs
[
'X'
]
if
isinstance
(
self
.
axis
,
int
):
return
np
.
flip
(
res
,
self
.
axis
)
for
axis
in
self
.
axis
:
res
=
np
.
flip
(
res
,
axis
)
return
res
...
...
python/paddle/tensor/manipulation.py
浏览文件 @
df27c264
...
...
@@ -223,7 +223,7 @@ def flip(x, axis, name=None):
Args:
x (Tensor): A Tensor(or LoDTensor) with shape :math:`[N_1, N_2,..., N_k]` . The data type of the input Tensor x
should be float32, float64, int32, int64, bool.
axis (list|tuple): The axis(axes) to flip on. Negative indices for indexing from the end are accepted.
axis (list|tuple
|int
): The axis(axes) to flip on. Negative indices for indexing from the end are accepted.
name (str, optional): The default value is None. Normally there is no need for user to set this property.
For more information, please refer to :ref:`api_guide_Name` .
...
...
@@ -240,10 +240,17 @@ def flip(x, axis, name=None):
x = np.arange(image_shape[0] * image_shape[1] * image_shape[2]).reshape(image_shape)
x = x.astype('float32')
img = paddle.to_tensor(x)
out = paddle.flip(img, [0,1])
tmp = paddle.flip(img, [0,1])
print(tmp) # [[[10,11],[8, 9]], [[6, 7],[4, 5]], [[2, 3],[0, 1]]]
print(out) # [[[10,11][8, 9]],[[6, 7],[4, 5]] [[2, 3],[0, 1]]]
out = paddle.flip(tmp,-1)
print(out) # [[[11,10],[9, 8]], [[7, 6],[5, 4]], [[3, 2],[1, 0]]]
"""
if
isinstance
(
axis
,
int
):
axis
=
[
axis
]
if
in_dygraph_mode
():
return
core
.
ops
.
flip
(
x
,
"axis"
,
axis
)
helper
=
LayerHelper
(
"flip"
,
**
locals
())
check_type
(
x
,
'X'
,
(
Variable
),
'flip'
)
dtype
=
helper
.
input_dtype
(
'x'
)
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录