Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
Crayon鑫
Paddle
提交
9089841b
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看板
未验证
提交
9089841b
编写于
10月 09, 2020
作者:
L
LielinJiang
提交者:
GitHub
10月 09, 2020
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Fix bilateral inference shape bug (#26822)
* fix bilateral bug
上级
5345a588
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
36 addition
and
20 deletion
+36
-20
paddle/fluid/operators/bilateral_slice_op.cc
paddle/fluid/operators/bilateral_slice_op.cc
+18
-13
python/paddle/fluid/contrib/layers/nn.py
python/paddle/fluid/contrib/layers/nn.py
+5
-3
python/paddle/fluid/tests/unittests/test_bilateral_slice_op.py
...n/paddle/fluid/tests/unittests/test_bilateral_slice_op.py
+13
-4
未找到文件。
paddle/fluid/operators/bilateral_slice_op.cc
浏览文件 @
9089841b
...
...
@@ -50,20 +50,25 @@ class BilateralSliceOp : public framework::OperatorWithKernel {
int64_t
input_chans
=
input_dims
[
1
];
int64_t
output_chans
;
if
(
has_offset
)
{
PADDLE_ENFORCE_EQ
((
coeffs_chans
%
(
input_chans
+
1
)),
0
,
platform
::
errors
::
InvalidArgument
(
"Slicing with affine offset, coefficients grid "
"should have n_out*(n_in+1) channels, but got %d"
,
coeffs_chans
));
output_chans
=
coeffs_chans
/
(
input_chans
+
1
);
if
((
!
ctx
->
IsRuntime
())
&&
((
coeffs_chans
<
0
)
||
(
input_chans
<
0
)))
{
output_chans
=
-
1
;
}
else
{
PADDLE_ENFORCE_EQ
((
coeffs_chans
%
input_chans
),
0
,
platform
::
errors
::
InvalidArgument
(
"Slicing without affine offset, coefficients grid "
"should have n_out*n_in channels, but got %d ."
,
coeffs_chans
));
output_chans
=
coeffs_chans
/
input_chans
;
if
(
has_offset
)
{
PADDLE_ENFORCE_EQ
((
coeffs_chans
%
(
input_chans
+
1
)),
0
,
platform
::
errors
::
InvalidArgument
(
"Slicing with affine offset, coefficients grid "
"should have n_out*(n_in+1) channels, but got %d"
,
coeffs_chans
));
output_chans
=
coeffs_chans
/
(
input_chans
+
1
);
}
else
{
PADDLE_ENFORCE_EQ
(
(
coeffs_chans
%
input_chans
),
0
,
platform
::
errors
::
InvalidArgument
(
"Slicing without affine offset, coefficients grid "
"should have n_out*n_in channels, but got %d ."
,
coeffs_chans
));
output_chans
=
coeffs_chans
/
input_chans
;
}
}
std
::
vector
<
int64_t
>
output_dims
;
...
...
python/paddle/fluid/contrib/layers/nn.py
浏览文件 @
9089841b
...
...
@@ -1525,10 +1525,10 @@ def bilateral_slice(x, guide, grid, has_offset, name=None):
grid = fluid.data(name='grid', shape=[None, 12, 8, 10, 6], dtype='float32')
# without offset
output = fluid.
layers
.bilateral_slice(x, guide, grid, has_offset=False)
output = fluid.
contrib
.bilateral_slice(x, guide, grid, has_offset=False)
# has offset
output = fluid.
layers
.bilateral_slice(x, guide, grid, has_offset=True)
output = fluid.
contrib
.bilateral_slice(x, guide, grid, has_offset=True)
"""
helper
=
LayerHelper
(
"bilateral_slice"
,
**
locals
())
...
...
@@ -1541,7 +1541,9 @@ def bilateral_slice(x, guide, grid, has_offset, name=None):
out
=
helper
.
create_variable_for_type_inference
(
x
.
dtype
)
inputs
=
{
'X'
:
x
,
'Guide'
:
guide
,
'Grid'
:
grid
}
if
paddle
.
fluid
.
in_dygraph_mode
():
attrs
=
(
'has_offset'
,
has_offset
)
return
getattr
(
core
.
ops
,
"bilateral_slice"
)(
x
,
grid
,
guide
,
*
attrs
)
helper
.
append_op
(
type
=
'bilateral_slice'
,
inputs
=
inputs
,
...
...
python/paddle/fluid/tests/unittests/test_bilateral_slice_op.py
浏览文件 @
9089841b
...
...
@@ -178,16 +178,25 @@ class TestBilateralSliceOp1(TestBilateralSliceOp):
self
.
data_type
=
'float32'
class
TestBilateralSliceApi
(
TestBilateralSliceOp
):
class
TestBilateralSliceApi
(
unittest
.
TestCase
):
def
test_api
(
self
):
x
=
paddle
.
fluid
.
data
(
name
=
'x'
,
shape
=
[
None
,
3
,
25
,
15
],
dtype
=
'float32'
)
guide
=
paddle
.
fluid
.
data
(
name
=
'guide'
,
shape
=
[
None
,
25
,
15
],
dtype
=
'float32'
)
grid
=
paddle
.
fluid
.
data
(
name
=
'grid'
,
shape
=
[
None
,
12
,
8
,
5
,
3
],
dtype
=
'float32'
)
paddle
.
fluid
.
contrib
.
layers
.
bilateral_slice
(
x
,
guide
,
grid
,
self
.
has_offset
)
name
=
'grid'
,
shape
=
[
None
,
None
,
8
,
5
,
3
],
dtype
=
'float32'
)
paddle
.
fluid
.
contrib
.
layers
.
bilateral_slice
(
x
,
guide
,
grid
,
False
)
if
not
paddle
.
fluid
.
is_compiled_with_cuda
():
return
with
paddle
.
fluid
.
dygraph
.
guard
():
x1
=
paddle
.
rand
([
3
,
1
,
50
,
30
])
guide1
=
paddle
.
rand
([
3
,
50
,
30
])
grid1
=
paddle
.
rand
([
3
,
2
,
2
,
5
,
3
])
paddle
.
fluid
.
contrib
.
bilateral_slice
(
x1
,
guide1
,
grid1
,
False
)
if
__name__
==
"__main__"
:
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录