Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
weixin_40195168达庆意
keras
提交
62c395e7
K
keras
项目概览
weixin_40195168达庆意
/
keras
与 Fork 源项目一致
从无法访问的项目Fork
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
K
keras
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
前往新版Gitcode,体验更适合开发者的 AI 搜索 >>
提交
62c395e7
编写于
3月 06, 2018
作者:
T
Taehoon Lee
提交者:
François Chollet
3月 05, 2018
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Make separable conv backend tests efficient (#9570)
上级
614a8b4f
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
29 addition
and
21 deletion
+29
-21
tests/keras/backend/backend_test.py
tests/keras/backend/backend_test.py
+29
-21
未找到文件。
tests/keras/backend/backend_test.py
浏览文件 @
62c395e7
...
...
@@ -257,6 +257,11 @@ def ref_depthwise_conv(x, w, padding, data_format):
return
y
def
ref_separable_conv
(
x
,
w1
,
w2
,
padding
,
data_format
):
x2
=
ref_depthwise_conv
(
x
,
w1
,
padding
,
data_format
)
return
ref_conv
(
x2
,
w2
,
padding
,
data_format
)
def
ref_rnn
(
x
,
w
,
init
,
go_backwards
=
False
,
mask
=
None
,
unroll
=
False
,
input_length
=
None
):
w_i
,
w_h
,
w_o
=
w
h
=
[]
...
...
@@ -1086,27 +1091,30 @@ class TestBackend(object):
BACKENDS
,
cntk_dynamicity
=
True
,
data_format
=
data_format
)
def
test_separable_conv2d
(
self
):
for
(
input_shape
,
data_format
)
in
[
((
2
,
3
,
4
,
5
),
'channels_first'
),
((
2
,
3
,
5
,
6
),
'channels_first'
),
((
1
,
6
,
5
,
3
),
'channels_last'
)]:
input_depth
=
input_shape
[
1
]
if
data_format
==
'channels_first'
else
input_shape
[
-
1
]
_
,
x_val
=
parse_shape_or_val
(
input_shape
)
x_tf
=
KTF
.
variable
(
x_val
)
for
kernel_shape
in
[(
2
,
2
),
(
4
,
3
)]:
for
depth_multiplier
in
[
1
,
2
]:
_
,
depthwise_val
=
parse_shape_or_val
(
kernel_shape
+
(
input_depth
,
depth_multiplier
))
_
,
pointwise_val
=
parse_shape_or_val
((
1
,
1
)
+
(
input_depth
*
depth_multiplier
,
7
))
z_tf
=
KTF
.
eval
(
KTF
.
separable_conv2d
(
x_tf
,
KTF
.
variable
(
depthwise_val
),
KTF
.
variable
(
pointwise_val
),
data_format
=
data_format
))
z_c
=
cntk_func_three_tensor
(
'separable_conv2d'
,
input_shape
,
depthwise_val
,
pointwise_val
,
data_format
=
data_format
)([
x_val
])[
0
]
assert_allclose
(
z_tf
,
z_c
,
1e-3
)
@
pytest
.
mark
.
skipif
(
K
.
backend
()
==
'theano'
,
reason
=
'Not supported.'
)
@
pytest
.
mark
.
parametrize
(
'op,input_shape,kernel_shape,depth_multiplier,padding,data_format'
,
[
(
'separable_conv2d'
,
(
2
,
3
,
4
,
5
),
(
3
,
3
),
1
,
'same'
,
'channels_first'
),
(
'separable_conv2d'
,
(
2
,
3
,
5
,
6
),
(
4
,
3
),
2
,
'valid'
,
'channels_first'
),
(
'separable_conv2d'
,
(
1
,
6
,
5
,
3
),
(
3
,
4
),
1
,
'valid'
,
'channels_last'
),
(
'separable_conv2d'
,
(
1
,
7
,
6
,
3
),
(
3
,
3
),
2
,
'same'
,
'channels_last'
),
])
def
test_separable_conv2d
(
self
,
op
,
input_shape
,
kernel_shape
,
depth_multiplier
,
padding
,
data_format
):
input_depth
=
input_shape
[
1
]
if
data_format
==
'channels_first'
else
input_shape
[
-
1
]
_
,
x
=
parse_shape_or_val
(
input_shape
)
_
,
depthwise
=
parse_shape_or_val
(
kernel_shape
+
(
input_depth
,
depth_multiplier
))
_
,
pointwise
=
parse_shape_or_val
((
1
,
1
)
+
(
input_depth
*
depth_multiplier
,
7
))
y1
=
ref_separable_conv
(
x
,
depthwise
,
pointwise
,
padding
,
data_format
)
if
K
.
backend
()
==
'cntk'
:
y2
=
cntk_func_three_tensor
(
op
,
input_shape
,
depthwise
,
pointwise
,
padding
=
padding
,
data_format
=
data_format
)([
x
])[
0
]
else
:
y2
=
K
.
eval
(
getattr
(
K
,
op
)(
K
.
variable
(
x
),
K
.
variable
(
depthwise
),
K
.
variable
(
pointwise
),
padding
=
padding
,
data_format
=
data_format
))
assert_allclose
(
y1
,
y2
,
atol
=
1e-05
)
def
test_pool2d
(
self
):
check_single_tensor_operation
(
'pool2d'
,
(
5
,
10
,
12
,
3
),
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录