Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
c36a5ad8
提交
c36a5ad8
authored
6月 25, 2017
作者:
affanv14
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
make grouped convolution cudnn test inherit from abstractconv base test
上级
54663e8c
显示空白字符变更
内嵌
并排
正在显示
1 个修改的文件
包含
25 行增加
和
127 行删除
+25
-127
test_dnn.py
theano/gpuarray/tests/test_dnn.py
+25
-127
没有找到文件。
theano/gpuarray/tests/test_dnn.py
浏览文件 @
c36a5ad8
...
@@ -23,9 +23,9 @@ from ..type import gpuarray_shared_constructor
...
@@ -23,9 +23,9 @@ from ..type import gpuarray_shared_constructor
from
.config
import
mode_with_gpu
,
mode_without_gpu
,
test_ctx_name
,
ref_cast
from
.config
import
mode_with_gpu
,
mode_without_gpu
,
test_ctx_name
,
ref_cast
from
.
import
test_nnet
from
.
import
test_nnet
from
.rnn_support
import
Model
,
GRU
,
LSTM
,
WrapperLayer
from
.rnn_support
import
Model
,
GRU
,
LSTM
,
WrapperLayer
import
unittest
from
theano.configdefaults
import
SUPPORTED_DNN_CONV_ALGO_FWD
from
theano.configdefaults
import
SUPPORTED_DNN_CONV_ALGO_FWD
from
theano.tensor.nnet.tests.test_abstract_conv
import
Grouped_conv_noOptim
mode_with_gpu
=
mode_with_gpu
.
including
()
mode_with_gpu
=
mode_with_gpu
.
including
()
# Globally disabled for mode_without_gpu
# Globally disabled for mode_without_gpu
...
@@ -2134,134 +2134,32 @@ def test_dnn_rnn_lstm_grad_c():
...
@@ -2134,134 +2134,32 @@ def test_dnn_rnn_lstm_grad_c():
utt
.
assert_allclose
(
ref_grads_layer
[
j
],
g
)
utt
.
assert_allclose
(
ref_grads_layer
[
j
],
g
)
class
Cudnn_grouped_conv
(
unittest
.
TestCase
):
def
dconv2d
(
border_mode
,
subsample
,
filter_dilation
,
num_groups
):
def
setUp
(
self
):
def
dconv
(
img
,
kern
):
self
.
num_groups
=
[
3
,
2
,
4
,
4
]
return
dnn
.
dnn_conv
(
img
,
kern
,
border_mode
=
border_mode
,
subsample
=
subsample
,
dilation
=
filter_dilation
,
self
.
border_mode
=
'valid'
conv_mode
=
'conv'
,
direction_hint
=
'forward'
,
workmem
=
None
,
self
.
subsample
=
(
1
,
1
)
algo
=
None
,
precision
=
None
,
num_groups
=
num_groups
)
self
.
img_shape
=
[(
5
,
6
,
5
,
5
),
(
4
,
4
,
7
,
5
),
(
3
,
8
,
5
,
3
),
(
2
,
4
,
7
,
7
)]
return
dconv
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
=
mode_with_gpu
self
.
ref_mode
=
'FAST_RUN'
def
test_fwd
(
self
):
img_sym
=
theano
.
tensor
.
tensor4
(
'img'
)
kern_sym
=
theano
.
tensor
.
tensor4
(
'kern'
)
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
(
theano
.
config
.
floatX
)
kern
=
np
.
random
.
random
(
kshp
)
.
astype
(
theano
.
config
.
floatX
)
top
=
np
.
random
.
random
(
tshp
)
.
astype
(
theano
.
config
.
floatX
)
split_imgs
=
np
.
split
(
img
,
groups
,
axis
=
1
)
split_kern
=
np
.
split
(
kern
,
groups
,
axis
=
0
)
grouped_conv_op
=
dnn
.
dnn_conv
(
img_sym
,
kern_sym
,
border_mode
=
self
.
border_mode
,
subsample
=
self
.
subsample
,
dilation
=
self
.
filter_dilation
,
num_groups
=
groups
)
grouped_func
=
theano
.
function
([
img_sym
,
kern_sym
],
grouped_conv_op
,
mode
=
self
.
mode
)
grouped_output
=
grouped_func
(
img
,
kern
)
ref_conv_op
=
theano
.
tensor
.
nnet
.
corr
.
CorrMM
(
border_mode
=
self
.
border_mode
,
subsample
=
self
.
subsample
,
filter_dilation
=
self
.
filter_dilation
)(
img_sym
,
kern_sym
[:,
:,
::
-
1
,
::
-
1
])
ref_func
=
theano
.
function
([
img_sym
,
kern_sym
],
ref_conv_op
,
mode
=
self
.
ref_mode
)
ref_concat_output
=
[
ref_func
(
img_arr
,
kern_arr
)
for
img_arr
,
kern_arr
in
zip
(
split_imgs
,
split_kern
)]
ref_concat_output
=
np
.
concatenate
(
ref_concat_output
,
axis
=
1
)
utt
.
assert_allclose
(
grouped_output
,
ref_concat_output
)
def
dconv
(
img
,
kern
,
out
):
desc
=
dnn
.
GpuDnnConvDesc
(
border_mode
=
'valid'
,
subsample
=
(
1
,
1
),
dilation
=
(
1
,
1
),
conv_mode
=
'conv'
,
precision
=
set_precision
(
theano
.
config
.
floatX
))(
kern
.
shape
)
return
dnn
.
GpuDnnConv
(
num_groups
=
groups
)(
img
,
kern
,
out
,
desc
,
alpha
=
0.5
,
beta
=
0.75
)
utt
.
verify_grad
(
dconv
,
[
img
,
kern
,
top
],
eps
=
1e-3
,
mode
=
mode_with_gpu
)
def
test_gradweights
(
self
):
img_sym
=
theano
.
tensor
.
tensor4
(
'img'
)
top_sym
=
theano
.
tensor
.
tensor4
(
'top'
)
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
(
theano
.
config
.
floatX
)
kern
=
np
.
random
.
random
(
kshp
)
.
astype
(
theano
.
config
.
floatX
)
top
=
np
.
random
.
random
(
tshp
)
.
astype
(
theano
.
config
.
floatX
)
split_imgs
=
np
.
split
(
img
,
groups
,
axis
=
1
)
split_top
=
np
.
split
(
top
,
groups
,
axis
=
1
)
grouped_convgrad_op
=
dnn
.
dnn_gradweight
(
img_sym
,
top_sym
,
kshp
,
border_mode
=
self
.
border_mode
,
subsample
=
self
.
subsample
,
dilation
=
self
.
filter_dilation
,
num_groups
=
groups
)
grouped_func
=
theano
.
function
([
img_sym
,
top_sym
],
grouped_convgrad_op
,
mode
=
self
.
mode
)
grouped_output
=
grouped_func
(
img
,
top
)
ref_conv_op
=
theano
.
tensor
.
nnet
.
corr
.
CorrMM_gradWeights
(
border_mode
=
self
.
border_mode
,
subsample
=
self
.
subsample
,
filter_dilation
=
self
.
filter_dilation
)(
img_sym
,
top_sym
,
kshp
[
2
:])
ref_conv_op
=
ref_conv_op
[:,
:,
::
-
1
,
::
-
1
]
ref_func
=
theano
.
function
([
img_sym
,
top_sym
],
ref_conv_op
,
mode
=
self
.
ref_mode
)
ref_concat_output
=
[
ref_func
(
img_arr
,
top_arr
)
for
img_arr
,
top_arr
in
zip
(
split_imgs
,
split_top
)]
ref_concat_output
=
np
.
concatenate
(
ref_concat_output
,
axis
=
0
)
utt
.
assert_allclose
(
grouped_output
,
ref_concat_output
)
def
dconvw
(
img
,
kern
,
out
):
def
dconv2dw
(
border_mode
,
subsample
,
filter_dilation
,
num_groups
):
desc
=
dnn
.
GpuDnnConvDesc
(
border_mode
=
'valid'
,
subsample
=
(
1
,
1
),
dilation
=
(
1
,
1
),
def
dconvw
(
img
,
topgrad
,
kshp
):
conv_mode
=
'conv'
,
precision
=
set_precision
(
theano
.
config
.
floatX
))(
kern
.
shape
)
return
dnn
.
dnn_gradweight
(
img
,
topgrad
,
kshp
,
border_mode
=
border_mode
,
subsample
=
subsample
,
dilation
=
filter_dilation
,
return
dnn
.
GpuDnnConvGradW
(
num_groups
=
groups
)(
img
,
out
,
kern
,
desc
,
alpha
=
0.75
,
conv_mode
=
'conv'
,
precision
=
None
,
algo
=
None
,
num_groups
=
num_groups
)
beta
=-
1.0
)
return
dconvw
utt
.
verify_grad
(
dconvw
,
[
img
,
kern
,
top
],
eps
=
1e-3
,
mode
=
mode_with_gpu
)
def
test_gradinputs
(
self
):
kern_sym
=
theano
.
tensor
.
tensor4
(
'kern'
)
top_sym
=
theano
.
tensor
.
tensor4
(
'top'
)
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
(
theano
.
config
.
floatX
)
kern
=
np
.
random
.
random
(
kshp
)
.
astype
(
theano
.
config
.
floatX
)
top
=
np
.
random
.
random
(
tshp
)
.
astype
(
theano
.
config
.
floatX
)
split_kerns
=
np
.
split
(
kern
,
groups
,
axis
=
0
)
split_top
=
np
.
split
(
top
,
groups
,
axis
=
1
)
grouped_convgrad_op
=
dnn
.
dnn_gradinput
(
kern_sym
,
top_sym
,
imshp
,
border_mode
=
self
.
border_mode
,
subsample
=
self
.
subsample
,
dilation
=
self
.
filter_dilation
,
num_groups
=
groups
)
grouped_func
=
theano
.
function
([
kern_sym
,
top_sym
],
grouped_convgrad_op
,
mode
=
self
.
mode
)
grouped_output
=
grouped_func
(
kern
,
top
)
ref_conv_op
=
theano
.
tensor
.
nnet
.
corr
.
CorrMM_gradInputs
(
border_mode
=
self
.
border_mode
,
subsample
=
self
.
subsample
,
filter_dilation
=
self
.
filter_dilation
)(
kern_sym
[:,
:,
::
-
1
,
::
-
1
],
top_sym
,
imshp
[
2
:])
ref_func
=
theano
.
function
([
kern_sym
,
top_sym
],
ref_conv_op
,
mode
=
self
.
ref_mode
)
ref_concat_output
=
[
ref_func
(
kern_arr
,
top_arr
)
for
kern_arr
,
top_arr
in
zip
(
split_kerns
,
split_top
)]
ref_concat_output
=
np
.
concatenate
(
ref_concat_output
,
axis
=
1
)
utt
.
assert_allclose
(
grouped_output
,
ref_concat_output
)
def
dconvi
(
img
,
kern
,
out
):
def
dconv2di
(
border_mode
,
subsample
,
filter_dilation
,
num_groups
):
desc
=
dnn
.
GpuDnnConvDesc
(
border_mode
=
'valid'
,
subsample
=
(
1
,
1
),
dilation
=
(
1
,
1
),
def
dconvi
(
kern
,
topgrad
,
imshp
):
conv_mode
=
'conv'
,
precision
=
set_precision
(
theano
.
config
.
floatX
))(
kern
.
shape
)
return
dnn
.
dnn_gradinput
(
kern
,
topgrad
,
imshp
,
border_mode
=
border_mode
,
subsample
=
subsample
,
dilation
=
filter_dilation
,
return
dnn
.
GpuDnnConvGradI
(
num_groups
=
groups
)(
kern
,
out
,
img
,
desc
,
alpha
=-
1.0
,
conv_mode
=
'conv'
,
precision
=
None
,
algo
=
None
,
num_groups
=
num_groups
)
beta
=
0.0
)
return
dconvi
utt
.
verify_grad
(
dconvi
,
[
img
,
kern
,
top
],
eps
=
1e-3
,
mode
=
mode_with_gpu
)
class
Cudnn_grouped_conv
(
Grouped_conv_noOptim
):
mode
=
mode_with_gpu
conv2d
=
staticmethod
(
dconv2d
)
conv2d_gradw
=
staticmethod
(
dconv2dw
)
conv2d_gradi
=
staticmethod
(
dconv2di
)
flip_filter
=
False
is_dnn
=
True
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论