Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
Crayon鑫
Paddle
提交
e553d572
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看板
提交
e553d572
编写于
11月 22, 2017
作者:
S
sweetsky0901
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
format test code
上级
0112c5d6
变更
1
显示空白变更内容
内联
并排
Showing
1 changed file
with
18 addition
and
9 deletion
+18
-9
python/paddle/v2/fluid/tests/test_unpool_op.py
python/paddle/v2/fluid/tests/test_unpool_op.py
+18
-9
未找到文件。
python/paddle/v2/fluid/tests/test_unpool_op.py
浏览文件 @
e553d572
...
...
@@ -15,7 +15,8 @@ def unpool2dmax_forward_naive(input, indices, ksize, strides, paddings):
index
=
indices
[
nidx
,
cidx
,
h
,
w
]
hidx
=
(
index
-
index
%
out_W
)
/
out_W
widx
=
index
%
out_W
out
[
nidx
,
cidx
,
int
(
hidx
),
int
(
widx
)]
=
input
[
nidx
,
cidx
,
h
,
w
]
out
[
nidx
,
cidx
,
int
(
hidx
),
int
(
widx
)]
=
\
input
[
nidx
,
cidx
,
h
,
w
]
return
out
...
...
@@ -26,23 +27,31 @@ class TestUnpoolOp(OpTest):
self
.
init_test_case
()
pre_input
=
np
.
random
.
random
(
self
.
shape
).
astype
(
"float32"
)
N
,
C
,
H
,
W
=
pre_input
.
shape
H_out
=
(
H
-
self
.
ksize
[
0
]
+
2
*
self
.
paddings
[
0
])
/
self
.
strides
[
0
]
+
1
W_out
=
(
W
-
self
.
ksize
[
1
]
+
2
*
self
.
paddings
[
1
])
/
self
.
strides
[
1
]
+
1
H_out
=
(
H
-
self
.
ksize
[
0
]
+
2
*
self
.
paddings
[
0
])
/
\
self
.
strides
[
0
]
+
1
W_out
=
(
W
-
self
.
ksize
[
1
]
+
2
*
self
.
paddings
[
1
])
/
\
self
.
strides
[
1
]
+
1
input
=
np
.
zeros
((
N
,
C
,
H_out
,
W_out
))
indices
=
np
.
zeros
((
N
,
C
,
H_out
,
W_out
))
for
i
in
xrange
(
H_out
):
for
j
in
xrange
(
W_out
):
r_start
=
np
.
max
((
i
*
self
.
strides
[
0
]
-
self
.
paddings
[
0
],
0
))
r_end
=
np
.
min
((
i
*
self
.
strides
[
0
]
+
self
.
ksize
[
0
]
-
self
.
paddings
[
0
],
H
))
r_end
=
np
.
min
((
i
*
self
.
strides
[
0
]
+
self
.
ksize
[
0
]
-
\
self
.
paddings
[
0
],
H
))
c_start
=
np
.
max
((
j
*
self
.
strides
[
1
]
-
self
.
paddings
[
1
],
0
))
c_end
=
np
.
min
((
j
*
self
.
strides
[
1
]
+
self
.
ksize
[
1
]
-
self
.
paddings
[
1
],
W
))
c_end
=
np
.
min
((
j
*
self
.
strides
[
1
]
+
self
.
ksize
[
1
]
-
\
self
.
paddings
[
1
],
W
))
for
nidx
in
xrange
(
N
):
for
cidx
in
xrange
(
C
):
x_masked
=
pre_input
[
nidx
,
cidx
,
r_start
:
r_end
,
c_start
:
c_end
]
x_masked
=
pre_input
[
nidx
,
cidx
,
r_start
:
r_end
,
\
c_start
:
c_end
]
input
[
nidx
,
cidx
,
i
,
j
]
=
x_masked
.
max
()
arg
=
x_masked
.
argmax
()
indices
[
nidx
,
cidx
,
i
,
j
]
=
(
r_start
+
arg
/
self
.
ksize
[
1
])
*
W
+
c_start
+
arg
%
self
.
ksize
[
1
]
output
=
self
.
Unpool2d_forward_naive
(
input
,
indices
,
self
.
ksize
,
self
.
strides
,
self
.
paddings
).
astype
(
"float32"
)
indices
[
nidx
,
cidx
,
i
,
j
]
=
\
(
r_start
+
arg
/
self
.
ksize
[
1
])
*
W
+
\
c_start
+
arg
%
self
.
ksize
[
1
]
output
=
self
.
Unpool2d_forward_naive
(
input
,
indices
,
self
.
ksize
,
\
self
.
strides
,
self
.
paddings
).
astype
(
"float32"
)
self
.
inputs
=
{
'X'
:
input
.
astype
(
'float32'
),
'Y'
:
indices
.
astype
(
'int16'
)}
self
.
attrs
=
{
...
...
@@ -57,7 +66,7 @@ class TestUnpoolOp(OpTest):
self
.
check_output
()
def
test_check_grad
(
self
):
self
.
check_grad
([
'X'
],
'Out'
,
max_relative_error
=
0.5
)
self
.
check_grad
([
'X'
],
'Out'
)
def
init_test_case
(
self
):
self
.
Unpool2d_forward_naive
=
unpool2dmax_forward_naive
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录