Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
30c18aa4
提交
30c18aa4
authored
2月 11, 2017
作者:
Tegan Maharaj
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
fixed bugs
上级
4eda607b
显示空白字符变更
内嵌
并排
正在显示
1 个修改的文件
包含
37 行增加
和
15 行删除
+37
-15
test_abstract_conv.py
theano/tensor/nnet/tests/test_abstract_conv.py
+37
-15
没有找到文件。
theano/tensor/nnet/tests/test_abstract_conv.py
浏览文件 @
30c18aa4
...
@@ -1605,10 +1605,9 @@ class TestConv2dGrads(unittest.TestCase):
...
@@ -1605,10 +1605,9 @@ class TestConv2dGrads(unittest.TestCase):
self
.
output_grad
=
theano
.
tensor
.
tensor4
()
self
.
output_grad
=
theano
.
tensor
.
tensor4
()
self
.
output_grad_wrt
=
theano
.
tensor
.
tensor4
()
self
.
output_grad_wrt
=
theano
.
tensor
.
tensor4
()
self
.
filters
=
theano
.
tensor
.
tensor4
()
self
.
x
=
theano
.
tensor
.
tensor4
(
'x'
,
theano
.
config
.
floatX
)
# inputs
self
.
x
=
theano
.
tensor
.
tensor4
(
'x'
,
theano
.
config
.
floatX
)
# inputs
self
.
w
=
theano
.
tensor
.
tensor4
(
'w'
,
theano
.
config
.
floatX
)
# weights
self
.
w
=
theano
.
tensor
.
tensor4
(
'w'
,
theano
.
config
.
floatX
)
#
filter
weights
def
test_conv2d_grad_wrt_inputs
(
self
):
def
test_conv2d_grad_wrt_inputs
(
self
):
"""Compares calculated abstract grads wrt inputs with the fwd grads
"""Compares calculated abstract grads wrt inputs with the fwd grads
...
@@ -1616,32 +1615,48 @@ class TestConv2dGrads(unittest.TestCase):
...
@@ -1616,32 +1615,48 @@ class TestConv2dGrads(unittest.TestCase):
the outputs of T.nnet.conv forward grads to make sure the
the outputs of T.nnet.conv forward grads to make sure the
results are the same.
results are the same.
"""
"""
for
(
in_shape
,
fltr_shape
)
in
zip
(
self
.
inputs_shapes
,
self
.
filters_shapes
):
for
(
in_shape
,
fltr_shape
)
in
zip
(
self
.
inputs_shapes
,
self
.
filters_shapes
):
for
bm
in
self
.
border_modes
:
for
bm
in
self
.
border_modes
:
for
ss
in
self
.
subsamples
:
for
ss
in
self
.
subsamples
:
for
ff
in
self
.
filter_flip
:
for
ff
in
self
.
filter_flip
:
if
self
.
filter_flip
:
if
self
.
filter_flip
:
fltr_shape
=
fltr_shape
[::
1
]
# conv2d doesn't seem to have filter_flip
fltr_shape
=
fltr_shape
[::
1
]
# conv2d doesn't seem to have filter_flip
# get random values of the right shapes
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
)
# old conv
conv_out
=
theano
.
tensor
.
nnet
.
conv
.
conv2d
(
self
.
x
,
conv_out
=
theano
.
tensor
.
nnet
.
conv
.
conv2d
(
self
.
x
,
filters
=
self
.
filters
,
filters
=
self
.
w
,
border_mode
=
bm
,
border_mode
=
bm
,
subsample
=
ss
,
subsample
=
ss
,
image_shape
=
in_shape
,
image_shape
=
in_shape
,
filter_shape
=
fltr_shape
filter_shape
=
fltr_shape
)
)
# grad of old conv
conv_grad
=
theano
.
grad
(
conv_out
.
sum
(),
wrt
=
[
self
.
x
],
known_grads
=
{
conv_out
:
self
.
output_grad
})
conv_grad
=
theano
.
grad
(
conv_out
.
sum
(),
wrt
=
[
self
.
x
],
known_grads
=
{
conv_out
:
self
.
output_grad
})
f_
prime
=
theano
.
function
([
self
.
x
,
self
.
output_grad
,
self
.
filters
],
conv_grad
)
f_
old
=
theano
.
function
([
self
.
x
,
self
.
w
,
self
.
output_grad
],
conv_grad
)
conv_wrt_i_out
=
theano
.
tensor
.
nnet
.
conv
.
abstract_conv
.
conv2d_grad_wrt_inputs
(
self
.
output_grad_wrt
,
# new conv + grad (wrt i)
filters
=
self
.
filters
,
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
,
border_mode
=
bm
,
subsample
=
ss
,
subsample
=
ss
,
input_shape
=
in_shape
,
input_shape
=
in_shape
,
filter_shape
=
fltr_shape
,
filter_shape
=
fltr_shape
,
filter_flip
=
ff
filter_flip
=
ff
)
)
f
=
theano
.
function
([
self
.
x
,
self
.
output_grad_wrt
,
self
.
filters
],
conv_wrt_i_out
)
f_new
=
theano
.
function
([
self
.
w
,
self
.
output_grad_wrt
],
conv_wrt_i_out
)
utt
.
assert_allclose
(
f
,
f_prime
)
# 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
):
def
test_conv2d_grad_wrt_weights
(
self
):
"""Compares calculated abstract grads wrt weights with the fwd grads
"""Compares calculated abstract grads wrt weights with the fwd grads
...
@@ -1656,23 +1671,30 @@ class TestConv2dGrads(unittest.TestCase):
...
@@ -1656,23 +1671,30 @@ class TestConv2dGrads(unittest.TestCase):
for
ff
in
self
.
filter_flip
:
for
ff
in
self
.
filter_flip
:
if
self
.
filter_flip
:
if
self
.
filter_flip
:
fltr_shape
=
fltr_shape
[::
1
]
# conv2d doesn't seem to have filter_flip
fltr_shape
=
fltr_shape
[::
1
]
# conv2d doesn't seem to have filter_flip
conv_out
=
theano
.
tensor
.
nnet
.
conv
.
conv2d
(
self
.
w
,
input_val
=
self
.
random_stream
.
random_sample
(
in_shape
)
.
astype
(
theano
.
config
.
floatX
)
filters
=
self
.
filters
,
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
.
conv
.
conv2d
(
self
.
x
,
filters
=
self
.
w
,
border_mode
=
bm
,
border_mode
=
bm
,
subsample
=
ss
,
subsample
=
ss
,
image_shape
=
in_shape
,
image_shape
=
in_shape
,
filter_shape
=
fltr_shape
filter_shape
=
fltr_shape
)
)
conv_grad
=
theano
.
grad
(
conv_out
.
sum
(),
wrt
=
[
self
.
w
],
known_grads
=
{
conv_out
:
self
.
output_grad
})
conv_grad
=
theano
.
grad
(
conv_out
.
sum
(),
wrt
=
[
self
.
w
],
known_grads
=
{
conv_out
:
self
.
output_grad
})
f_
prime
=
theano
.
function
([
self
.
w
,
self
.
output_grad
,
self
.
filters
],
conv_grad
)
f_
old
=
theano
.
function
([
self
.
x
,
self
.
w
,
self
.
output_grad
],
conv_grad
)
conv_wrt_w_out
=
theano
.
tensor
.
nnet
.
conv
.
abstract_conv
.
conv2d_grad_wrt_weights
(
self
.
output_grad_wrt
,
conv_wrt_w_out
=
theano
.
tensor
.
nnet
.
abstract_conv
.
conv2d_grad_wrt_weights
(
self
.
x
,
filters
=
self
.
filters
,
output_grad
=
self
.
output_grad_wrt
,
border_mode
=
bm
,
border_mode
=
bm
,
subsample
=
ss
,
subsample
=
ss
,
input_shape
=
in_shape
,
input_shape
=
in_shape
,
filter_shape
=
fltr_shape
,
filter_shape
=
fltr_shape
,
filter_flip
=
ff
filter_flip
=
ff
)
)
f
=
theano
.
function
([
self
.
w
,
self
.
output_grad_wrt
,
self
.
filters
],
conv_wrt_w_out
)
f
_new
=
theano
.
function
([
self
.
x
,
self
.
output_grad_wrt
],
conv_wrt_w_out
)
utt
.
assert_allclose
(
f
,
f_prime
)
utt
.
assert_allclose
(
f
_new
(
input_val
,
out_grad_val
),
f_old
(
input_val
,
filter_val
,
out_grad_val
)
)
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论