Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
2ef334c7
提交
2ef334c7
authored
6月 23, 2015
作者:
Arnaud Bergeron
提交者:
--global
8月 04, 2015
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Add tests for dnn_pool(..., nd=3)
上级
8d45feab
显示空白字符变更
内嵌
并排
正在显示
1 个修改的文件
包含
116 行增加
和
9 行删除
+116
-9
test_dnn.py
theano/sandbox/cuda/tests/test_dnn.py
+116
-9
没有找到文件。
theano/sandbox/cuda/tests/test_dnn.py
浏览文件 @
2ef334c7
...
@@ -161,8 +161,28 @@ def test_dnn_conv_inplace():
...
@@ -161,8 +161,28 @@ def test_dnn_conv_inplace():
assert
len
([
n
for
n
in
topo
if
isinstance
(
n
.
op
,
GpuAllocEmpty
)])
==
2
assert
len
([
n
for
n
in
topo
if
isinstance
(
n
.
op
,
GpuAllocEmpty
)])
==
2
def
pool_2d_i2n
(
input
,
ds
=
(
2
,
2
),
strides
=
None
,
def
pool3d2d
(
input
,
ds
=
(
2
,
2
,
2
),
strides
=
None
,
pad
=
(
0
,
0
,
0
),
pad
=
(
0
,
0
),
pool_func
=
T
.
max
,
mode
=
'ignore_borders'
):
if
strides
is
None
:
strides
=
ds
shape
=
input
.
shape
# resahpe to B, C*0, 1, 2 and do the pooling on 1, 2
first
=
input
.
reshape
((
shape
[
0
],
shape
[
1
]
*
shape
[
2
],
shape
[
3
],
shape
[
4
]))
pooled1
=
pool_2d_i2n
(
first
,
ds
=
ds
[
1
:],
strides
=
strides
[
1
:],
pad
=
pad
[
1
:],
pool_function
=
pool_func
,
mode
=
mode
)
shp1
=
pooled1
.
shape
# reshape to B, C, 0, 1*2 and do the pooling on 0
second
=
pooled1
.
reshape
((
shape
[
0
],
shape
[
1
],
shape
[
2
],
shp1
[
2
]
*
shp1
[
3
]))
pooled2
=
pool_2d_i2n
(
second
,
ds
=
(
ds
[
0
],
1
),
strides
=
(
strides
[
0
],
1
),
pad
=
(
pad
[
0
],
0
),
pool_function
=
pool_func
,
mode
=
mode
)
shp2
=
pooled2
.
shape
return
pooled2
.
reshape
((
shape
[
0
],
shape
[
1
],
shp2
[
2
],
shp1
[
2
],
shp1
[
3
]))
def
pool_2d_i2n
(
input
,
ds
=
(
2
,
2
),
strides
=
None
,
pad
=
(
0
,
0
),
pool_function
=
T
.
max
,
mode
=
'ignore_borders'
):
pool_function
=
T
.
max
,
mode
=
'ignore_borders'
):
if
strides
is
None
:
if
strides
is
None
:
strides
=
ds
strides
=
ds
...
@@ -302,6 +322,97 @@ def test_pooling():
...
@@ -302,6 +322,97 @@ def test_pooling():
assert
numpy
.
allclose
(
c_out
,
g_out
)
assert
numpy
.
allclose
(
c_out
,
g_out
)
def
test_pooling3d
():
if
not
cuda
.
dnn
.
dnn_available
():
raise
SkipTest
(
cuda
.
dnn
.
dnn_available
.
msg
)
x
=
T
.
TensorType
(
broadcastable
=
(
False
,
False
,
False
,
False
,
False
),
dtype
=
'float32'
)()
for
mode
,
pad
in
product
((
'max'
,
'average_inc_pad'
,
'average_exc_pad'
),
((
0
,
0
,
0
),
(
1
,
0
,
0
),
(
0
,
1
,
0
),
(
0
,
0
,
1
),
(
2
,
3
,
2
),
(
3
,
2
,
2
),
(
2
,
2
,
3
))):
if
mode
==
'max'
:
func
=
T
.
max
else
:
func
=
T
.
mean
if
pad
!=
(
0
,
0
,
0
)
and
cuda
.
dnn
.
version
()
==
-
1
:
continue
if
pad
!=
(
0
,
0
,
0
)
and
func
is
T
.
mean
:
continue
for
ws
in
(
4
,
2
,
5
):
for
stride
in
(
2
,
3
):
if
stride
>
ws
:
continue
if
pad
[
0
]
>
stride
or
pad
[
1
]
>
stride
or
pad
[
2
]
>
stride
:
# Not implemented
continue
out1
=
cuda
.
dnn
.
dnn_pool
(
x
,
(
ws
,
ws
,
ws
),
stride
=
(
stride
,
stride
,
stride
),
pad
=
pad
,
mode
=
mode
,
nd
=
3
)
out2
=
pool3d2d
(
x
,
ds
=
(
ws
,
ws
,
ws
),
strides
=
(
stride
,
stride
,
stride
),
pad
=
pad
,
pool_func
=
func
)
mode_without_gpu2
=
mode_without_gpu
.
including
()
mode_without_gpu2
.
check_isfinite
=
False
f1
=
theano
.
function
([
x
],
out1
,
mode
=
mode_with_gpu
)
assert
any
([
isinstance
(
node
.
op
,
cuda
.
dnn
.
GpuDnnPool
)
for
node
in
f1
.
maker
.
fgraph
.
apply_nodes
])
f2
=
theano
.
function
([
x
],
out2
,
mode
=
mode_without_gpu2
)
assert
not
any
([
isinstance
(
node
.
op
,
cuda
.
dnn
.
GpuDnnPool
)
for
node
in
f2
.
maker
.
fgraph
.
apply_nodes
])
for
shp
in
[(
1
,
10
,
100
,
100
,
100
),
(
1
,
3
,
99
,
99
,
99
),
(
32
,
1
,
147
,
197
,
37
),
]:
data
=
numpy
.
random
.
normal
(
0
,
1
,
shp
)
.
astype
(
"float32"
)
a
=
f1
(
data
)
.
__array__
()
b
=
f2
(
data
)
.
__array__
()
assert
numpy
.
allclose
(
a
,
b
,
atol
=
numpy
.
finfo
(
numpy
.
float32
)
.
eps
)
# Test the grad
for
shp
in
[(
1
,
1
,
2
,
2
,
2
),
(
1
,
1
,
3
,
3
,
3
)]:
data
=
numpy
.
random
.
normal
(
0
,
1
,
shp
)
.
astype
(
"float32"
)
*
10
ws
=
2
stride
=
2
if
pad
[
0
]
>
stride
or
pad
[
1
]
>
stride
or
pad
[
2
]
>
stride
:
# Not implemented
continue
# Test the GPU grad + GPU implementation
def
fn
(
x
):
dnn_op
=
cuda
.
dnn
.
dnn_pool
(
x
,
ws
=
(
ws
,
ws
,
ws
),
stride
=
(
stride
,
stride
,
stride
),
pad
=
pad
,
mode
=
mode
,
nd
=
3
)
return
dnn_op
theano
.
tests
.
unittest_tools
.
verify_grad
(
fn
,
[
data
],
cast_to_output_type
=
False
,
mode
=
mode_with_gpu
)
# Confirm that we get the good op.
fg
=
theano
.
function
([
x
],
theano
.
grad
(
fn
(
x
)
.
sum
(),
x
),
mode
=
mode_with_gpu
)
assert
any
([
isinstance
(
node
.
op
,
cuda
.
dnn
.
GpuDnnPoolGrad
)
for
node
in
fg
.
maker
.
fgraph
.
toposort
()])
g_out
=
fg
(
data
)
# Compare again the CPU result
out
=
pool3d2d
(
x
,
(
ws
,
ws
,
ws
),
strides
=
(
stride
,
stride
,
stride
),
pad
=
pad
,
pool_func
=
func
)
fc
=
theano
.
function
([
x
],
theano
.
grad
(
out
.
sum
(),
x
),
mode
=
mode_without_gpu
)
c_out
=
fc
(
data
)
assert
numpy
.
allclose
(
c_out
,
g_out
)
def
test_pooling_opt
():
def
test_pooling_opt
():
if
not
cuda
.
dnn
.
dnn_available
():
if
not
cuda
.
dnn
.
dnn_available
():
raise
SkipTest
(
cuda
.
dnn
.
dnn_available
.
msg
)
raise
SkipTest
(
cuda
.
dnn
.
dnn_available
.
msg
)
...
@@ -815,7 +926,7 @@ def test_dnn_conv_grad():
...
@@ -815,7 +926,7 @@ def test_dnn_conv_grad():
def
test_conv3d_fwd
():
def
test_conv3d_fwd
():
if
not
cuda
.
dnn
.
dnn_available
()
and
dnn
.
version
()[
0
]
>=
3000
:
if
not
cuda
.
dnn
.
dnn_available
()
and
dnn
.
version
()[
0
]
>=
3000
:
raise
SkipTest
(
'"3D conv not supported in cudnn v1'
)
raise
SkipTest
(
'"3D conv not supported in cudnn v1'
)
def
run_conv3d_fwd
(
inputs_shape
,
filters_shape
,
def
run_conv3d_fwd
(
inputs_shape
,
filters_shape
,
...
@@ -835,7 +946,6 @@ def test_conv3d_fwd():
...
@@ -835,7 +946,6 @@ def test_conv3d_fwd():
f_ref
=
theano
.
function
([],
conv_ref
.
dimshuffle
(
0
,
4
,
1
,
2
,
3
))
f_ref
=
theano
.
function
([],
conv_ref
.
dimshuffle
(
0
,
4
,
1
,
2
,
3
))
f
=
theano
.
function
([],
conv
,
mode
=
mode_with_gpu
)
f
=
theano
.
function
([],
conv
,
mode
=
mode_with_gpu
)
res_ref
=
f_ref
()
res_ref
=
f_ref
()
res
=
f
()
res
=
f
()
...
@@ -863,11 +973,9 @@ def test_conv3d_fwd():
...
@@ -863,11 +973,9 @@ def test_conv3d_fwd():
subsample
=
(
1
,
2
,
3
))
subsample
=
(
1
,
2
,
3
))
def
test_conv3d_gradweight
():
def
test_conv3d_gradweight
():
if
not
cuda
.
dnn
.
dnn_available
()
and
dnn
.
version
()[
0
]
>=
3000
:
if
not
cuda
.
dnn
.
dnn_available
()
and
dnn
.
version
()[
0
]
>=
3000
:
raise
SkipTest
(
'"3D conv not supported in cudnn v1'
)
raise
SkipTest
(
'"3D conv not supported in cudnn v1'
)
def
run_gradweight
(
inputs_shape
,
filters_shape
,
dCdH_shape
,
def
run_gradweight
(
inputs_shape
,
filters_shape
,
dCdH_shape
,
...
@@ -914,7 +1022,7 @@ def test_conv3d_gradweight():
...
@@ -914,7 +1022,7 @@ def test_conv3d_gradweight():
def
test_conv3d_gradinput
():
def
test_conv3d_gradinput
():
if
not
cuda
.
dnn
.
dnn_available
()
and
dnn
.
version
()[
0
]
>=
3000
:
if
not
cuda
.
dnn
.
dnn_available
()
and
dnn
.
version
()[
0
]
>=
3000
:
raise
SkipTest
(
'"3D conv not supported in cudnn v1'
)
raise
SkipTest
(
'"3D conv not supported in cudnn v1'
)
def
run_gradinput
(
inputs_shape
,
filters_shape
,
def
run_gradinput
(
inputs_shape
,
filters_shape
,
...
@@ -958,7 +1066,6 @@ def test_conv3d_gradinput():
...
@@ -958,7 +1066,6 @@ def test_conv3d_gradinput():
subsample
=
(
3
,
1
,
2
))
subsample
=
(
3
,
1
,
2
))
def
test_version
():
def
test_version
():
if
not
cuda
.
dnn
.
dnn_available
():
if
not
cuda
.
dnn
.
dnn_available
():
raise
SkipTest
(
cuda
.
dnn
.
dnn_available
.
msg
)
raise
SkipTest
(
cuda
.
dnn
.
dnn_available
.
msg
)
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论