Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
d286cadb
提交
d286cadb
authored
11月 25, 2016
作者:
Gijs van Tulder
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
DnnConv grad ops in gpuarray backend check shape consistency.
上级
d01b5839
显示空白字符变更
内嵌
并排
正在显示
3 个修改的文件
包含
103 行增加
和
24 行删除
+103
-24
dnn_gi.c
theano/gpuarray/dnn_gi.c
+42
-0
dnn_gw.c
theano/gpuarray/dnn_gw.c
+42
-0
test_dnn.py
theano/gpuarray/tests/test_dnn.py
+19
-24
没有找到文件。
theano/gpuarray/dnn_gi.c
浏览文件 @
d286cadb
...
@@ -77,6 +77,48 @@ APPLY_SPECIFIC(conv_gi)(PyGpuArrayObject *kerns, PyGpuArrayObject *output,
...
@@ -77,6 +77,48 @@ APPLY_SPECIFIC(conv_gi)(PyGpuArrayObject *kerns, PyGpuArrayObject *output,
cuda_enter
(
c
->
ctx
);
cuda_enter
(
c
->
ctx
);
int
expected_output_dims
[
5
]
=
{
0
};
err
=
cudnnGetConvolutionNdForwardOutputDim
(
desc
,
APPLY_SPECIFIC
(
input
),
APPLY_SPECIFIC
(
kerns
),
PyGpuArray_NDIM
(
im
),
expected_output_dims
);
if
(
err
!=
CUDNN_STATUS_SUCCESS
)
{
PyErr_Format
(
PyExc_RuntimeError
,
"error computing convolution output dim: %s"
,
cudnnGetErrorString
(
err
));
cuda_exit
(
c
->
ctx
);
return
1
;
}
if
(
PyGpuArray_NDIM
(
im
)
==
4
)
{
if
((
PyGpuArray_DIMS
(
output
)[
0
]
!=
expected_output_dims
[
0
])
||
(
PyGpuArray_DIMS
(
output
)[
1
]
!=
expected_output_dims
[
1
])
||
(
PyGpuArray_DIMS
(
output
)[
2
]
!=
expected_output_dims
[
2
])
||
(
PyGpuArray_DIMS
(
output
)[
3
]
!=
expected_output_dims
[
3
]))
{
PyErr_Format
(
PyExc_ValueError
,
"impossible convolution output dim: expected %ldx%ldx%ldx%ld"
" but received gradient with shape %ldx%ldx%ldx%ld"
,
expected_output_dims
[
0
],
expected_output_dims
[
1
],
expected_output_dims
[
2
],
expected_output_dims
[
3
],
PyGpuArray_DIMS
(
output
)[
0
],
PyGpuArray_DIMS
(
output
)[
1
],
PyGpuArray_DIMS
(
output
)[
2
],
PyGpuArray_DIMS
(
output
)[
3
]);
cuda_exit
(
c
->
ctx
);
return
1
;
}
}
else
if
(
PyGpuArray_NDIM
(
im
)
==
5
)
{
if
((
PyGpuArray_DIMS
(
output
)[
0
]
!=
expected_output_dims
[
0
])
||
(
PyGpuArray_DIMS
(
output
)[
1
]
!=
expected_output_dims
[
1
])
||
(
PyGpuArray_DIMS
(
output
)[
2
]
!=
expected_output_dims
[
2
])
||
(
PyGpuArray_DIMS
(
output
)[
3
]
!=
expected_output_dims
[
3
])
||
(
PyGpuArray_DIMS
(
output
)[
4
]
!=
expected_output_dims
[
4
]))
{
PyErr_Format
(
PyExc_ValueError
,
"impossible convolution output dim: expected %ldx%ldx%ldx%ldx%ld"
" but received gradient with shape %ldx%ldx%ldx%ldx%ld"
,
expected_output_dims
[
0
],
expected_output_dims
[
1
],
expected_output_dims
[
2
],
expected_output_dims
[
3
],
expected_output_dims
[
4
],
PyGpuArray_DIMS
(
output
)[
0
],
PyGpuArray_DIMS
(
output
)[
1
],
PyGpuArray_DIMS
(
output
)[
2
],
PyGpuArray_DIMS
(
output
)[
3
],
PyGpuArray_DIMS
(
output
)[
4
]);
cuda_exit
(
c
->
ctx
);
return
1
;
}
}
#ifdef CHOOSE_ALGO
#ifdef CHOOSE_ALGO
#ifndef CHOOSE_ONCE
#ifndef CHOOSE_ONCE
reuse_algo
=
1
;
reuse_algo
=
1
;
...
...
theano/gpuarray/dnn_gw.c
浏览文件 @
d286cadb
...
@@ -77,6 +77,48 @@ APPLY_SPECIFIC(conv_gw)(PyGpuArrayObject *input, PyGpuArrayObject *output,
...
@@ -77,6 +77,48 @@ APPLY_SPECIFIC(conv_gw)(PyGpuArrayObject *input, PyGpuArrayObject *output,
cuda_enter
(
c
->
ctx
);
cuda_enter
(
c
->
ctx
);
int
expected_output_dims
[
5
]
=
{
0
};
err
=
cudnnGetConvolutionNdForwardOutputDim
(
desc
,
APPLY_SPECIFIC
(
input
),
APPLY_SPECIFIC
(
kerns
),
PyGpuArray_NDIM
(
input
),
expected_output_dims
);
if
(
err
!=
CUDNN_STATUS_SUCCESS
)
{
PyErr_Format
(
PyExc_RuntimeError
,
"error computing convolution output dim: %s"
,
cudnnGetErrorString
(
err
));
cuda_exit
(
c
->
ctx
);
return
1
;
}
if
(
PyGpuArray_NDIM
(
input
)
==
4
)
{
if
((
PyGpuArray_DIMS
(
output
)[
0
]
!=
expected_output_dims
[
0
])
||
(
PyGpuArray_DIMS
(
output
)[
1
]
!=
expected_output_dims
[
1
])
||
(
PyGpuArray_DIMS
(
output
)[
2
]
!=
expected_output_dims
[
2
])
||
(
PyGpuArray_DIMS
(
output
)[
3
]
!=
expected_output_dims
[
3
]))
{
PyErr_Format
(
PyExc_ValueError
,
"impossible convolution output dim: expected %ldx%ldx%dx%ld"
" but received gradient with shape %ldx%ldx%dx%ld"
,
expected_output_dims
[
0
],
expected_output_dims
[
1
],
expected_output_dims
[
2
],
expected_output_dims
[
3
],
PyGpuArray_DIMS
(
output
)[
0
],
PyGpuArray_DIMS
(
output
)[
1
],
PyGpuArray_DIMS
(
output
)[
2
],
PyGpuArray_DIMS
(
output
)[
3
]);
cuda_exit
(
c
->
ctx
);
return
1
;
}
}
else
if
(
PyGpuArray_NDIM
(
input
)
==
5
)
{
if
((
PyGpuArray_DIMS
(
output
)[
0
]
!=
expected_output_dims
[
0
])
||
(
PyGpuArray_DIMS
(
output
)[
1
]
!=
expected_output_dims
[
1
])
||
(
PyGpuArray_DIMS
(
output
)[
2
]
!=
expected_output_dims
[
2
])
||
(
PyGpuArray_DIMS
(
output
)[
3
]
!=
expected_output_dims
[
3
])
||
(
PyGpuArray_DIMS
(
output
)[
4
]
!=
expected_output_dims
[
4
]))
{
PyErr_Format
(
PyExc_ValueError
,
"impossible convolution output dim: expected %ldx%ldx%ldx%ldx%ld"
" but received gradient with shape %ldx%ldx%ldx%ldx%ld"
,
expected_output_dims
[
0
],
expected_output_dims
[
1
],
expected_output_dims
[
2
],
expected_output_dims
[
3
],
expected_output_dims
[
4
],
PyGpuArray_DIMS
(
output
)[
0
],
PyGpuArray_DIMS
(
output
)[
1
],
PyGpuArray_DIMS
(
output
)[
2
],
PyGpuArray_DIMS
(
output
)[
3
],
PyGpuArray_DIMS
(
output
)[
4
]);
cuda_exit
(
c
->
ctx
);
return
1
;
}
}
#ifdef CHOOSE_ALGO
#ifdef CHOOSE_ALGO
#ifndef CHOOSE_ONCE
#ifndef CHOOSE_ONCE
reuse_algo
=
1
;
reuse_algo
=
1
;
...
...
theano/gpuarray/tests/test_dnn.py
浏览文件 @
d286cadb
...
@@ -12,6 +12,7 @@ import theano.tensor as T
...
@@ -12,6 +12,7 @@ import theano.tensor as T
import
theano.tests.unittest_tools
as
utt
import
theano.tests.unittest_tools
as
utt
from
theano.tensor.signal.pool
import
pool_2d
,
pool_3d
from
theano.tensor.signal.pool
import
pool_2d
,
pool_3d
from
theano.tensor.signal.pool
import
Pool
,
MaxPoolGrad
,
AveragePoolGrad
from
theano.tensor.signal.pool
import
Pool
,
MaxPoolGrad
,
AveragePoolGrad
from
theano.tensor.nnet.abstract_conv
import
get_conv_output_shape
from
..
import
dnn
from
..
import
dnn
from
..basic_ops
import
GpuAllocEmpty
from
..basic_ops
import
GpuAllocEmpty
...
@@ -628,56 +629,50 @@ class TestDnnInferShapes(utt.InferShapeTester):
...
@@ -628,56 +629,50 @@ class TestDnnInferShapes(utt.InferShapeTester):
[(
1
,
1
,
1
),
(
2
,
2
,
2
)],
[(
1
,
1
,
1
),
(
2
,
2
,
2
)],
'none'
)
'none'
)
def
_test_conv_gradw
(
self
,
img
,
kerns
,
out
,
img_val
,
kern_vals
,
border_mode
,
conv_mode
,
subsample
):
def
_test_conv_gradw
(
self
,
img
,
topgrad
,
kerns
,
img_shape
,
kerns_shape
,
border_mode
,
conv_mode
,
subsample
):
if
not
dnn
.
dnn_available
(
test_ctx_name
):
if
not
dnn
.
dnn_available
(
test_ctx_name
):
raise
SkipTest
(
dnn
.
dnn_available
.
msg
)
raise
SkipTest
(
dnn
.
dnn_available
.
msg
)
topgrad_shape
=
get_conv_output_shape
(
img_shape
,
kerns_shape
,
border_mode
,
subsample
)
img_val
=
numpy
.
asarray
(
img_val
=
numpy
.
asarray
(
img_val
,
numpy
.
random
.
rand
(
*
img_shape
)
,
dtype
=
theano
.
config
.
floatX
dtype
=
theano
.
config
.
floatX
)
)
kern
_vals
=
numpy
.
asarray
(
topgrad
_vals
=
numpy
.
asarray
(
kern_vals
,
numpy
.
random
.
rand
(
*
topgrad_shape
)
,
dtype
=
theano
.
config
.
floatX
dtype
=
theano
.
config
.
floatX
)
)
temp_img
=
img
.
dimshuffle
(
1
,
0
,
2
,
3
)
kerns_vals
=
numpy
.
zeros
(
kerns_shape
,
dtype
=
theano
.
config
.
floatX
)
temp_kerns
=
kerns
kerns_shape
=
theano
.
shared
(
numpy
.
asarray
(
kerns_shape
))
if
conv_mode
==
'conv'
:
temp_kerns
=
temp_kerns
[:,
:,
::
-
1
,
::
-
1
]
temp_kerns
=
temp_kerns
.
dimshuffle
(
1
,
0
,
2
,
3
)
shape
=
(
kern_vals
.
shape
[
1
],
img_val
.
shape
[
1
],
img_val
.
shape
[
2
]
-
kern_vals
.
shape
[
2
]
+
1
,
img_val
.
shape
[
3
]
-
kern_vals
.
shape
[
3
]
+
1
)
out_vals
=
numpy
.
zeros
(
shape
,
dtype
=
theano
.
config
.
floatX
)
desc
=
dnn
.
GpuDnnConvDesc
(
desc
=
dnn
.
GpuDnnConvDesc
(
border_mode
=
border_mode
,
border_mode
=
border_mode
,
subsample
=
subsample
,
subsample
=
subsample
,
conv_mode
=
conv_mode
,
conv_mode
=
conv_mode
,
precision
=
set_precision
(
theano
.
config
.
floatX
)
precision
=
set_precision
(
theano
.
config
.
floatX
)
)(
out
.
shape
)
)(
kerns_
shape
)
conv_grad_w
=
dnn
.
GpuDnnConvGradW
()(
conv_grad_w
=
dnn
.
GpuDnnConvGradW
()(
temp_
img
,
img
,
t
emp_kerns
,
t
opgrad
,
out
,
kerns
,
desc
,
desc
,
)
)
self
.
_compile_and_check
(
self
.
_compile_and_check
(
[
temp_img
,
temp_kerns
,
out
],
[
img
,
topgrad
,
kerns
],
[
conv_grad_w
],
[
conv_grad_w
],
[
img_val
,
kern_vals
,
out
_vals
],
[
img_val
,
topgrad_vals
,
kerns
_vals
],
dnn
.
GpuDnnConvGradW
dnn
.
GpuDnnConvGradW
)
)
@parameterized.expand
(
product
(
border_modes
,
conv_modes
),
utt
.
custom_name_func
)
@parameterized.expand
(
product
(
border_modes
,
conv_modes
),
utt
.
custom_name_func
)
def
test_conv_gradw
(
self
,
border_mode
,
conv_mode
):
def
test_conv_gradw
(
self
,
border_mode
,
conv_mode
):
self
.
_test_conv_gradw
(
T
.
tensor4
(
'img'
),
self
.
_test_conv_gradw
(
T
.
tensor4
(
'img'
),
T
.
tensor4
(
'topgrad'
),
T
.
tensor4
(
'kerns'
),
T
.
tensor4
(
'kerns'
),
T
.
tensor4
(
'out'
),
(
5
,
2
,
6
,
13
),
numpy
.
random
.
rand
(
2
,
5
,
6
,
8
),
(
1
,
2
,
3
,
7
),
numpy
.
random
.
rand
(
2
,
1
,
5
,
6
),
border_mode
,
border_mode
,
conv_mode
,
conv_mode
,
(
1
,
1
))
(
1
,
1
))
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论