Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
1ce720d3
提交
1ce720d3
authored
11月 18, 2016
作者:
Alexander Matyasko
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Add tests for 6d/7d and to check pool interface
上级
b1546706
隐藏空白字符变更
内嵌
并排
正在显示
3 个修改的文件
包含
45 行增加
和
4 行删除
+45
-4
pool.c
theano/gpuarray/pool.c
+9
-0
pool.py
theano/gpuarray/pool.py
+5
-4
test_pool.py
theano/gpuarray/tests/test_pool.py
+31
-0
没有找到文件。
theano/gpuarray/pool.c
浏览文件 @
1ce720d3
...
@@ -239,11 +239,20 @@ int APPLY_SPECIFIC(pool)(PyGpuArrayObject *x,
...
@@ -239,11 +239,20 @@ int APPLY_SPECIFIC(pool)(PyGpuArrayObject *x,
size_t
w
[
3
];
size_t
w
[
3
];
size_t
s
[
3
];
size_t
s
[
3
];
size_t
p
[
3
];
z_dims
[
0
]
=
x_dims
[
0
];
z_dims
[
1
]
=
x_dims
[
1
];
size_t
p
[
3
];
z_dims
[
0
]
=
x_dims
[
0
];
z_dims
[
1
]
=
x_dims
[
1
];
int
nonzero_padding
=
0
;
for
(
int
i
=
0
;
i
<
ndims
;
i
++
)
{
for
(
int
i
=
0
;
i
<
ndims
;
i
++
)
{
w
[
i
]
=
*
((
npy_intp
*
)
PyArray_GETPTR1
(
ws
,
i
));
w
[
i
]
=
*
((
npy_intp
*
)
PyArray_GETPTR1
(
ws
,
i
));
s
[
i
]
=
*
((
npy_intp
*
)
PyArray_GETPTR1
(
stride
,
i
));
s
[
i
]
=
*
((
npy_intp
*
)
PyArray_GETPTR1
(
stride
,
i
));
p
[
i
]
=
*
((
npy_intp
*
)
PyArray_GETPTR1
(
pad
,
i
));
p
[
i
]
=
*
((
npy_intp
*
)
PyArray_GETPTR1
(
pad
,
i
));
z_dims
[
2
+
i
]
=
OUTPUT_DIMS
(
x_dims
[
2
+
i
]
+
2
*
p
[
i
],
w
[
i
],
s
[
i
]);
z_dims
[
2
+
i
]
=
OUTPUT_DIMS
(
x_dims
[
2
+
i
]
+
2
*
p
[
i
],
w
[
i
],
s
[
i
]);
if
(
p
[
i
]
>
0
)
{
nonzero_padding
=
1
;
}
}
if
(
!
IGNORE_BORDER
&&
nonzero_padding
)
{
PyErr_SetString
(
PyExc_ValueError
,
"GpuPool: padding works only with ignore_border=True"
);
return
1
;
}
}
if
(
theano_prep_output
(
z
,
PyGpuArray_NDIM
(
x
),
z_dims
,
if
(
theano_prep_output
(
z
,
PyGpuArray_NDIM
(
x
),
z_dims
,
...
...
theano/gpuarray/pool.py
浏览文件 @
1ce720d3
...
@@ -48,12 +48,10 @@ class GpuPool(CGpuKernelBase):
...
@@ -48,12 +48,10 @@ class GpuPool(CGpuKernelBase):
pad
=
(
0
,)
*
nd
pad
=
(
0
,)
*
nd
elif
isinstance
(
pad
,
(
tuple
,
list
)):
elif
isinstance
(
pad
,
(
tuple
,
list
)):
if
max
(
pad
)
!=
0
and
not
self
.
ignore_border
:
if
max
(
pad
)
!=
0
and
not
self
.
ignore_border
:
raise
NotImplementedError
(
raise
ValueError
(
'Padding works only with ignore_border=True'
)
'Padding works only with ignore_border=True'
)
if
isinstance
(
ws
,
(
tuple
,
list
)):
if
isinstance
(
ws
,
(
tuple
,
list
)):
if
any
(
pad
[
i
]
>=
ws
[
i
]
for
i
in
range
(
nd
)):
if
any
(
pad
[
i
]
>=
ws
[
i
]
for
i
in
range
(
nd
)):
raise
NotImplementedError
(
raise
ValueError
(
'Padding must be smaller than strides'
)
'Padding must be smaller than strides'
)
ws
=
as_tensor_variable
(
ws
)
ws
=
as_tensor_variable
(
ws
)
stride
=
as_tensor_variable
(
stride
)
stride
=
as_tensor_variable
(
stride
)
...
@@ -177,6 +175,9 @@ class GpuAveragePoolGrad(CGpuKernelBase):
...
@@ -177,6 +175,9 @@ class GpuAveragePoolGrad(CGpuKernelBase):
stride
=
ws
stride
=
ws
if
pad
is
None
:
if
pad
is
None
:
pad
=
(
0
,)
*
nd
pad
=
(
0
,)
*
nd
elif
isinstance
(
pad
,
(
tuple
,
list
)):
if
max
(
pad
)
!=
0
and
not
self
.
mode
==
'average_exc_pad'
:
raise
ValueError
(
'Padding must be zero for average_exc_pad'
)
ws
=
as_tensor_variable
(
ws
)
ws
=
as_tensor_variable
(
ws
)
stride
=
as_tensor_variable
(
stride
)
stride
=
as_tensor_variable
(
stride
)
pad
=
as_tensor_variable
(
pad
)
pad
=
as_tensor_variable
(
pad
)
...
...
theano/gpuarray/tests/test_pool.py
浏览文件 @
1ce720d3
from
__future__
import
absolute_import
,
print_function
,
division
from
__future__
import
absolute_import
,
print_function
,
division
import
unittest
import
copy
import
copy
import
itertools
import
itertools
...
@@ -17,6 +18,36 @@ from ..pool import (GpuPool, GpuMaxPoolGrad, GpuAveragePoolGrad,
...
@@ -17,6 +18,36 @@ from ..pool import (GpuPool, GpuMaxPoolGrad, GpuAveragePoolGrad,
GpuDownsampleFactorMaxGradGrad
)
GpuDownsampleFactorMaxGradGrad
)
class
TestPool
(
unittest
.
TestCase
):
def
test_pool_py_interface
(
self
):
shp
=
(
2
,
2
,
2
,
2
)
inp
=
theano
.
shared
(
rand
(
*
shp
),
'a'
)
inp
=
tensor
.
as_tensor_variable
(
inp
)
with
self
.
assertRaises
(
ValueError
):
# test when pad >= ws
ds_op
=
GpuPool
(
ignore_border
=
True
,
ndim
=
2
)
ds_op
(
inp
,
[
2
,
2
],
pad
=
[
3
,
3
])
with
self
.
assertRaises
(
ValueError
):
# test when ignore_border and pad >= 0
ds_op
=
GpuPool
(
ignore_border
=
False
,
ndim
=
2
)
ds_op
(
inp
,
[
2
,
2
],
pad
=
[
1
,
1
])
def
test_pool_c_interface
(
self
):
gpu_mode
=
copy
.
copy
(
mode_with_gpu
)
.
excluding
(
"cudnn"
)
gpu_mode
.
check_py_code
=
False
shp
=
(
2
,
2
,
2
,
2
)
inp
=
theano
.
shared
(
rand
(
*
shp
),
'a'
)
inp
=
tensor
.
as_tensor_variable
(
inp
)
with
self
.
assertRaises
(
ValueError
):
# test when ignore_border and pad >= 0
ds_op
=
GpuPool
(
ignore_border
=
False
,
ndim
=
2
)
pad
=
tensor
.
as_tensor_variable
([
1
,
1
])
f
=
theano
.
function
([],
ds_op
(
inp
,
[
2
,
2
],
pad
=
pad
),
mode
=
gpu_mode
)
f
()
def
test_pool2d
():
def
test_pool2d
():
shps
=
[(
1
,
12
),
shps
=
[(
1
,
12
),
(
1
,
1
,
12
),
(
1
,
1
,
12
),
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论