Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
e44ce417
提交
e44ce417
authored
6月 05, 2017
作者:
affanv14
提交者:
Mohammed Affan
6月 14, 2017
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Improve test for abstractconv
上级
95450282
隐藏空白字符变更
内嵌
并排
正在显示
1 个修改的文件
包含
123 行增加
和
111 行删除
+123
-111
test_abstract_conv.py
theano/tensor/nnet/tests/test_abstract_conv.py
+123
-111
没有找到文件。
theano/tensor/nnet/tests/test_abstract_conv.py
浏览文件 @
e44ce417
...
...
@@ -3,6 +3,7 @@ import unittest
import
numpy
as
np
from
nose.plugins.skip
import
SkipTest
from
nose.tools
import
assert_raises
,
assert_true
import
theano
from
theano
import
tensor
from
theano.configparser
import
change_flags
...
...
@@ -1701,126 +1702,137 @@ class TestConv2dGrads(unittest.TestCase):
class
Grouped_conv_noOptim
(
unittest
.
TestCase
):
conv2d
=
staticmethod
(
theano
.
tensor
.
nnet
.
abstract_conv
.
AbstractConv2d
)
conv2d_gradw
=
staticmethod
(
theano
.
tensor
.
nnet
.
abstract_conv
.
AbstractConv2d_gradWeights
)
conv2d_gradi
=
staticmethod
(
theano
.
tensor
.
nnet
.
abstract_conv
.
AbstractConv2d_gradInputs
)
mode
=
theano
.
Mode
(
optimizer
=
None
)
flip_filter
=
False
def
setUp
(
self
):
self
.
num_groups
=
3
self
.
num_groups
=
[
3
,
2
,
4
,
4
]
self
.
border_mode
=
'valid'
self
.
subsample
=
(
1
,
1
)
self
.
img_shape
=
(
5
,
6
,
5
,
5
)
self
.
kern_shape
=
(
6
,
2
,
3
,
3
)
self
.
top_shape
=
(
5
,
6
,
3
,
3
)
self
.
img_shape
=
[(
5
,
6
,
5
,
5
),
(
4
,
4
,
7
,
5
),
(
3
,
8
,
5
,
3
),
(
2
,
4
,
7
,
7
)]
self
.
kern_shape
=
[(
6
,
2
,
3
,
3
),
(
6
,
2
,
5
,
3
),
(
4
,
2
,
3
,
3
),
(
4
,
1
,
3
,
5
)]
self
.
top_shape
=
[(
5
,
6
,
3
,
3
),
(
4
,
6
,
3
,
3
),
(
3
,
4
,
3
,
1
),
(
2
,
4
,
5
,
3
)]
self
.
filter_dilation
=
(
1
,
1
)
self
.
mode
=
theano
.
Mode
(
optimizer
=
None
)
self
.
ref_mode
=
'FAST_RUN'
def
test_fwd
(
self
):
img
=
np
.
random
.
random
(
self
.
img_shape
)
.
astype
(
'float32'
)
kern
=
np
.
random
.
random
(
self
.
kern_shape
)
.
astype
(
'float32'
)
split_imgs
=
np
.
split
(
img
,
self
.
num_groups
,
axis
=
1
)
split_kern
=
np
.
split
(
kern
,
self
.
num_groups
,
axis
=
0
)
img_var
=
theano
.
tensor
.
tensor4
(
'img'
)
kern_var
=
theano
.
tensor
.
tensor4
(
'kern'
)
grouped_abstractconv_func
=
theano
.
tensor
.
nnet
.
abstract_conv
.
AbstractConv2d
(
imshp
=
None
,
kshp
=
None
,
border_mode
=
self
.
border_mode
,
subsample
=
self
.
subsample
,
filter_dilation
=
self
.
filter_dilation
,
num_groups
=
self
.
num_groups
)
grouped_conv_output
=
grouped_abstractconv_func
(
img_var
,
kern_var
)
grouped_func
=
theano
.
function
([
img_var
,
kern_var
],
grouped_conv_output
,
mode
=
self
.
mode
)
grouped_output
=
grouped_func
(
img
,
kern
)
normal_conv_output
=
conv2d_corr
(
img_var
,
kern_var
,
border_mode
=
self
.
border_mode
,
subsample
=
self
.
subsample
,
filter_dilation
=
self
.
filter_dilation
)
normal_func
=
theano
.
function
([
img_var
,
kern_var
],
normal_conv_output
,
mode
=
'FAST_RUN'
)
normal_concat_output
=
[
normal_func
(
img_arr
,
kern_arr
)
for
img_arr
,
kern_arr
in
zip
(
split_imgs
,
split_kern
)]
normal_concat_output
=
np
.
concatenate
(
normal_concat_output
,
axis
=
1
)
utt
.
assert_allclose
(
grouped_output
,
normal_concat_output
)
utt
.
verify_grad
(
grouped_abstractconv_func
,
[
img
,
kern
],
mode
=
self
.
mode
)
for
imshp
,
kshp
,
groups
in
zip
(
self
.
img_shape
,
self
.
kern_shape
,
self
.
num_groups
):
img
=
np
.
random
.
random
(
imshp
)
.
astype
(
'float32'
)
kern
=
np
.
random
.
random
(
kshp
)
.
astype
(
'float32'
)
split_imgs
=
np
.
split
(
img
,
groups
,
axis
=
1
)
split_kern
=
np
.
split
(
kern
,
groups
,
axis
=
0
)
img_sym
=
theano
.
tensor
.
tensor4
(
'img'
)
kern_sym
=
theano
.
tensor
.
tensor4
(
'kern'
)
grouped_abstractconv_func
=
self
.
conv2d
(
border_mode
=
self
.
border_mode
,
subsample
=
self
.
subsample
,
filter_dilation
=
self
.
filter_dilation
,
num_groups
=
groups
)
if
self
.
flip_filter
:
grouped_conv_output
=
grouped_abstractconv_func
(
img_sym
,
kern_sym
[:,
:,
::
-
1
,
::
-
1
])
else
:
grouped_conv_output
=
grouped_abstractconv_func
(
img_sym
,
kern_sym
)
grouped_func
=
theano
.
function
([
img_sym
,
kern_sym
],
grouped_conv_output
,
mode
=
self
.
mode
)
grouped_output
=
grouped_func
(
img
,
kern
)
normal_conv_output
=
conv2d_corr
(
img_sym
,
kern_sym
,
border_mode
=
self
.
border_mode
,
subsample
=
self
.
subsample
,
filter_dilation
=
self
.
filter_dilation
)
normal_func
=
theano
.
function
([
img_sym
,
kern_sym
],
normal_conv_output
,
mode
=
self
.
ref_mode
)
normal_concat_output
=
[
normal_func
(
img_arr
,
kern_arr
)
for
img_arr
,
kern_arr
in
zip
(
split_imgs
,
split_kern
)]
normal_concat_output
=
np
.
concatenate
(
normal_concat_output
,
axis
=
1
)
utt
.
assert_allclose
(
grouped_output
,
normal_concat_output
)
utt
.
verify_grad
(
grouped_abstractconv_func
,
[
img
,
kern
],
mode
=
self
.
mode
)
def
test_gradweights
(
self
):
img
=
np
.
random
.
random
(
self
.
img_shape
)
.
astype
(
'float32'
)
top
=
np
.
random
.
random
(
self
.
top_shape
)
.
astype
(
'float32'
)
split_imgs
=
np
.
split
(
img
,
self
.
num_groups
,
axis
=
1
)
split_top
=
np
.
split
(
top
,
self
.
num_groups
,
axis
=
1
)
img_var
=
theano
.
tensor
.
tensor4
(
'img'
)
top_var
=
theano
.
tensor
.
tensor4
(
'top'
)
grouped_abstractconvgrad_func
=
theano
.
tensor
.
nnet
.
abstract_conv
.
AbstractConv2d_gradWeights
(
imshp
=
None
,
kshp
=
None
,
border_mode
=
self
.
border_mode
,
subsample
=
self
.
subsample
,
filter_dilation
=
self
.
filter_dilation
,
num_groups
=
self
.
num_groups
)
grouped_conv_output
=
grouped_abstractconvgrad_func
(
img_var
,
top_var
,
self
.
kern_shape
[
-
2
:])
grouped_func
=
theano
.
function
([
img_var
,
top_var
],
grouped_conv_output
,
mode
=
self
.
mode
)
grouped_output
=
grouped_func
(
img
,
top
)
normal_conv_output
=
conv2d_corr_gw
(
img_var
,
top_var
,
self
.
kern_shape
,
border_mode
=
self
.
border_mode
,
subsample
=
self
.
subsample
,
filter_dilation
=
self
.
filter_dilation
)
normal_func
=
theano
.
function
([
img_var
,
top_var
],
normal_conv_output
,
mode
=
'FAST_RUN'
)
normal_concat_output
=
[
normal_func
(
img_arr
,
top_arr
)
for
img_arr
,
top_arr
in
zip
(
split_imgs
,
split_top
)]
normal_concat_output
=
np
.
concatenate
(
normal_concat_output
,
axis
=
0
)
utt
.
assert_allclose
(
grouped_output
,
normal_concat_output
)
def
abstract_conv_gradweight
(
inputs_val
,
output_val
):
return
grouped_abstractconvgrad_func
(
inputs_val
,
output_val
,
self
.
kern_shape
[
-
2
:])
for
imshp
,
kshp
,
tshp
,
groups
in
zip
(
self
.
img_shape
,
self
.
kern_shape
,
self
.
top_shape
,
self
.
num_groups
):
img
=
np
.
random
.
random
(
imshp
)
.
astype
(
'float32'
)
top
=
np
.
random
.
random
(
tshp
)
.
astype
(
'float32'
)
split_imgs
=
np
.
split
(
img
,
groups
,
axis
=
1
)
split_top
=
np
.
split
(
top
,
groups
,
axis
=
1
)
img_sym
=
theano
.
tensor
.
tensor4
(
'img'
)
top_sym
=
theano
.
tensor
.
tensor4
(
'top'
)
grouped_abstractconvgrad_func
=
self
.
conv2d_gradw
(
border_mode
=
self
.
border_mode
,
subsample
=
self
.
subsample
,
filter_dilation
=
self
.
filter_dilation
,
num_groups
=
groups
)
grouped_conv_output
=
grouped_abstractconvgrad_func
(
img_sym
,
top_sym
,
kshp
[
-
2
:])
if
self
.
flip_filter
:
grouped_conv_output
=
grouped_conv_output
[:,
:,
::
-
1
,
::
-
1
]
grouped_func
=
theano
.
function
([
img_sym
,
top_sym
],
grouped_conv_output
,
mode
=
self
.
mode
)
grouped_output
=
grouped_func
(
img
,
top
)
normal_conv_output
=
conv2d_corr_gw
(
img_sym
,
top_sym
,
kshp
,
border_mode
=
self
.
border_mode
,
subsample
=
self
.
subsample
,
filter_dilation
=
self
.
filter_dilation
)
normal_func
=
theano
.
function
([
img_sym
,
top_sym
],
normal_conv_output
,
mode
=
self
.
ref_mode
)
normal_concat_output
=
[
normal_func
(
img_arr
,
top_arr
)
for
img_arr
,
top_arr
in
zip
(
split_imgs
,
split_top
)]
normal_concat_output
=
np
.
concatenate
(
normal_concat_output
,
axis
=
0
)
utt
.
assert_allclose
(
grouped_output
,
normal_concat_output
)
def
abstract_conv_gradweight
(
inputs_val
,
output_val
):
return
grouped_abstractconvgrad_func
(
inputs_val
,
output_val
,
kshp
[
-
2
:])
utt
.
verify_grad
(
abstract_conv_gradweight
,
[
img
,
top
],
mode
=
self
.
mode
,
eps
=
1
)
utt
.
verify_grad
(
abstract_conv_gradweight
,
[
img
,
top
],
mode
=
self
.
mode
,
eps
=
1
)
def
test_gradinputs
(
self
):
kern
=
np
.
random
.
random
(
self
.
kern_shape
)
.
astype
(
'float32'
)
top
=
np
.
random
.
random
(
self
.
top_shape
)
.
astype
(
'float32'
)
split_kerns
=
np
.
split
(
kern
,
self
.
num_groups
,
axis
=
0
)
split_top
=
np
.
split
(
top
,
self
.
num_groups
,
axis
=
1
)
kern_var
=
theano
.
tensor
.
tensor4
(
'kern'
)
top_var
=
theano
.
tensor
.
tensor4
(
'top'
)
grouped_abstractconvgrad_func
=
theano
.
tensor
.
nnet
.
abstract_conv
.
AbstractConv2d_gradInputs
(
imshp
=
None
,
kshp
=
None
,
border_mode
=
self
.
border_mode
,
subsample
=
self
.
subsample
,
filter_dilation
=
self
.
filter_dilation
,
num_groups
=
self
.
num_groups
)
grouped_conv_output
=
grouped_abstractconvgrad_func
(
kern_var
,
top_var
,
self
.
img_shape
[
-
2
:])
grouped_func
=
theano
.
function
([
kern_var
,
top_var
],
grouped_conv_output
,
mode
=
self
.
mode
)
grouped_output
=
grouped_func
(
kern
,
top
)
normal_conv_output
=
conv2d_corr_gi
(
kern_var
,
top_var
,
self
.
img_shape
,
border_mode
=
self
.
border_mode
,
subsample
=
self
.
subsample
,
filter_dilation
=
self
.
filter_dilation
)
normal_func
=
theano
.
function
([
kern_var
,
top_var
],
normal_conv_output
,
mode
=
'FAST_RUN'
)
normal_concat_output
=
[
normal_func
(
kern_arr
,
top_arr
)
for
kern_arr
,
top_arr
in
zip
(
split_kerns
,
split_top
)]
normal_concat_output
=
np
.
concatenate
(
normal_concat_output
,
axis
=
1
)
utt
.
assert_allclose
(
grouped_output
,
normal_concat_output
)
def
abstract_conv_gradinputs
(
filters_val
,
output_val
):
return
grouped_abstractconvgrad_func
(
filters_val
,
output_val
,
self
.
img_shape
[
2
:])
for
imshp
,
kshp
,
tshp
,
groups
in
zip
(
self
.
img_shape
,
self
.
kern_shape
,
self
.
top_shape
,
self
.
num_groups
):
kern
=
np
.
random
.
random
(
kshp
)
.
astype
(
'float32'
)
top
=
np
.
random
.
random
(
tshp
)
.
astype
(
'float32'
)
split_kerns
=
np
.
split
(
kern
,
groups
,
axis
=
0
)
split_top
=
np
.
split
(
top
,
groups
,
axis
=
1
)
kern_sym
=
theano
.
tensor
.
tensor4
(
'kern'
)
top_sym
=
theano
.
tensor
.
tensor4
(
'top'
)
grouped_abstractconvgrad_func
=
self
.
conv2d_gradi
(
border_mode
=
self
.
border_mode
,
subsample
=
self
.
subsample
,
filter_dilation
=
self
.
filter_dilation
,
num_groups
=
groups
)
if
self
.
flip_filter
:
grouped_conv_output
=
grouped_abstractconvgrad_func
(
kern_sym
[:,
:,
::
-
1
,
::
-
1
],
top_sym
,
imshp
[
-
2
:])
else
:
grouped_conv_output
=
grouped_abstractconvgrad_func
(
kern_sym
,
top_sym
,
imshp
[
-
2
:])
grouped_func
=
theano
.
function
([
kern_sym
,
top_sym
],
grouped_conv_output
,
mode
=
self
.
mode
)
grouped_output
=
grouped_func
(
kern
,
top
)
normal_conv_output
=
conv2d_corr_gi
(
kern_sym
,
top_sym
,
imshp
,
border_mode
=
self
.
border_mode
,
subsample
=
self
.
subsample
,
filter_dilation
=
self
.
filter_dilation
)
normal_func
=
theano
.
function
([
kern_sym
,
top_sym
],
normal_conv_output
,
mode
=
self
.
ref_mode
)
normal_concat_output
=
[
normal_func
(
kern_arr
,
top_arr
)
for
kern_arr
,
top_arr
in
zip
(
split_kerns
,
split_top
)]
normal_concat_output
=
np
.
concatenate
(
normal_concat_output
,
axis
=
1
)
utt
.
assert_allclose
(
grouped_output
,
normal_concat_output
)
def
abstract_conv_gradinputs
(
filters_val
,
output_val
):
return
grouped_abstractconvgrad_func
(
filters_val
,
output_val
,
imshp
[
2
:])
utt
.
verify_grad
(
abstract_conv_gradinputs
,
[
kern
,
top
],
mode
=
self
.
mode
,
eps
=
1
)
utt
.
verify_grad
(
abstract_conv_gradinputs
,
[
kern
,
top
],
mode
=
self
.
mode
,
eps
=
1
)
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论