Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
6aacf213
提交
6aacf213
authored
12月 02, 2014
作者:
Dustin Webb
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Finished infer_shape on dnn ops and wrote tests.
Conflicts: theano/sandbox/cuda/tests/test_dnn.py
上级
bb3fe454
隐藏空白字符变更
内嵌
并排
正在显示
2 个修改的文件
包含
129 行增加
和
6 行删除
+129
-6
dnn.py
theano/sandbox/cuda/dnn.py
+49
-5
test_dnn.py
theano/sandbox/cuda/tests/test_dnn.py
+80
-1
没有找到文件。
theano/sandbox/cuda/dnn.py
浏览文件 @
6aacf213
...
...
@@ -377,15 +377,12 @@ class GpuDnnConv(DnnBase, COp):
kw
=
shape
[
1
][
3
]
# Width of each filter
padh
=
0
padw
=
0
sh
=
1
sw
=
1
desc
=
node
.
inputs
[
2
]
.
owner
.
op
sh
,
sw
=
desc
.
subsample
if
desc
.
border_mode
==
'full'
:
padh
=
kh
-
1
padw
=
kw
-
1
sh
=
desc
.
subsample
[
0
]
sw
=
desc
.
subsample
[
1
]
return
[(
b
,
nb
,
...
...
@@ -448,6 +445,30 @@ class GpuDnnConvGradW(DnnBase, COp):
return
Apply
(
self
,
[
img
,
topgrad
,
desc
,
h
,
w
],
[
CudaNdarrayType
(
broadcastable
)()])
def
infer_shape
(
self
,
node
,
shape
):
h
=
shape
[
0
][
2
]
# Height of input feature maps
w
=
shape
[
0
][
3
]
# Width of input feature maps
kh
=
shape
[
1
][
2
]
# Height of each filter
kw
=
shape
[
1
][
3
]
# Width of each filter
desc
=
node
.
inputs
[
2
]
.
owner
.
op
sh
,
sw
=
desc
.
subsample
if
desc
.
border_mode
==
'full'
:
kh
=
2
-
h
+
(
kh
-
1
)
*
sh
kw
=
2
-
w
+
(
kw
-
1
)
*
sw
else
:
# border_mode is 'valid'
assert
(
desc
.
border_mode
==
'valid'
)
kh
=
h
-
(
kh
-
1
)
*
sh
kw
=
w
-
(
kw
-
1
)
*
sw
return
[(
shape
[
1
][
1
],
shape
[
0
][
1
],
kh
,
kw
)]
class
GpuDnnConvGradI
(
DnnBase
,
COp
):
"""
...
...
@@ -502,6 +523,29 @@ class GpuDnnConvGradI(DnnBase, COp):
return
Apply
(
self
,
[
kern
,
topgrad
,
desc
,
h
,
w
],
[
CudaNdarrayType
(
broadcastable
)()])
def
infer_shape
(
self
,
node
,
shape
):
b
=
shape
[
0
][
0
]
# Number of inputs
h
=
shape
[
0
][
2
]
# Height of input feature maps
w
=
shape
[
0
][
3
]
# Width of input feature maps
nb
=
shape
[
1
][
0
]
# Number of output feature maps
kh
=
shape
[
1
][
2
]
# Height of each filter
kw
=
shape
[
1
][
3
]
# Width of each filter
padh
=
0
padw
=
0
desc
=
node
.
inputs
[
2
]
.
owner
.
op
sh
,
sw
=
desc
.
subsample
if
desc
.
border_mode
==
'full'
:
padh
=
h
-
1
padw
=
w
-
1
return
[(
shape
[
1
][
0
],
shape
[
0
][
1
],
(
kh
-
1
)
*
sh
+
h
-
2
*
padh
,
(
kw
-
1
)
*
sw
+
w
-
2
*
padw
)]
def
dnn_conv
(
img
,
kerns
,
border_mode
=
'valid'
,
subsample
=
(
1
,
1
),
conv_mode
=
'conv'
,
direction_hint
=
None
):
...
...
@@ -1070,7 +1114,7 @@ class GpuDnnSoftmaxBase(DnnBase):
if
isinstance
(
shape
,
list
):
return
[
shape
[
0
]]
else
:
return
shape
return
shape
*
2
def
_define_tensor4d_desc
(
self
,
name
,
id
):
return
"""
...
...
theano/sandbox/cuda/tests/test_dnn.py
浏览文件 @
6aacf213
...
...
@@ -3,6 +3,7 @@ import unittest
from
nose.plugins.skip
import
SkipTest
import
numpy
from
itertools
import
product
import
theano
from
theano.compat.six
import
StringIO
...
...
@@ -12,7 +13,7 @@ import theano.tests.unittest_tools as utt
from
theano.sandbox.neighbours
import
images2neibs
,
neibs2images
from
theano.tensor.signal.downsample
import
max_pool_2d
from
theano.tensor.signal.downsample
import
DownsampleFactorMaxGrad
import
theano.sandbox.cuda.dnn
as
dnn
# Skip test if cuda_ndarray is not available.
import
theano.sandbox.cuda
as
cuda
...
...
@@ -194,6 +195,84 @@ def test_dnn_tag():
for
n
in
f
.
maker
.
fgraph
.
toposort
()])
class
TestDnnInferShapes
(
utt
.
InferShapeTester
):
def
setUp
(
self
):
super
(
TestDnnInferShapes
,
self
)
.
setUp
()
def
test_softmax
(
self
):
t
=
T
.
tensor4
(
't'
)
rand_tensor
=
numpy
.
asarray
(
numpy
.
random
.
rand
(
5
,
4
,
3
,
2
),
dtype
=
theano
.
config
.
floatX
)
self
.
_compile_and_check
(
[
t
],
[
dnn
.
GpuDnnSoftmax
(
'bc01'
,
'accurate'
,
'channel'
)(
t
)],
[
rand_tensor
],
dnn
.
GpuDnnSoftmax
)
self
.
_compile_and_check
(
[
t
],
[
T
.
grad
(
dnn
.
GpuDnnSoftmax
(
'bc01'
,
'accurate'
,
'channel'
)(
t
)
.
mean
(),
t
)
],
[
rand_tensor
],
dnn
.
GpuDnnSoftmaxGrad
)
def
test_conv
(
self
):
img
=
T
.
tensor4
(
'img'
)
kerns
=
T
.
tensor4
(
'kerns'
)
img_val
=
numpy
.
asarray
(
numpy
.
random
.
rand
(
2
,
3
,
4
,
5
),
dtype
=
theano
.
config
.
floatX
)
kern_vals
=
numpy
.
asarray
(
numpy
.
random
.
rand
(
2
,
3
,
4
,
5
),
dtype
=
theano
.
config
.
floatX
)
for
params
in
product
(
[
'valid'
,
'full'
],
[(
1
,
1
),
(
2
,
2
)],
[
'conv'
,
'cross'
]
):
conv
=
dnn
.
dnn_conv
(
img
,
kerns
,
params
[
0
],
params
[
1
],
params
[
2
])
softmax
=
dnn
.
GpuDnnSoftmax
(
'bc01'
,
'accurate'
,
'channel'
)
self
.
_compile_and_check
(
[
img
,
kerns
],
[
conv
],
[
img_val
,
kern_vals
],
dnn
.
GpuDnnConv
)
self
.
_compile_and_check
(
[
img
,
kerns
],
[
T
.
grad
(
softmax
(
conv
)
.
mean
(),
img
)],
[
img_val
,
kern_vals
],
dnn
.
GpuDnnConvGradI
)
self
.
_compile_and_check
(
[
img
,
kerns
],
[
T
.
grad
(
softmax
(
conv
)
.
mean
(),
kerns
)],
[
img_val
,
kern_vals
],
dnn
.
GpuDnnConvGradW
)
def
test_version
():
if
not
cuda
.
dnn
.
dnn_available
():
raise
SkipTest
(
cuda
.
dnn
.
dnn_available
.
msg
)
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论