Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
e183ab3b
提交
e183ab3b
authored
1月 13, 2017
作者:
Tegan Maharaj
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
added proper comparison to conv2d.grad
上级
3b740511
隐藏空白字符变更
内嵌
并排
正在显示
1 个修改的文件
包含
44 行增加
和
43 行删除
+44
-43
test_abstract_conv.py
theano/tensor/nnet/tests/test_abstract_conv.py
+44
-43
没有找到文件。
theano/tensor/nnet/tests/test_abstract_conv.py
浏览文件 @
e183ab3b
...
@@ -1606,6 +1606,7 @@ class TestConv2dGrads(unittest.TestCase):
...
@@ -1606,6 +1606,7 @@ class TestConv2dGrads(unittest.TestCase):
self
.
filter_flip
=
[
True
,
False
]
self
.
filter_flip
=
[
True
,
False
]
self
.
output_grad
=
T
.
tensor4
()
self
.
output_grad
=
T
.
tensor4
()
self
.
output_grad_wrt
=
T
.
tensor4
()
self
.
filters
=
T
.
tensor4
()
self
.
filters
=
T
.
tensor4
()
self
.
x
=
T
.
tensor4
(
'x'
,
theano
.
config
.
floatX
)
#inputs
self
.
x
=
T
.
tensor4
(
'x'
,
theano
.
config
.
floatX
)
#inputs
...
@@ -1628,20 +1629,32 @@ class TestConv2dGrads(unittest.TestCase):
...
@@ -1628,20 +1629,32 @@ class TestConv2dGrads(unittest.TestCase):
results are the same.
results are the same.
"""
"""
for
(
in_shape
,
fltr_shape
)
in
zip
(
inputs_shapes
,
filters_shapes
):
for
(
in_shape
,
fltr_shape
)
in
zip
(
self
.
inputs_shapes
,
self
.
filters_shapes
):
for
bm
in
border_modes
:
for
bm
in
self
.
border_modes
:
for
ss
in
subsamples
:
for
ss
in
self
.
subsamples
:
for
ff
in
filter_flip
:
for
ff
in
self
.
filter_flip
:
conv_out
=
T
.
nnet
.
conv
.
conv2d
(
x
,
if
filter_flip
=
True
:
filters
=
filters
,
fltr_shape
=
transpose
(
fltr_shape
)
#conv2d doesn't seem to have filter_flip
conv_out
=
T
.
nnet
.
conv
.
conv2d
(
self
.
x
,
filters
=
self
.
filters
,
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
(
wrt
=
[
x
],
known_grads
=
{
conv_out
:
output_grad
})
conv_grad
=
theano
.
grad
(
wrt
=
[
x
],
known_grads
=
{
conv_out
:
self
.
output_grad
})
f_prime
=
theano
.
function
([
x
,
output_grad
,
filters
],
conv_grad
)
f_prime
=
theano
.
function
([
x
,
output_grad
,
filters
],
conv_grad
)
utt
.
assert_allclose
(
conv_grad
,
f_prime
)
conv_wrt_i_out
=
T
.
nnet
.
conv
.
abstract_conv
.
conv2d_grad_wrt_inputs
(
self
.
output_grad_wrt
,
filters
=
self
.
filters
,
border_mode
=
bm
,
subsample
=
ss
,
input_shape
=
in_shape
,
filter_shape
=
fltr_shape
,
filter_flip
=
ff
)
f
=
theano
.
function
([
x
,
output_grad_wrt
,
filters
],
conv_wrt_i_out
)
utt
.
assert_allclose
(
f
,
f_prime
)
def
test_conv2d_grad_wrt_weights
():
def
test_conv2d_grad_wrt_weights
():
"""Compares calculated abstract grads wrt weights with the fwd grads
"""Compares calculated abstract grads wrt weights with the fwd grads
...
@@ -1652,47 +1665,34 @@ class TestConv2dGrads(unittest.TestCase):
...
@@ -1652,47 +1665,34 @@ class TestConv2dGrads(unittest.TestCase):
"""
"""
for
(
in_shape
,
fltr_shape
)
in
zip
(
inputs_shapes
,
filters_shapes
):
for
(
in_shape
,
fltr_shape
)
in
zip
(
self
.
inputs_shapes
,
self
.
filters_shapes
):
for
bm
in
border_modes
:
for
bm
in
self
.
border_modes
:
for
ss
in
subsamples
:
for
ss
in
self
.
subsamples
:
for
ff
in
filter_flip
:
for
ff
in
self
.
filter_flip
:
conv_out
=
T
.
nnet
.
conv
.
conv2d
(
w
,
if
filter_flip
=
True
:
filters
=
filters
,
fltr_shape
=
transpose
(
fltr_shape
)
#conv2d doesn't seem to have filter_flip
conv_out
=
T
.
nnet
.
conv
.
conv2d
(
self
.
w
,
filters
=
self
.
filters
,
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
(
wrt
=
[
w
],
known_grads
=
{
conv_out
:
output_grad
})
conv_grad
=
theano
.
grad
(
wrt
=
[
w
],
known_grads
=
{
conv_out
:
output_grad
})
f_prime
=
theano
.
function
([
w
,
output_grad
,
filters
],
conv_grad
)
f_prime
=
theano
.
function
([
w
,
output_grad
,
filters
],
conv_grad
)
utt
.
assert_allclose
(
conv_grad
,
f_prime
)
def
test_conv2_grads_wrt_input_and_weights
():
conv_wrt_w_out
=
T
.
nnet
.
conv
.
abstract_conv
.
conv2d_grad_wrt_weights
(
self
.
output_grad_wrt
,
"""Compares calculated abstract grads wrt [inputs, weights] with the fwd grads
filters
=
self
.
filters
,
border_mode
=
bm
,
subsample
=
ss
,
input_shape
=
in_shape
,
filter_shape
=
fltr_shape
,
filter_flip
=
ff
)
f
=
theano
.
function
([
w
,
output_grad_wrt
,
filters
],
conv_wrt_w_out
)
utt
.
assert_allclose
(
f
,
f_prime
)
This method checks the outputs of conv2_grad wrt inputs and weights
against the outputs of T.nnet.conv forward grads to make sure the
results are the same.
"""
def
test_conv2_grads_wrt_input_and_weights
():
#for (input_shape, filter_shape) in zip(inputs_shapes, filter_shapes):
test_conv2d_grad_wrt_inputs
()
#make_rand_inputs = theano.function([x], random_stream(input_shape))
test_conv2d_grad_wrt_weights
()
#make_rand_filters = theano.function([filters], random_stream(filter_shape))
\ No newline at end of file
for
(
in_shape
,
fltr_shape
)
in
zip
(
inputs_shapes
,
filters_shapes
):
for
wrt
in
[
x
,
w
]:
#for both inputs (x) and weights (w)
for
bm
in
border_modes
:
for
ss
in
subsamples
:
for
ff
in
filter_flip
:
conv_out
=
T
.
nnet
.
conv
.
conv2d
(
wrt
,
filters
=
filters
,
border_mode
=
bm
,
subsample
=
ss
,
image_shape
=
in_shape
filter_shape
=
fltr_shape
)
conv_grad
=
theano
.
grad
(
wrt
=
[
wrt
],
known_grads
=
{
conv_out
:
output_grad
})
f_prime
=
theano
.
function
([
wrt
,
output_grad
,
filters
],
conv_grad
)
utt
.
assert_allclose
(
conv_grad
,
f_prime
)
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论