Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
23512f3d
提交
23512f3d
authored
3月 14, 2017
作者:
Pascal Lamblin
提交者:
GitHub
3月 14, 2017
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #5554 from teganmaharaj/test_abstract_conv
Test abstract conv
上级
7cfd2879
1ae4563b
隐藏空白字符变更
内嵌
并排
正在显示
1 个修改的文件
包含
106 行增加
和
0 行删除
+106
-0
test_abstract_conv.py
theano/tensor/nnet/tests/test_abstract_conv.py
+106
-0
没有找到文件。
theano/tensor/nnet/tests/test_abstract_conv.py
浏览文件 @
23512f3d
...
@@ -1594,3 +1594,109 @@ class TestConv2dTranspose(unittest.TestCase):
...
@@ -1594,3 +1594,109 @@ class TestConv2dTranspose(unittest.TestCase):
[
2
,
2
,
4
,
4
,
4
,
4
,
4
,
4
,
2
,
2
],
[
2
,
2
,
4
,
4
,
4
,
4
,
4
,
4
,
2
,
2
],
[
2
,
2
,
4
,
4
,
4
,
4
,
4
,
4
,
2
,
2
]]]]
*
2
)
[
2
,
2
,
4
,
4
,
4
,
4
,
4
,
4
,
2
,
2
]]]]
*
2
)
numpy
.
testing
.
assert_equal
(
output
,
expected_output
)
numpy
.
testing
.
assert_equal
(
output
,
expected_output
)
class
TestConv2dGrads
(
unittest
.
TestCase
):
def
setUp
(
self
):
if
(
not
theano
.
config
.
cxx
or
theano
.
config
.
mode
==
"FAST_COMPILE"
):
raise
SkipTest
(
"Need blas to test conv2d"
)
self
.
random_stream
=
numpy
.
random
.
RandomState
(
utt
.
fetch_seed
())
self
.
inputs_shapes
=
[(
8
,
1
,
12
,
12
),
(
1
,
1
,
5
,
5
),
(
1
,
1
,
5
,
6
),
(
1
,
1
,
6
,
6
)]
self
.
filters_shapes
=
[(
5
,
1
,
2
,
2
),
(
1
,
1
,
3
,
3
)]
self
.
subsamples
=
[(
1
,
1
),
(
2
,
2
)]
self
.
border_modes
=
[
"valid"
,
"full"
]
self
.
filter_flip
=
[
True
,
False
]
self
.
output_grad
=
theano
.
tensor
.
tensor4
()
self
.
output_grad_wrt
=
theano
.
tensor
.
tensor4
()
self
.
x
=
theano
.
tensor
.
tensor4
(
'x'
,
theano
.
config
.
floatX
)
# inputs
self
.
w
=
theano
.
tensor
.
tensor4
(
'w'
,
theano
.
config
.
floatX
)
# filter weights
def
test_conv2d_grad_wrt_inputs
(
self
):
"""Compares calculated abstract grads wrt inputs with the fwd grads
This method checks the outputs of conv2_grad_wrt_inputs against
the outputs of T.nnet.conv forward grads to make sure the
results are the same.
"""
for
(
in_shape
,
fltr_shape
)
in
zip
(
self
.
inputs_shapes
,
self
.
filters_shapes
):
for
bm
in
self
.
border_modes
:
for
ss
in
self
.
subsamples
:
for
ff
in
self
.
filter_flip
:
input_val
=
self
.
random_stream
.
random_sample
(
in_shape
)
.
astype
(
theano
.
config
.
floatX
)
filter_val
=
self
.
random_stream
.
random_sample
(
fltr_shape
)
.
astype
(
theano
.
config
.
floatX
)
out_grad_shape
=
theano
.
tensor
.
nnet
.
abstract_conv
.
get_conv_output_shape
(
image_shape
=
in_shape
,
kernel_shape
=
fltr_shape
,
border_mode
=
bm
,
subsample
=
ss
)
out_grad_val
=
self
.
random_stream
.
random_sample
(
out_grad_shape
)
.
astype
(
theano
.
config
.
floatX
)
conv_out
=
theano
.
tensor
.
nnet
.
conv2d
(
self
.
x
,
filters
=
self
.
w
,
border_mode
=
bm
,
subsample
=
ss
,
input_shape
=
in_shape
,
filter_shape
=
fltr_shape
,
filter_flip
=
ff
)
conv_grad
=
theano
.
grad
(
conv_out
.
sum
(),
wrt
=
self
.
x
,
known_grads
=
{
conv_out
:
self
.
output_grad
})
f_old
=
theano
.
function
([
self
.
x
,
self
.
w
,
self
.
output_grad
],
conv_grad
)
conv_wrt_i_out
=
theano
.
tensor
.
nnet
.
abstract_conv
.
conv2d_grad_wrt_inputs
(
output_grad
=
self
.
output_grad_wrt
,
filters
=
self
.
w
,
border_mode
=
bm
,
subsample
=
ss
,
input_shape
=
in_shape
,
filter_shape
=
fltr_shape
,
filter_flip
=
ff
)
f_new
=
theano
.
function
([
self
.
w
,
self
.
output_grad_wrt
],
conv_wrt_i_out
)
# check that they're equal
utt
.
assert_allclose
(
f_new
(
filter_val
,
out_grad_val
),
f_old
(
input_val
,
filter_val
,
out_grad_val
))
def
test_conv2d_grad_wrt_weights
(
self
):
"""Compares calculated abstract grads wrt weights with the fwd grads
This method checks the outputs of conv2_grad_wrt_weights against
the outputs of T.nnet.conv forward grads to make sure the
results are the same.
"""
for
(
in_shape
,
fltr_shape
)
in
zip
(
self
.
inputs_shapes
,
self
.
filters_shapes
):
for
bm
in
self
.
border_modes
:
for
ss
in
self
.
subsamples
:
for
ff
in
self
.
filter_flip
:
input_val
=
self
.
random_stream
.
random_sample
(
in_shape
)
.
astype
(
theano
.
config
.
floatX
)
filter_val
=
self
.
random_stream
.
random_sample
(
fltr_shape
)
.
astype
(
theano
.
config
.
floatX
)
out_grad_shape
=
theano
.
tensor
.
nnet
.
abstract_conv
.
get_conv_output_shape
(
image_shape
=
in_shape
,
kernel_shape
=
fltr_shape
,
border_mode
=
bm
,
subsample
=
ss
)
out_grad_val
=
self
.
random_stream
.
random_sample
(
out_grad_shape
)
.
astype
(
theano
.
config
.
floatX
)
conv_out
=
theano
.
tensor
.
nnet
.
conv2d
(
self
.
x
,
filters
=
self
.
w
,
border_mode
=
bm
,
subsample
=
ss
,
input_shape
=
in_shape
,
filter_shape
=
fltr_shape
,
filter_flip
=
ff
)
conv_grad
=
theano
.
grad
(
conv_out
.
sum
(),
wrt
=
self
.
w
,
known_grads
=
{
conv_out
:
self
.
output_grad
})
f_old
=
theano
.
function
([
self
.
x
,
self
.
w
,
self
.
output_grad
],
conv_grad
)
conv_wrt_w_out
=
theano
.
tensor
.
nnet
.
abstract_conv
.
conv2d_grad_wrt_weights
(
self
.
x
,
output_grad
=
self
.
output_grad_wrt
,
border_mode
=
bm
,
subsample
=
ss
,
input_shape
=
in_shape
,
filter_shape
=
fltr_shape
,
filter_flip
=
ff
)
f_new
=
theano
.
function
([
self
.
x
,
self
.
output_grad_wrt
],
conv_wrt_w_out
)
utt
.
assert_allclose
(
f_new
(
input_val
,
out_grad_val
),
f_old
(
input_val
,
filter_val
,
out_grad_val
))
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论