Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
Paddle
提交
7a79fd88
P
Paddle
项目概览
PaddlePaddle
/
Paddle
11 个月 前同步成功
通知
2291
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看板
体验新版 GitCode,发现更多精彩内容 >>
未验证
提交
7a79fd88
编写于
3月 20, 2023
作者:
zhouweiwei2014
提交者:
GitHub
3月 20, 2023
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Fix unsqueeze with empty axis bug (#51828)
上级
6ac7cabe
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
21 addition
and
15 deletion
+21
-15
paddle/phi/infermeta/unary.cc
paddle/phi/infermeta/unary.cc
+3
-8
paddle/phi/kernels/funcs/unsqueeze.h
paddle/phi/kernels/funcs/unsqueeze.h
+1
-1
paddle/phi/kernels/unsqueeze_kernel.cc
paddle/phi/kernels/unsqueeze_kernel.cc
+1
-6
python/paddle/fluid/tests/unittests/test_unsqueeze_op.py
python/paddle/fluid/tests/unittests/test_unsqueeze_op.py
+16
-0
未找到文件。
paddle/phi/infermeta/unary.cc
浏览文件 @
7a79fd88
...
...
@@ -4791,15 +4791,10 @@ void UnsqueezeInferMeta(const MetaTensor& x,
std
::
vector
<
int64_t
>
vec_out_dims
(
output_size
,
-
1
);
out
->
set_dtype
(
x
.
dtype
());
out
->
set_dims
(
phi
::
make_ddim
(
vec_out_dims
));
}
else
if
(
!
axes
.
GetData
().
empty
())
{
std
::
vector
<
int32_t
>
tmp
;
tmp
.
reserve
(
axes
.
GetData
().
size
());
std
::
for_each
(
axes
.
GetData
().
begin
(),
axes
.
GetData
().
end
(),
[
&
tmp
](
const
int64_t
&
t
)
{
tmp
.
push_back
(
t
);
});
auto
out_dims
=
funcs
::
GetUnsqueezeShape
(
tmp
,
x_dims
);
}
else
{
auto
out_dims
=
funcs
::
GetUnsqueezeShape
(
axes
.
GetData
(),
x_dims
);
out
->
set_dims
(
out_dims
);
if
(
x_dims
[
0
]
==
out_dims
[
0
])
{
if
(
x_dims
.
size
()
>
0
&&
x_dims
[
0
]
==
out_dims
[
0
])
{
out
->
share_lod
(
x
);
}
out
->
set_dtype
(
x
.
dtype
());
...
...
paddle/phi/kernels/funcs/unsqueeze.h
浏览文件 @
7a79fd88
...
...
@@ -103,7 +103,7 @@ inline DDim GetOutputSqueezeShape(const std::vector<int> squeeze_dims,
return
phi
::
make_ddim
(
output_shape
);
}
inline
DDim
GetUnsqueezeShape
(
const
std
::
vector
<
int
>
unsqz_dims
,
inline
DDim
GetUnsqueezeShape
(
const
std
::
vector
<
int
64_t
>
unsqz_dims
,
const
DDim
&
in_dims
)
{
int
output_size
=
in_dims
.
size
()
+
static_cast
<
int
>
(
unsqz_dims
.
size
());
int
cur_output_size
=
in_dims
.
size
();
...
...
paddle/phi/kernels/unsqueeze_kernel.cc
浏览文件 @
7a79fd88
...
...
@@ -28,12 +28,7 @@ void UnsqueezeInferKernel(const Context& dev_ctx,
auto
x_dims
=
x
.
dims
();
auto
out_dims
=
out
->
dims
();
if
(
axes
.
FromTensor
())
{
std
::
vector
<
int32_t
>
tmp
;
tmp
.
reserve
(
axes
.
GetData
().
size
());
std
::
for_each
(
axes
.
GetData
().
begin
(),
axes
.
GetData
().
end
(),
[
&
tmp
](
const
int64_t
&
t
)
{
tmp
.
push_back
(
t
);
});
out_dims
=
funcs
::
GetUnsqueezeShape
(
tmp
,
x_dims
);
out_dims
=
funcs
::
GetUnsqueezeShape
(
axes
.
GetData
(),
x_dims
);
}
out
->
Resize
(
out_dims
);
dev_ctx
.
template
Alloc
<
T
>(
out
);
...
...
python/paddle/fluid/tests/unittests/test_unsqueeze_op.py
浏览文件 @
7a79fd88
...
...
@@ -108,6 +108,22 @@ class TestUnsqueezeOp4(TestUnsqueezeOp):
self
.
new_shape
=
(
10
,
1
,
1
,
2
,
5
,
1
)
# axis is empty, x is ND
class
TestUnsqueezeOp5
(
TestUnsqueezeOp
):
def
init_test_case
(
self
):
self
.
ori_shape
=
()
self
.
axes
=
()
self
.
new_shape
=
()
# axis is empty, x is 0D
class
TestUnsqueezeOp6
(
TestUnsqueezeOp
):
def
init_test_case
(
self
):
self
.
ori_shape
=
(
10
,
2
,
5
)
self
.
axes
=
()
self
.
new_shape
=
(
10
,
2
,
5
)
class
TestUnsqueezeOp_ZeroDim1
(
TestUnsqueezeOp
):
def
init_test_case
(
self
):
self
.
ori_shape
=
()
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录