Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
85022b36
提交
85022b36
authored
11月 18, 2016
作者:
Alexander Matyasko
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Add checks for pooling parameters
1) Check that ws, stride and pad are int 2) Check that padding is zero when ignore border is false (not supported) 3) Check that window shape is less than pad (not supported)
上级
bb9042a7
显示空白字符变更
内嵌
并排
正在显示
1 个修改的文件
包含
73 行增加
和
24 行删除
+73
-24
pool.py
theano/gpuarray/pool.py
+73
-24
没有找到文件。
theano/gpuarray/pool.py
浏览文件 @
85022b36
...
@@ -37,16 +37,35 @@ class GpuPool(CGpuKernelBase):
...
@@ -37,16 +37,35 @@ class GpuPool(CGpuKernelBase):
def
c_header_dirs
(
self
):
def
c_header_dirs
(
self
):
return
[
os
.
path
.
dirname
(
__file__
),
pygpu
.
get_include
()]
return
[
os
.
path
.
dirname
(
__file__
),
pygpu
.
get_include
()]
def
make_node
(
self
,
inp
,
ws
,
stride
,
pad
):
def
make_node
(
self
,
inp
,
ws
,
stride
=
None
,
pad
=
None
):
ctx_name
=
infer_context_name
(
inp
)
ctx_name
=
infer_context_name
(
inp
)
inp
=
as_gpuarray_variable
(
inp
,
ctx_name
)
inp
=
as_gpuarray_variable
(
inp
,
ctx_name
)
assert
(
inp
.
ndim
==
self
.
ndim
+
2
)
nd
=
self
.
ndim
assert
(
inp
.
ndim
==
nd
+
2
)
if
stride
is
None
:
stride
=
ws
if
pad
is
None
:
pad
=
(
0
,)
*
nd
elif
isinstance
(
pad
,
(
tuple
,
list
)):
if
max
(
pad
)
!=
0
and
not
self
.
ignore_border
:
raise
NotImplementedError
(
'Padding works only with ignore_border=True'
)
if
isinstance
(
ws
,
(
tuple
,
list
)):
if
any
(
pad
[
i
]
>=
ws
[
i
]
for
i
in
range
(
nd
)):
raise
NotImplementedError
(
'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
)
pad
=
as_tensor_variable
(
pad
)
pad
=
as_tensor_variable
(
pad
)
assert
ws
.
type
.
ndim
==
stride
.
type
.
ndim
and
ws
.
type
.
ndim
==
pad
.
type
.
ndim
assert
ws
.
ndim
==
stride
.
ndim
and
ws
.
ndim
==
pad
.
ndim
assert
ws
.
type
.
ndim
==
1
assert
ws
.
ndim
==
1
if
not
ws
.
dtype
.
startswith
(
'int'
):
raise
TypeError
(
'Window shape parameters must be ints.'
)
if
not
stride
.
dtype
.
startswith
(
'int'
):
raise
TypeError
(
'Stride parameters must be ints.'
)
if
not
pad
.
dtype
.
startswith
(
'int'
):
raise
TypeError
(
'Padding parameters must be ints.'
)
return
Apply
(
self
,
[
inp
,
ws
,
stride
,
pad
],
[
inp
.
type
()])
return
Apply
(
self
,
[
inp
,
ws
,
stride
,
pad
],
[
inp
.
type
()])
...
@@ -86,24 +105,34 @@ class GpuMaxPoolGrad(CGpuKernelBase):
...
@@ -86,24 +105,34 @@ class GpuMaxPoolGrad(CGpuKernelBase):
def
c_header_dirs
(
self
):
def
c_header_dirs
(
self
):
return
[
os
.
path
.
dirname
(
__file__
),
pygpu
.
get_include
()]
return
[
os
.
path
.
dirname
(
__file__
),
pygpu
.
get_include
()]
def
make_node
(
self
,
inp
,
out
,
out_grad
,
ws
,
stride
,
pad
):
def
make_node
(
self
,
inp
,
out
,
out_grad
,
ws
,
stride
=
None
,
pad
=
None
):
ctx_name
=
infer_context_name
(
inp
,
out
,
out_grad
)
ctx_name
=
infer_context_name
(
inp
,
out
,
out_grad
)
nd
=
self
.
ndim
inp
=
as_gpuarray_variable
(
inp
,
ctx_name
)
inp
=
as_gpuarray_variable
(
inp
,
ctx_name
)
assert
(
inp
.
ndim
==
self
.
ndim
+
2
)
assert
(
inp
.
ndim
==
nd
+
2
)
out
=
as_gpuarray_variable
(
out
,
ctx_name
)
out
=
as_gpuarray_variable
(
out
,
ctx_name
)
assert
(
out
.
ndim
==
self
.
ndim
+
2
)
assert
(
out
.
ndim
==
nd
+
2
)
out_grad
=
as_gpuarray_variable
(
out_grad
,
ctx_name
)
out_grad
=
as_gpuarray_variable
(
out_grad
,
ctx_name
)
assert
(
out_grad
.
ndim
in
[
4
,
5
]
)
assert
(
out_grad
.
ndim
==
nd
+
2
)
assert
(
out_grad
.
ndim
==
inp
.
ndim
)
assert
(
out_grad
.
ndim
==
inp
.
ndim
)
assert
(
inp
.
ndim
==
out
.
ndim
)
assert
(
inp
.
ndim
==
out
.
ndim
)
if
stride
is
None
:
stride
=
ws
if
pad
is
None
:
pad
=
(
0
,)
*
nd
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
)
assert
ws
.
type
.
ndim
==
stride
.
type
.
ndim
and
ws
.
type
.
ndim
==
pad
.
type
.
ndim
assert
ws
.
ndim
==
stride
.
ndim
and
ws
.
ndim
==
pad
.
ndim
assert
ws
.
type
.
ndim
==
1
assert
ws
.
ndim
==
1
if
not
ws
.
dtype
.
startswith
(
'int'
):
raise
TypeError
(
'Window shape parameters must be ints.'
)
if
not
stride
.
dtype
.
startswith
(
'int'
):
raise
TypeError
(
'Stride parameters must be ints.'
)
if
not
pad
.
dtype
.
startswith
(
'int'
):
raise
TypeError
(
'Padding parameters must be ints.'
)
return
Apply
(
self
,
[
inp
,
out
,
out_grad
,
ws
,
stride
,
pad
],
[
inp
.
type
()])
return
Apply
(
self
,
[
inp
,
out
,
out_grad
,
ws
,
stride
,
pad
],
[
inp
.
type
()])
def
get_params
(
self
,
node
):
def
get_params
(
self
,
node
):
...
@@ -134,21 +163,31 @@ class GpuAveragePoolGrad(CGpuKernelBase):
...
@@ -134,21 +163,31 @@ class GpuAveragePoolGrad(CGpuKernelBase):
def
c_header_dirs
(
self
):
def
c_header_dirs
(
self
):
return
[
os
.
path
.
dirname
(
__file__
),
pygpu
.
get_include
()]
return
[
os
.
path
.
dirname
(
__file__
),
pygpu
.
get_include
()]
def
make_node
(
self
,
inp
,
out_grad
,
ws
,
stride
,
pad
):
def
make_node
(
self
,
inp
,
out_grad
,
ws
,
stride
=
None
,
pad
=
None
):
ctx_name
=
infer_context_name
(
inp
,
out_grad
)
ctx_name
=
infer_context_name
(
inp
,
out_grad
)
nd
=
self
.
ndim
inp
=
as_gpuarray_variable
(
inp
,
ctx_name
)
inp
=
as_gpuarray_variable
(
inp
,
ctx_name
)
assert
(
inp
.
ndim
==
self
.
ndim
+
2
)
assert
(
inp
.
ndim
==
nd
+
2
)
out_grad
=
as_gpuarray_variable
(
out_grad
,
ctx_name
)
out_grad
=
as_gpuarray_variable
(
out_grad
,
ctx_name
)
assert
(
out_grad
.
ndim
==
self
.
ndim
+
2
)
assert
(
out_grad
.
ndim
==
nd
+
2
)
assert
(
out_grad
.
ndim
==
inp
.
ndim
)
assert
(
out_grad
.
ndim
==
inp
.
ndim
)
if
stride
is
None
:
stride
=
ws
if
pad
is
None
:
pad
=
(
0
,)
*
nd
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
)
assert
ws
.
type
.
ndim
==
stride
.
type
.
ndim
and
ws
.
type
.
ndim
==
pad
.
type
.
ndim
assert
ws
.
ndim
==
stride
.
ndim
and
ws
.
ndim
==
pad
.
ndim
assert
ws
.
type
.
ndim
==
1
assert
ws
.
ndim
==
1
if
not
ws
.
dtype
.
startswith
(
'int'
):
raise
TypeError
(
'Window shape parameters must be ints.'
)
if
not
stride
.
dtype
.
startswith
(
'int'
):
raise
TypeError
(
'Stride parameters must be ints.'
)
if
not
pad
.
dtype
.
startswith
(
'int'
):
raise
TypeError
(
'Padding parameters must be ints.'
)
return
Apply
(
self
,
[
inp
,
out_grad
,
ws
,
stride
,
pad
],
[
inp
.
type
()])
return
Apply
(
self
,
[
inp
,
out_grad
,
ws
,
stride
,
pad
],
[
inp
.
type
()])
def
get_params
(
self
,
node
):
def
get_params
(
self
,
node
):
...
@@ -183,24 +222,34 @@ class GpuDownsampleFactorMaxGradGrad(CGpuKernelBase):
...
@@ -183,24 +222,34 @@ class GpuDownsampleFactorMaxGradGrad(CGpuKernelBase):
def
c_header_dirs
(
self
):
def
c_header_dirs
(
self
):
return
[
os
.
path
.
dirname
(
__file__
),
pygpu
.
get_include
()]
return
[
os
.
path
.
dirname
(
__file__
),
pygpu
.
get_include
()]
def
make_node
(
self
,
inp
,
out
,
out_grad
,
ws
,
stride
,
pad
):
def
make_node
(
self
,
inp
,
out
,
out_grad
,
ws
,
stride
=
None
,
pad
=
None
):
ctx_name
=
infer_context_name
(
inp
,
out
,
out_grad
)
ctx_name
=
infer_context_name
(
inp
,
out
,
out_grad
)
nd
=
self
.
ndim
inp
=
as_gpuarray_variable
(
inp
,
ctx_name
)
inp
=
as_gpuarray_variable
(
inp
,
ctx_name
)
assert
(
inp
.
ndim
==
self
.
ndim
+
2
)
assert
(
inp
.
ndim
==
nd
+
2
)
out
=
as_gpuarray_variable
(
out
,
ctx_name
)
out
=
as_gpuarray_variable
(
out
,
ctx_name
)
assert
(
out_grad
.
ndim
==
self
.
ndim
+
2
)
assert
(
out_grad
.
ndim
==
nd
+
2
)
out_grad
=
as_gpuarray_variable
(
out_grad
,
ctx_name
)
out_grad
=
as_gpuarray_variable
(
out_grad
,
ctx_name
)
assert
(
out
.
ndim
==
self
.
ndim
+
2
)
assert
(
out
.
ndim
==
nd
+
2
)
assert
(
out_grad
.
ndim
==
inp
.
ndim
)
assert
(
out_grad
.
ndim
==
inp
.
ndim
)
assert
(
inp
.
ndim
==
out
.
ndim
)
assert
(
inp
.
ndim
==
out
.
ndim
)
if
stride
is
None
:
stride
=
ws
if
pad
is
None
:
pad
=
(
0
,)
*
nd
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
)
assert
ws
.
type
.
ndim
==
stride
.
type
.
ndim
and
ws
.
type
.
ndim
==
pad
.
type
.
ndim
assert
ws
.
ndim
==
stride
.
ndim
and
ws
.
ndim
==
pad
.
ndim
assert
ws
.
type
.
ndim
==
1
assert
ws
.
ndim
==
1
if
not
ws
.
dtype
.
startswith
(
'int'
):
raise
TypeError
(
'Window shape parameters must be ints.'
)
if
not
stride
.
dtype
.
startswith
(
'int'
):
raise
TypeError
(
'Stride parameters must be ints.'
)
if
not
pad
.
dtype
.
startswith
(
'int'
):
raise
TypeError
(
'Padding parameters must be ints.'
)
return
Apply
(
self
,
[
inp
,
out
,
out_grad
,
ws
,
stride
,
pad
],
[
inp
.
type
()])
return
Apply
(
self
,
[
inp
,
out
,
out_grad
,
ws
,
stride
,
pad
],
[
inp
.
type
()])
def
get_params
(
self
,
node
):
def
get_params
(
self
,
node
):
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论