Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
beded2b3
提交
beded2b3
authored
11月 30, 2016
作者:
Gijs van Tulder
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Check shape of cuDNN convolution result.
上级
65798698
隐藏空白字符变更
内嵌
并排
正在显示
4 个修改的文件
包含
98 行增加
和
38 行删除
+98
-38
dnn.py
theano/gpuarray/dnn.py
+30
-23
dnn.py
theano/sandbox/cuda/dnn.py
+23
-14
abstract_conv.py
theano/tensor/nnet/abstract_conv.py
+29
-0
test_abstract_conv.py
theano/tensor/nnet/tests/test_abstract_conv.py
+16
-1
没有找到文件。
theano/gpuarray/dnn.py
浏览文件 @
beded2b3
...
@@ -24,7 +24,8 @@ from theano.tensor.nnet.abstract_conv import (AbstractConv2d,
...
@@ -24,7 +24,8 @@ from theano.tensor.nnet.abstract_conv import (AbstractConv2d,
AbstractConv3d
,
AbstractConv3d
,
AbstractConv3d_gradWeights
,
AbstractConv3d_gradWeights
,
AbstractConv3d_gradInputs
,
AbstractConv3d_gradInputs
,
get_conv_output_shape
)
get_conv_output_shape
,
assert_conv_shape
)
from
theano.tensor.signal.pool
import
(
from
theano.tensor.signal.pool
import
(
Pool
,
MaxPoolGrad
,
AveragePoolGrad
)
Pool
,
MaxPoolGrad
,
AveragePoolGrad
)
from
.
import
pygpu
from
.
import
pygpu
...
@@ -978,11 +979,12 @@ def dnn_conv(img, kerns, border_mode='valid', subsample=(1, 1),
...
@@ -978,11 +979,12 @@ def dnn_conv(img, kerns, border_mode='valid', subsample=(1, 1),
# that would be flipped by conv_mode='conv' in GpuDnnConvGradW.
# that would be flipped by conv_mode='conv' in GpuDnnConvGradW.
kerns
=
kerns
[:,
:,
::
-
1
,
::
-
1
]
kerns
=
kerns
[:,
:,
::
-
1
,
::
-
1
]
kerns
=
gpu_contiguous
(
kerns
.
dimshuffle
(
1
,
0
,
2
,
3
))
kerns
=
gpu_contiguous
(
kerns
.
dimshuffle
(
1
,
0
,
2
,
3
))
shape2
=
shape_i
(
img
,
2
,
fgraph
)
-
shape_i
(
kerns
,
2
,
fgraph
)
+
1
out_shp
=
(
shape_i
(
kerns
,
1
,
fgraph
),
shape3
=
shape_i
(
img
,
3
,
fgraph
)
-
shape_i
(
kerns
,
3
,
fgraph
)
+
1
shape_i
(
img
,
1
,
fgraph
),
out
=
gpu_alloc_empty
(
ctx_name
,
dtype
=
img
.
dtype
)(
shape_i
(
img
,
2
,
fgraph
)
-
shape_i
(
kerns
,
2
,
fgraph
)
+
1
,
shape_i
(
kerns
,
1
,
fgraph
),
shape_i
(
img
,
3
,
fgraph
)
-
shape_i
(
kerns
,
3
,
fgraph
)
+
1
)
shape_i
(
img
,
1
,
fgraph
),
shape2
,
shape3
)
out_shp
=
assert_conv_shape
(
out_shp
)
out
=
gpu_alloc_empty
(
ctx_name
,
dtype
=
img
.
dtype
)(
*
out_shp
)
desc
=
GpuDnnConvDesc
(
border_mode
=
'valid'
,
subsample
=
(
1
,
1
),
desc
=
GpuDnnConvDesc
(
border_mode
=
'valid'
,
subsample
=
(
1
,
1
),
conv_mode
=
'cross'
,
precision
=
precision
)(
out
.
shape
)
conv_mode
=
'cross'
,
precision
=
precision
)(
out
.
shape
)
conv
=
gpu_dnn_conv_gradW
()(
img
,
kerns
,
out
,
desc
)
conv
=
gpu_dnn_conv_gradW
()(
img
,
kerns
,
out
,
desc
)
...
@@ -996,11 +998,12 @@ def dnn_conv(img, kerns, border_mode='valid', subsample=(1, 1),
...
@@ -996,11 +998,12 @@ def dnn_conv(img, kerns, border_mode='valid', subsample=(1, 1),
img
=
gpu_contiguous
(
img
)
# cudnn v2 rc3 need contiguous data
img
=
gpu_contiguous
(
img
)
# cudnn v2 rc3 need contiguous data
kerns
=
gpu_contiguous
(
kerns
.
dimshuffle
(
1
,
0
,
2
,
3
))
kerns
=
gpu_contiguous
(
kerns
.
dimshuffle
(
1
,
0
,
2
,
3
))
conv_mode
=
'cross'
if
conv_mode
==
'conv'
else
'conv'
conv_mode
=
'cross'
if
conv_mode
==
'conv'
else
'conv'
shape2
=
shape_i
(
img
,
2
,
fgraph
)
+
shape_i
(
kerns
,
2
,
fgraph
)
-
1
out_shp
=
(
shape_i
(
img
,
0
,
fgraph
),
shape3
=
shape_i
(
img
,
3
,
fgraph
)
+
shape_i
(
kerns
,
3
,
fgraph
)
-
1
shape_i
(
kerns
,
1
,
fgraph
),
out
=
gpu_alloc_empty
(
ctx_name
,
dtype
=
img
.
dtype
)(
shape_i
(
img
,
0
,
fgraph
),
shape_i
(
img
,
2
,
fgraph
)
+
shape_i
(
kerns
,
2
,
fgraph
)
-
1
,
shape_i
(
kerns
,
1
,
fgraph
),
shape_i
(
img
,
3
,
fgraph
)
+
shape_i
(
kerns
,
3
,
fgraph
)
-
1
)
shape2
,
shape3
)
out_shp
=
assert_conv_shape
(
out_shp
)
out
=
gpu_alloc_empty
(
ctx_name
,
dtype
=
img
.
dtype
)(
*
out_shp
)
desc
=
GpuDnnConvDesc
(
border_mode
=
'valid'
,
subsample
=
(
1
,
1
),
desc
=
GpuDnnConvDesc
(
border_mode
=
'valid'
,
subsample
=
(
1
,
1
),
conv_mode
=
conv_mode
,
precision
=
precision
)(
kerns
.
shape
)
conv_mode
=
conv_mode
,
precision
=
precision
)(
kerns
.
shape
)
return
gpu_dnn_conv_gradI
()(
kerns
,
img
,
out
,
desc
)
return
gpu_dnn_conv_gradI
()(
kerns
,
img
,
out
,
desc
)
...
@@ -1020,6 +1023,7 @@ def dnn_conv(img, kerns, border_mode='valid', subsample=(1, 1),
...
@@ -1020,6 +1023,7 @@ def dnn_conv(img, kerns, border_mode='valid', subsample=(1, 1),
out_shp
=
get_conv_output_shape
(
ishape
,
kshape
,
out_shp
=
get_conv_output_shape
(
ishape
,
kshape
,
desc_op
.
border_mode
,
desc_op
.
border_mode
,
desc_op
.
subsample
)
desc_op
.
subsample
)
out_shp
=
assert_conv_shape
(
out_shp
)
out
=
gpu_alloc_empty
(
ctx_name
,
dtype
=
img
.
dtype
)(
*
out_shp
)
out
=
gpu_alloc_empty
(
ctx_name
,
dtype
=
img
.
dtype
)(
*
out_shp
)
return
gpu_dnn_conv
(
algo
=
algo
)(
img
,
kerns
,
out
,
desc
)
return
gpu_dnn_conv
(
algo
=
algo
)(
img
,
kerns
,
out
,
desc
)
...
@@ -1092,12 +1096,13 @@ def dnn_conv3d(img, kerns, border_mode='valid', subsample=(1, 1, 1),
...
@@ -1092,12 +1096,13 @@ def dnn_conv3d(img, kerns, border_mode='valid', subsample=(1, 1, 1),
# that would be flipped by conv_mode='conv' in GpuDnnConvGradW.
# that would be flipped by conv_mode='conv' in GpuDnnConvGradW.
kerns
=
kerns
[:,
:,
::
-
1
,
::
-
1
]
kerns
=
kerns
[:,
:,
::
-
1
,
::
-
1
]
kerns
=
gpu_contiguous
(
kerns
.
dimshuffle
(
1
,
0
,
2
,
3
,
4
))
kerns
=
gpu_contiguous
(
kerns
.
dimshuffle
(
1
,
0
,
2
,
3
,
4
))
shape2
=
shape_i
(
img
,
2
,
fgraph
)
-
shape_i
(
kerns
,
2
,
fgraph
)
+
1
out_shp
=
(
shape_i
(
kerns
,
1
,
fgraph
),
shape3
=
shape_i
(
img
,
3
,
fgraph
)
-
shape_i
(
kerns
,
3
,
fgraph
)
+
1
shape_i
(
img
,
1
,
fgraph
),
shape4
=
shape_i
(
img
,
4
,
fgraph
)
-
shape_i
(
kerns
,
4
,
fgraph
)
+
1
shape_i
(
img
,
2
,
fgraph
)
-
shape_i
(
kerns
,
2
,
fgraph
)
+
1
,
out
=
gpu_alloc_empty
(
ctx_name
,
dtype
=
img
.
dtype
)(
shape_i
(
img
,
3
,
fgraph
)
-
shape_i
(
kerns
,
3
,
fgraph
)
+
1
,
shape_i
(
kerns
,
1
,
fgraph
),
shape_i
(
img
,
4
,
fgraph
)
-
shape_i
(
kerns
,
4
,
fgraph
)
+
1
)
shape_i
(
img
,
1
,
fgraph
),
shape2
,
shape3
,
shape4
)
out_shp
=
assert_conv_shape
(
out_shp
)
out
=
gpu_alloc_empty
(
ctx_name
,
dtype
=
img
.
dtype
)(
*
out_shp
)
desc
=
GpuDnnConvDesc
(
border_mode
=
'valid'
,
subsample
=
(
1
,
1
,
1
),
desc
=
GpuDnnConvDesc
(
border_mode
=
'valid'
,
subsample
=
(
1
,
1
,
1
),
conv_mode
=
'cross'
,
precision
=
precision
)(
out
.
shape
)
conv_mode
=
'cross'
,
precision
=
precision
)(
out
.
shape
)
conv
=
gpu_dnn_conv_gradW
()(
img
,
kerns
,
out
,
desc
)
conv
=
gpu_dnn_conv_gradW
()(
img
,
kerns
,
out
,
desc
)
...
@@ -1111,12 +1116,13 @@ def dnn_conv3d(img, kerns, border_mode='valid', subsample=(1, 1, 1),
...
@@ -1111,12 +1116,13 @@ def dnn_conv3d(img, kerns, border_mode='valid', subsample=(1, 1, 1),
img
=
gpu_contiguous
(
img
)
# cudnn v2 rc3 need contiguous data
img
=
gpu_contiguous
(
img
)
# cudnn v2 rc3 need contiguous data
kerns
=
gpu_contiguous
(
kerns
.
dimshuffle
(
1
,
0
,
2
,
3
,
4
))
kerns
=
gpu_contiguous
(
kerns
.
dimshuffle
(
1
,
0
,
2
,
3
,
4
))
conv_mode
=
'cross'
if
conv_mode
==
'conv'
else
'conv'
conv_mode
=
'cross'
if
conv_mode
==
'conv'
else
'conv'
shape2
=
shape_i
(
img
,
2
,
fgraph
)
+
shape_i
(
kerns
,
2
,
fgraph
)
-
1
out_shp
=
(
shape_i
(
img
,
0
,
fgraph
),
shape3
=
shape_i
(
img
,
3
,
fgraph
)
+
shape_i
(
kerns
,
3
,
fgraph
)
-
1
shape_i
(
kerns
,
1
,
fgraph
),
shape4
=
shape_i
(
img
,
4
,
fgraph
)
+
shape_i
(
kerns
,
4
,
fgraph
)
-
1
shape_i
(
img
,
2
,
fgraph
)
+
shape_i
(
kerns
,
2
,
fgraph
)
-
1
,
out
=
gpu_alloc_empty
(
ctx_name
,
dtype
=
img
.
dtype
)(
shape_i
(
img
,
0
,
fgraph
),
shape_i
(
img
,
3
,
fgraph
)
+
shape_i
(
kerns
,
3
,
fgraph
)
-
1
,
shape_i
(
kerns
,
1
,
fgraph
),
shape_i
(
img
,
4
,
fgraph
)
+
shape_i
(
kerns
,
4
,
fgraph
)
-
1
)
shape2
,
shape3
,
shape4
)
out_shp
=
assert_conv_shape
(
out_shp
)
out
=
gpu_alloc_empty
(
ctx_name
,
dtype
=
img
.
dtype
)(
*
out_shp
)
desc
=
GpuDnnConvDesc
(
border_mode
=
'valid'
,
subsample
=
(
1
,
1
,
1
),
desc
=
GpuDnnConvDesc
(
border_mode
=
'valid'
,
subsample
=
(
1
,
1
,
1
),
conv_mode
=
conv_mode
,
precision
=
precision
)(
kerns
.
shape
)
conv_mode
=
conv_mode
,
precision
=
precision
)(
kerns
.
shape
)
return
gpu_dnn_conv_gradI
()(
kerns
,
img
,
out
,
desc
)
return
gpu_dnn_conv_gradI
()(
kerns
,
img
,
out
,
desc
)
...
@@ -1136,6 +1142,7 @@ def dnn_conv3d(img, kerns, border_mode='valid', subsample=(1, 1, 1),
...
@@ -1136,6 +1142,7 @@ def dnn_conv3d(img, kerns, border_mode='valid', subsample=(1, 1, 1),
out_shp
=
get_conv_output_shape
(
ishape
,
kshape
,
out_shp
=
get_conv_output_shape
(
ishape
,
kshape
,
desc_op
.
border_mode
,
desc_op
.
border_mode
,
desc_op
.
subsample
)
desc_op
.
subsample
)
out_shp
=
assert_conv_shape
(
out_shp
)
out
=
gpu_alloc_empty
(
ctx_name
,
dtype
=
img
.
dtype
)(
*
out_shp
)
out
=
gpu_alloc_empty
(
ctx_name
,
dtype
=
img
.
dtype
)(
*
out_shp
)
return
gpu_dnn_conv
(
algo
=
algo
)(
img
,
kerns
,
out
,
desc
)
return
gpu_dnn_conv
(
algo
=
algo
)(
img
,
kerns
,
out
,
desc
)
...
...
theano/sandbox/cuda/dnn.py
浏览文件 @
beded2b3
...
@@ -14,7 +14,8 @@ from theano.gof.type import CDataType
...
@@ -14,7 +14,8 @@ from theano.gof.type import CDataType
from
theano.compile
import
optdb
from
theano.compile
import
optdb
from
theano.compile.ops
import
shape_i
from
theano.compile.ops
import
shape_i
from
theano.tensor.nnet
import
LogSoftmax
,
SoftmaxGrad
from
theano.tensor.nnet
import
LogSoftmax
,
SoftmaxGrad
from
theano.tensor.nnet.abstract_conv
import
get_conv_output_shape
from
theano.tensor.nnet.abstract_conv
import
(
get_conv_output_shape
,
assert_conv_shape
)
from
theano.tensor.signal.pool
import
(
from
theano.tensor.signal.pool
import
(
Pool
,
MaxPoolGrad
,
AveragePoolGrad
)
Pool
,
MaxPoolGrad
,
AveragePoolGrad
)
from
theano.sandbox.cuda.type
import
CudaNdarrayType
from
theano.sandbox.cuda.type
import
CudaNdarrayType
...
@@ -1132,10 +1133,12 @@ def dnn_conv(img, kerns, border_mode='valid', subsample=(1, 1),
...
@@ -1132,10 +1133,12 @@ def dnn_conv(img, kerns, border_mode='valid', subsample=(1, 1),
# that would be flipped by conv_mode='conv' in GpuDnnConvGradW.
# that would be flipped by conv_mode='conv' in GpuDnnConvGradW.
kerns
=
kerns
[:,
:,
::
-
1
,
::
-
1
]
kerns
=
kerns
[:,
:,
::
-
1
,
::
-
1
]
kerns
=
gpu_contiguous
(
kerns
.
dimshuffle
(
1
,
0
,
2
,
3
))
kerns
=
gpu_contiguous
(
kerns
.
dimshuffle
(
1
,
0
,
2
,
3
))
shape2
=
shape_i
(
img
,
2
,
fgraph
)
-
shape_i
(
kerns
,
2
,
fgraph
)
+
1
out_shp
=
(
shape_i
(
kerns
,
1
,
fgraph
),
shape3
=
shape_i
(
img
,
3
,
fgraph
)
-
shape_i
(
kerns
,
3
,
fgraph
)
+
1
shape_i
(
img
,
1
,
fgraph
),
out
=
gpu_alloc_empty
(
shape_i
(
kerns
,
1
,
fgraph
),
shape_i
(
img
,
2
,
fgraph
)
-
shape_i
(
kerns
,
2
,
fgraph
)
+
1
,
shape_i
(
img
,
1
,
fgraph
),
shape2
,
shape3
)
shape_i
(
img
,
3
,
fgraph
)
-
shape_i
(
kerns
,
3
,
fgraph
)
+
1
)
out_shp
=
assert_conv_shape
(
out_shp
)
out
=
gpu_alloc_empty
(
*
out_shp
)
desc
=
GpuDnnConvDesc
(
border_mode
=
'valid'
,
subsample
=
(
1
,
1
),
desc
=
GpuDnnConvDesc
(
border_mode
=
'valid'
,
subsample
=
(
1
,
1
),
conv_mode
=
'cross'
,
precision
=
precision
)(
img
.
shape
,
conv_mode
=
'cross'
,
precision
=
precision
)(
img
.
shape
,
out
.
shape
)
out
.
shape
)
...
@@ -1149,10 +1152,12 @@ def dnn_conv(img, kerns, border_mode='valid', subsample=(1, 1),
...
@@ -1149,10 +1152,12 @@ def dnn_conv(img, kerns, border_mode='valid', subsample=(1, 1),
img
=
gpu_contiguous
(
img
)
img
=
gpu_contiguous
(
img
)
kerns
=
gpu_contiguous
(
kerns
.
dimshuffle
(
1
,
0
,
2
,
3
))
kerns
=
gpu_contiguous
(
kerns
.
dimshuffle
(
1
,
0
,
2
,
3
))
conv_mode
=
'cross'
if
conv_mode
==
'conv'
else
'conv'
conv_mode
=
'cross'
if
conv_mode
==
'conv'
else
'conv'
shape2
=
shape_i
(
img
,
2
,
fgraph
)
+
shape_i
(
kerns
,
2
,
fgraph
)
-
1
out_shp
=
(
shape_i
(
img
,
0
,
fgraph
),
shape3
=
shape_i
(
img
,
3
,
fgraph
)
+
shape_i
(
kerns
,
3
,
fgraph
)
-
1
shape_i
(
kerns
,
1
,
fgraph
),
out
=
gpu_alloc_empty
(
shape_i
(
img
,
0
,
fgraph
),
shape_i
(
img
,
2
,
fgraph
)
+
shape_i
(
kerns
,
2
,
fgraph
)
-
1
,
shape_i
(
kerns
,
1
,
fgraph
),
shape2
,
shape3
)
shape_i
(
img
,
3
,
fgraph
)
+
shape_i
(
kerns
,
3
,
fgraph
)
-
1
)
out_shp
=
assert_conv_shape
(
out_shp
)
out
=
gpu_alloc_empty
(
*
out_shp
)
desc
=
GpuDnnConvDesc
(
border_mode
=
'valid'
,
subsample
=
(
1
,
1
),
desc
=
GpuDnnConvDesc
(
border_mode
=
'valid'
,
subsample
=
(
1
,
1
),
conv_mode
=
conv_mode
,
precision
=
precision
)(
out
.
shape
,
conv_mode
=
conv_mode
,
precision
=
precision
)(
out
.
shape
,
kerns
.
shape
)
kerns
.
shape
)
...
@@ -1170,6 +1175,7 @@ def dnn_conv(img, kerns, border_mode='valid', subsample=(1, 1),
...
@@ -1170,6 +1175,7 @@ def dnn_conv(img, kerns, border_mode='valid', subsample=(1, 1),
out_shp
=
GpuDnnConv
.
get_out_shape
(
img
.
shape
,
kerns
.
shape
,
out_shp
=
GpuDnnConv
.
get_out_shape
(
img
.
shape
,
kerns
.
shape
,
desc_op
.
border_mode
,
desc_op
.
border_mode
,
desc_op
.
subsample
)
desc_op
.
subsample
)
out_shp
=
assert_conv_shape
(
out_shp
)
out
=
gpu_alloc_empty
(
*
out_shp
)
out
=
gpu_alloc_empty
(
*
out_shp
)
return
GpuDnnConv
(
algo
=
algo
)(
img
,
kerns
,
out
,
desc
)
return
GpuDnnConv
(
algo
=
algo
)(
img
,
kerns
,
out
,
desc
)
...
@@ -1248,11 +1254,13 @@ def dnn_conv3d(img, kerns, border_mode='valid', subsample=(1, 1, 1),
...
@@ -1248,11 +1254,13 @@ def dnn_conv3d(img, kerns, border_mode='valid', subsample=(1, 1, 1),
# that would be flipped by conv_mode='conv' in GpuDnnConvGradW.
# that would be flipped by conv_mode='conv' in GpuDnnConvGradW.
kerns
=
kerns
[:,
:,
::
-
1
,
::
-
1
,
::
-
1
]
kerns
=
kerns
[:,
:,
::
-
1
,
::
-
1
,
::
-
1
]
kerns
=
gpu_contiguous
(
kerns
.
dimshuffle
(
1
,
0
,
2
,
3
,
4
))
kerns
=
gpu_contiguous
(
kerns
.
dimshuffle
(
1
,
0
,
2
,
3
,
4
))
shape2
=
shape_i
(
img
,
2
,
fgraph
)
-
shape_i
(
kerns
,
2
,
fgraph
)
+
1
out_shp
=
(
shape_i
(
kerns
,
1
,
fgraph
),
shape3
=
shape_i
(
img
,
3
,
fgraph
)
-
shape_i
(
kerns
,
3
,
fgraph
)
+
1
shape_i
(
img
,
1
,
fgraph
),
shape4
=
shape_i
(
img
,
4
,
fgraph
)
-
shape_i
(
kerns
,
4
,
fgraph
)
+
1
shape_i
(
img
,
2
,
fgraph
)
-
shape_i
(
kerns
,
2
,
fgraph
)
+
1
,
out
=
gpu_alloc_empty
(
shape_i
(
kerns
,
1
,
fgraph
),
shape_i
(
img
,
3
,
fgraph
)
-
shape_i
(
kerns
,
3
,
fgraph
)
+
1
,
shape_i
(
img
,
1
,
fgraph
),
shape2
,
shape3
,
shape4
)
shape_i
(
img
,
4
,
fgraph
)
-
shape_i
(
kerns
,
4
,
fgraph
)
+
1
)
out_shp
=
assert_conv_shape
(
out_shp
)
out
=
gpu_alloc_empty
(
*
out_shp
)
desc
=
GpuDnnConvDesc
(
border_mode
=
'valid'
,
subsample
=
(
1
,
1
,
1
),
desc
=
GpuDnnConvDesc
(
border_mode
=
'valid'
,
subsample
=
(
1
,
1
,
1
),
conv_mode
=
'cross'
,
precision
=
precision
)(
img
.
shape
,
conv_mode
=
'cross'
,
precision
=
precision
)(
img
.
shape
,
out
.
shape
)
out
.
shape
)
...
@@ -1271,6 +1279,7 @@ def dnn_conv3d(img, kerns, border_mode='valid', subsample=(1, 1, 1),
...
@@ -1271,6 +1279,7 @@ def dnn_conv3d(img, kerns, border_mode='valid', subsample=(1, 1, 1),
out_shp
=
GpuDnnConv3d
.
get_out_shape
(
img
.
shape
,
kerns
.
shape
,
out_shp
=
GpuDnnConv3d
.
get_out_shape
(
img
.
shape
,
kerns
.
shape
,
desc_op
.
border_mode
,
desc_op
.
border_mode
,
desc_op
.
subsample
)
desc_op
.
subsample
)
out_shp
=
assert_conv_shape
(
out_shp
)
out
=
gpu_alloc_empty
(
*
out_shp
)
out
=
gpu_alloc_empty
(
*
out_shp
)
return
GpuDnnConv3d
(
algo
=
algo
)(
img
,
kerns
,
out
,
desc
)
return
GpuDnnConv3d
(
algo
=
algo
)(
img
,
kerns
,
out
,
desc
)
...
...
theano/tensor/nnet/abstract_conv.py
浏览文件 @
beded2b3
...
@@ -11,6 +11,7 @@ import theano
...
@@ -11,6 +11,7 @@ import theano
from
theano.tensor
import
as_tensor_variable
,
patternbroadcast
from
theano.tensor
import
as_tensor_variable
,
patternbroadcast
from
theano.tensor
import
get_scalar_constant_value
,
NotScalarConstantError
from
theano.tensor
import
get_scalar_constant_value
,
NotScalarConstantError
from
theano.tensor.opt
import
Assert
from
theano.gof
import
Apply
,
Op
from
theano.gof
import
Apply
,
Op
from
six.moves
import
xrange
from
six.moves
import
xrange
...
@@ -428,6 +429,34 @@ def check_conv_gradinputs_shape(image_shape, kernel_shape, output_shape,
...
@@ -428,6 +429,34 @@ def check_conv_gradinputs_shape(image_shape, kernel_shape, output_shape,
for
(
given
,
computed
)
in
zip
(
output_shape
,
computed_output_shape
))
for
(
given
,
computed
)
in
zip
(
output_shape
,
computed_output_shape
))
def
assert_conv_shape
(
shape
):
"""This function adds Assert nodes that check if shape is a valid convolution shape.
Parameters
----------
shape: tuple of int (symbolic or numeric) corresponding to the input, output or
kernel shape of a convolution. For input and output, the first elements should
should be the batch size and number of channels. For kernels, the first and
second elements should contain the number of input and output channels.
The remaining dimensions are the convolution dimensions.
Returns
-------
Returns a tuple similar to the given `shape`, but with each element wrapped in
an `Assert` op that checks that dimension. The first two dimensions should be
larger than or equal to zero. The convolution dimensions should be larger than zero.
"""
out_shape
=
[]
for
i
,
n
in
enumerate
(
shape
):
if
i
<
2
:
assert_shp
=
Assert
(
'The convolution would produce an invalid shape (dim[
%
d] < 0).'
%
i
)
out_shape
.
append
(
assert_shp
(
n
,
theano
.
tensor
.
ge
(
n
,
0
)))
else
:
assert_shp
=
Assert
(
'The convolution would produce an invalid shape (dim[
%
d] <= 0).'
%
i
)
out_shape
.
append
(
assert_shp
(
n
,
theano
.
tensor
.
gt
(
n
,
0
)))
return
tuple
(
out_shape
)
def
conv2d
(
input
,
def
conv2d
(
input
,
filters
,
filters
,
input_shape
=
None
,
input_shape
=
None
,
...
...
theano/tensor/nnet/tests/test_abstract_conv.py
浏览文件 @
beded2b3
...
@@ -13,7 +13,8 @@ from theano.tensor.nnet import corr, corr3d, abstract_conv as conv
...
@@ -13,7 +13,8 @@ from theano.tensor.nnet import corr, corr3d, abstract_conv as conv
from
theano.tensor.nnet.abstract_conv
import
(
get_conv_output_shape
,
from
theano.tensor.nnet.abstract_conv
import
(
get_conv_output_shape
,
get_conv_gradweights_shape
,
get_conv_gradweights_shape
,
get_conv_gradinputs_shape
,
get_conv_gradinputs_shape
,
check_conv_gradinputs_shape
)
check_conv_gradinputs_shape
,
assert_conv_shape
)
from
theano.tensor.nnet.abstract_conv
import
AbstractConv2d
from
theano.tensor.nnet.abstract_conv
import
AbstractConv2d
from
theano.tensor.nnet.abstract_conv
import
AbstractConv2d_gradInputs
from
theano.tensor.nnet.abstract_conv
import
AbstractConv2d_gradInputs
from
theano.tensor.nnet.abstract_conv
import
AbstractConv2d_gradWeights
from
theano.tensor.nnet.abstract_conv
import
AbstractConv2d_gradWeights
...
@@ -211,6 +212,20 @@ class TestConvGradInputsShape(unittest.TestCase):
...
@@ -211,6 +212,20 @@ class TestConvGradInputsShape(unittest.TestCase):
self
.
assertEqual
(
computed_kernel_shape
,
kernel_shape_with_None
)
self
.
assertEqual
(
computed_kernel_shape
,
kernel_shape_with_None
)
class
TestAssertConvShape
(
unittest
.
TestCase
):
def
test_basic
(
self
):
shape
=
tuple
(
tensor
.
iscalar
()
for
i
in
range
(
4
))
f
=
theano
.
function
(
shape
,
assert_conv_shape
(
shape
))
self
.
assertEqual
([
1
,
2
,
3
,
4
],
f
(
1
,
2
,
3
,
4
))
self
.
assertEqual
([
0
,
0
,
1
,
1
],
f
(
0
,
0
,
1
,
1
))
assert_raises
(
AssertionError
,
f
,
3
,
3
,
3
,
0
)
assert_raises
(
AssertionError
,
f
,
3
,
3
,
0
,
3
)
assert_raises
(
AssertionError
,
f
,
3
,
3
,
-
1
,
3
)
assert_raises
(
AssertionError
,
f
,
3
,
-
1
,
3
,
3
)
assert_raises
(
AssertionError
,
f
,
-
1
,
3
,
3
,
3
)
class
BaseTestConv
(
object
):
class
BaseTestConv
(
object
):
def
get_output_shape
(
self
,
inputs_shape
,
filters_shape
,
def
get_output_shape
(
self
,
inputs_shape
,
filters_shape
,
subsample
,
border_mode
,
filter_dilation
):
subsample
,
border_mode
,
filter_dilation
):
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论