Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
Paddle
提交
90f39b11
P
Paddle
项目概览
PaddlePaddle
/
Paddle
大约 1 年 前同步成功
通知
2292
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,发现更多精彩内容 >>
提交
90f39b11
编写于
10月 15, 2018
作者:
J
jerrywgz
浏览文件
操作
浏览文件
下载
差异文件
Merge branch 'roialign' of
https://github.com/jerrywgz/Paddle
into roialign
上级
5e52dafd
c0e34eeb
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
18 addition
and
18 deletion
+18
-18
paddle/fluid/operators/roi_align_op.h
paddle/fluid/operators/roi_align_op.h
+4
-5
python/paddle/fluid/tests/unittests/test_roi_align_op.py
python/paddle/fluid/tests/unittests/test_roi_align_op.py
+14
-13
未找到文件。
paddle/fluid/operators/roi_align_op.h
浏览文件 @
90f39b11
...
...
@@ -290,9 +290,6 @@ class CPUROIAlignGradOpKernel : public framework::OpKernel<T> {
for
(
int
n
=
0
;
n
<
rois_num
;
++
n
)
{
int
roi_batch_idx
=
roi_batch_id_data
[
n
];
T
*
batch_grad_data
=
in_grad_data
+
roi_batch_idx
*
in_stride
[
0
];
const
T
*
batch_out_grad_data
=
out_grad_data
+
roi_batch_idx
*
out_stride
[
0
];
T
roi_xmin
=
rois_data
[
0
]
*
spatial_scale
;
T
roi_ymin
=
rois_data
[
1
]
*
spatial_scale
;
T
roi_xmax
=
rois_data
[
2
]
*
spatial_scale
;
...
...
@@ -303,6 +300,10 @@ class CPUROIAlignGradOpKernel : public framework::OpKernel<T> {
static_cast
<
T
>
(
roi_height
)
/
static_cast
<
T
>
(
pooled_height
);
T
bin_size_w
=
static_cast
<
T
>
(
roi_width
)
/
static_cast
<
T
>
(
pooled_width
);
for
(
int
c
=
0
;
c
<
channels
;
++
c
)
{
T
*
batch_grad_data
=
in_grad_data
+
roi_batch_idx
*
in_stride
[
0
]
+
c
*
in_stride
[
1
];
const
T
*
batch_out_grad_data
=
out_grad_data
+
n
*
out_stride
[
0
]
+
c
*
out_stride
[
1
];
for
(
int
ph
=
0
;
ph
<
pooled_height
;
++
ph
)
{
for
(
int
pw
=
0
;
pw
<
pooled_width
;
++
pw
)
{
int
pool_index
=
ph
*
pooled_width
+
pw
;
...
...
@@ -329,8 +330,6 @@ class CPUROIAlignGradOpKernel : public framework::OpKernel<T> {
}
}
}
batch_grad_data
+=
in_stride
[
1
];
batch_out_grad_data
+=
out_stride
[
1
];
}
rois_data
+=
roi_stride
[
0
];
}
...
...
python/paddle/fluid/tests/unittests/test_roi_align_op.py
浏览文件 @
90f39b11
...
...
@@ -37,7 +37,7 @@ class TestROIAlignOp(OpTest):
self
.
outputs
=
{
'Out'
:
self
.
out_data
}
def
init_test_case
(
self
):
self
.
batch_size
=
1
self
.
batch_size
=
3
self
.
channels
=
3
self
.
height
=
8
self
.
width
=
6
...
...
@@ -45,10 +45,10 @@ class TestROIAlignOp(OpTest):
# n, c, h, w
self
.
x_dim
=
(
self
.
batch_size
,
self
.
channels
,
self
.
height
,
self
.
width
)
self
.
spatial_scale
=
1.0
/
1
.0
self
.
spatial_scale
=
1.0
/
2
.0
self
.
pooled_height
=
2
self
.
pooled_width
=
2
self
.
sampling_ratio
=
2
self
.
sampling_ratio
=
-
1
self
.
x
=
np
.
random
.
random
(
self
.
x_dim
).
astype
(
'float32'
)
...
...
@@ -57,7 +57,7 @@ class TestROIAlignOp(OpTest):
count
=
roi_bin_grid_h
*
roi_bin_grid_w
bilinear_pos
=
np
.
zeros
(
[
self
.
channels
,
self
.
pooled_height
,
self
.
pooled_width
,
count
,
4
],
np
.
in
t32
)
np
.
floa
t32
)
bilinear_w
=
np
.
zeros
(
[
self
.
pooled_height
,
self
.
pooled_width
,
count
,
4
],
np
.
float32
)
for
ph
in
range
(
self
.
pooled_width
):
...
...
@@ -85,7 +85,7 @@ class TestROIAlignOp(OpTest):
if
x_low
>=
self
.
width
-
1
:
x
=
x_high
=
x_low
=
self
.
width
-
1
else
:
x_high
=
x_low
=
self
.
width
-
1
x_high
=
x_low
+
1
ly
=
y
-
y_low
lx
=
x
-
x_low
hy
=
1
-
ly
...
...
@@ -107,8 +107,9 @@ class TestROIAlignOp(OpTest):
return
bilinear_pos
,
bilinear_w
def
calc_roi_align
(
self
):
self
.
out_data
=
np
.
zeros
((
self
.
rois_num
,
self
.
channels
,
self
.
pooled_height
,
self
.
pooled_width
))
self
.
out_data
=
np
.
zeros
(
(
self
.
rois_num
,
self
.
channels
,
self
.
pooled_height
,
self
.
pooled_width
)).
astype
(
'float32'
)
for
i
in
range
(
self
.
rois_num
):
roi
=
self
.
rois
[
i
]
...
...
@@ -118,14 +119,14 @@ class TestROIAlignOp(OpTest):
roi_ymin
=
roi
[
2
]
*
self
.
spatial_scale
roi_xmax
=
roi
[
3
]
*
self
.
spatial_scale
roi_ymax
=
roi
[
4
]
*
self
.
spatial_scale
roi_width
=
int
(
max
(
roi_xmax
-
roi_xmin
,
1
)
)
roi_height
=
int
(
max
(
roi_ymax
-
roi_ymin
,
1
)
)
roi_width
=
max
(
roi_xmax
-
roi_xmin
,
1
)
roi_height
=
max
(
roi_ymax
-
roi_ymin
,
1
)
bin_size_h
=
float
(
roi_height
)
/
float
(
self
.
pooled_height
)
bin_size_w
=
float
(
roi_width
)
/
float
(
self
.
pooled_width
)
roi_bin_grid_h
=
self
.
sampling_ratio
if
self
.
sampling_ratio
>
0
else
\
math
.
ceil
(
roi_height
/
pooled_height
)
math
.
ceil
(
roi_height
/
self
.
pooled_height
)
roi_bin_grid_w
=
self
.
sampling_ratio
if
self
.
sampling_ratio
>
0
else
\
math
.
ceil
(
roi_width
/
pooled_width
)
math
.
ceil
(
roi_width
/
self
.
pooled_width
)
count
=
int
(
roi_bin_grid_h
*
roi_bin_grid_w
)
pre_size
=
count
*
self
.
pooled_width
*
self
.
pooled_height
bilinear_pos
,
bilinear_w
=
self
.
pre_calc
(
x_i
,
roi_xmin
,
roi_ymin
,
...
...
@@ -139,7 +140,7 @@ class TestROIAlignOp(OpTest):
def
make_rois
(
self
):
rois
=
[]
self
.
rois_lod
=
[[
0
]]
self
.
rois_lod
=
[[]]
for
bno
in
range
(
self
.
batch_size
):
self
.
rois_lod
[
0
].
append
(
bno
+
1
)
for
i
in
range
(
bno
+
1
):
...
...
@@ -166,4 +167,4 @@ class TestROIAlignOp(OpTest):
self
.
check_output
()
def
test_check_grad
(
self
):
self
.
check_grad
([
'X'
],
'Out'
)
self
.
check_grad
([
'X'
],
'Out'
,
max_relative_error
=
0.005
)
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录