Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
94b43288
提交
94b43288
authored
8月 29, 2016
作者:
Cesar Laurent
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Adressed Freds comments
上级
1ad6fae7
隐藏空白字符变更
内嵌
并排
正在显示
4 个修改的文件
包含
79 行增加
和
8 行删除
+79
-8
downsample.txt
doc/library/tensor/signal/downsample.txt
+14
-0
index.txt
doc/library/tensor/signal/index.txt
+1
-0
pool.py
theano/tensor/signal/pool.py
+63
-8
test_pool.py
theano/tensor/signal/tests/test_pool.py
+1
-0
没有找到文件。
doc/library/tensor/signal/downsample.txt
0 → 100644
浏览文件 @
94b43288
.. _libdoc_tensor_signal_downsample:
======================================================
:mod:`downsample` -- Down-Sampling
======================================================
.. module:: downsample
:platform: Unix, Windows
:synopsis: ops for performing various forms of downsampling
.. moduleauthor:: LISA
.. note::
This module is deprecated. Use the functions in :func:`theano.tensor.nnet.signal.pool`
doc/library/tensor/signal/index.txt
浏览文件 @
94b43288
...
...
@@ -21,3 +21,4 @@ forms of signal processing.
conv
pool
downsample
theano/tensor/signal/pool.py
浏览文件 @
94b43288
...
...
@@ -243,7 +243,6 @@ class Pool(OpenMPOp):
def
prepare_node
(
self
,
node
,
storage_map
,
compute_map
):
if
len
(
node
.
inputs
)
==
1
:
warnings
.
warn
(
"Theano Pool internal changed."
,
stacklevel
=
3
)
# Old interface
self
.
mode
=
node
.
op
.
mode
ws
=
theano
.
tensor
.
constant
(
node
.
op
.
ds
)
...
...
@@ -277,12 +276,10 @@ class Pool(OpenMPOp):
if
stride
is
None
:
stride
=
ws
if
isinstance
(
pad
,
(
tuple
,
list
)):
pad
=
tuple
(
pad
)
if
pad
!=
(
0
,
0
)
and
not
self
.
ignore_border
:
if
tuple
(
pad
)
!=
(
0
,
0
)
and
not
self
.
ignore_border
:
raise
NotImplementedError
(
'padding works only with ignore_border=True'
)
if
isinstance
(
ws
,
(
tuple
,
list
)):
ws
=
tuple
(
ws
)
if
pad
[
0
]
>=
ws
[
0
]
or
pad
[
1
]
>=
ws
[
1
]:
raise
NotImplementedError
(
'padding_h and padding_w must be smaller than strides'
)
...
...
@@ -308,6 +305,7 @@ class Pool(OpenMPOp):
def
perform
(
self
,
node
,
inp
,
out
):
x
,
ws
,
stride
,
pad
=
inp
z
,
=
out
assert
ws
.
shape
==
stride
.
shape
==
pad
.
shape
==
(
2
,)
if
len
(
x
.
shape
)
!=
4
:
raise
NotImplementedError
(
'Pool requires 4D input for now'
)
...
...
@@ -401,6 +399,21 @@ class Pool(OpenMPOp):
else
:
omp_parallel
=
''
ccode
=
"""
if(PyArray_DIM(
%(ws)
s, 0)!=2)
{
PyErr_SetString(PyExc_ValueError, "ws must be a vector of size 2");
%(fail)
s;
}
if(PyArray_DIM(
%(stride)
s, 0)!=2)
{
PyErr_SetString(PyExc_ValueError, "stride must be a vector of size 2");
%(fail)
s;
}
if(PyArray_DIM(
%(pad)
s, 0)!=2)
{
PyErr_SetString(PyExc_ValueError, "pad must be a vector of size 2");
%(fail)
s;
}
// Getting ws, stride and pad
int ws0, ws1, st0, st1, pd0, pd1;
ws0 = *((npy_intp*)PyArray_GETPTR1(
%(ws)
s, 0));
...
...
@@ -675,7 +688,6 @@ class PoolGrad(OpenMPOp):
def
prepare_node
(
self
,
node
,
storage_map
,
compute_map
):
if
len
(
node
.
inputs
)
<
5
:
# 5 for AveragePoolGrad, 6 for MaxPoolGrad
warnings
.
warn
(
"Theano PoolGrad internal changed."
,
stacklevel
=
3
)
# Old interface
self
.
mode
=
node
.
op
.
mode
ws
=
theano
.
tensor
.
constant
(
node
.
op
.
ds
)
...
...
@@ -728,12 +740,19 @@ class MaxPoolGrad(PoolGrad):
assert
isinstance
(
ws
,
Variable
)
and
ws
.
ndim
==
1
assert
isinstance
(
stride
,
Variable
)
and
stride
.
ndim
==
1
assert
isinstance
(
pad
,
Variable
)
and
pad
.
ndim
==
1
if
not
ws
.
dtype
.
startswith
(
'int'
):
raise
TypeError
(
'Pool downsample 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
,
[
x
,
maxout
,
gz
,
ws
,
stride
,
pad
],
[
x
.
type
()])
def
perform
(
self
,
node
,
inp
,
out
):
assert
self
.
mode
==
'max'
x
,
maxout
,
gz
,
ws
,
stride
,
pad
=
inp
gx_stg
,
=
out
assert
ws
.
shape
==
stride
.
shape
==
pad
.
shape
==
(
2
,)
# number of pooling output rows
pr
=
maxout
.
shape
[
-
2
]
# number of pooling output cols
...
...
@@ -817,6 +836,21 @@ class MaxPoolGrad(PoolGrad):
PyErr_SetString(PyExc_ValueError, "gz must be a 4d ndarray");
%(fail)
s;
}
if(PyArray_DIM(
%(ws)
s, 0)!=2)
{
PyErr_SetString(PyExc_ValueError, "ws must be a vector of size 2");
%(fail)
s;
}
if(PyArray_DIM(
%(stride)
s, 0)!=2)
{
PyErr_SetString(PyExc_ValueError, "stride must be a vector of size 2");
%(fail)
s;
}
if(PyArray_DIM(
%(pad)
s, 0)!=2)
{
PyErr_SetString(PyExc_ValueError, "pad must be a vector of size 2");
%(fail)
s;
}
// Getting ws, stride and pad
int ws0, ws1, st0, st1, pd0, pd1;
ws0 = *((npy_intp*)PyArray_GETPTR1(
%(ws)
s, 0));
...
...
@@ -927,11 +961,18 @@ class AveragePoolGrad(PoolGrad):
assert
isinstance
(
ws
,
Variable
)
and
ws
.
ndim
==
1
assert
isinstance
(
stride
,
Variable
)
and
stride
.
ndim
==
1
assert
isinstance
(
pad
,
Variable
)
and
pad
.
ndim
==
1
if
not
ws
.
dtype
.
startswith
(
'int'
):
raise
TypeError
(
'Pool downsample 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
,
[
x
,
gz
,
ws
,
stride
,
pad
],
[
x
.
type
()])
def
perform
(
self
,
node
,
inp
,
out
):
x
,
gz
,
ws
,
stride
,
pad
=
inp
gx_stg
,
=
out
assert
ws
.
shape
==
stride
.
shape
==
pad
.
shape
==
(
2
,)
if
self
.
mode
==
'average_exc_pad'
and
pad
[
0
]
!=
0
and
pad
[
1
]
!=
0
:
raise
NotImplementedError
()
z_shape
=
self
.
out_shape
(
x
.
shape
,
ws
,
self
.
ignore_border
,
stride
,
pad
)
...
...
@@ -1016,12 +1057,10 @@ class DownsampleFactorMaxGradGrad(OpenMPOp):
if
stride
is
None
:
stride
=
ws
if
isinstance
(
pad
,
(
tuple
,
list
)):
pad
=
tuple
(
pad
)
if
pad
!=
(
0
,
0
)
and
not
self
.
ignore_border
:
if
tuple
(
pad
)
!=
(
0
,
0
)
and
not
self
.
ignore_border
:
raise
NotImplementedError
(
'padding works only with ignore_border=True'
)
if
isinstance
(
ws
,
(
tuple
,
list
)):
ws
=
tuple
(
ws
)
if
pad
[
0
]
>=
ws
[
0
]
or
pad
[
1
]
>=
ws
[
1
]:
raise
NotImplementedError
(
'padding_h and padding_w must be smaller than strides'
)
...
...
@@ -1042,6 +1081,7 @@ class DownsampleFactorMaxGradGrad(OpenMPOp):
def
perform
(
self
,
node
,
inp
,
out
):
x
,
maxout
,
ggx
,
ws
,
stride
,
pad
=
inp
z
,
=
out
assert
ws
.
shape
==
stride
.
shape
==
pad
.
shape
==
(
2
,)
if
len
(
x
.
shape
)
!=
4
:
raise
NotImplementedError
(
'DownsampleFactorMaxGradGrad requires 4D input for now'
)
...
...
@@ -1114,6 +1154,21 @@ class DownsampleFactorMaxGradGrad(OpenMPOp):
else
:
omp_parallel
=
''
return
"""
if(PyArray_DIM(
%(ws)
s, 0)!=2)
{
PyErr_SetString(PyExc_ValueError, "ws must be a vector of size 2");
%(fail)
s;
}
if(PyArray_DIM(
%(stride)
s, 0)!=2)
{
PyErr_SetString(PyExc_ValueError, "stride must be a vector of size 2");
%(fail)
s;
}
if(PyArray_DIM(
%(pad)
s, 0)!=2)
{
PyErr_SetString(PyExc_ValueError, "pad must be a vector of size 2");
%(fail)
s;
}
// Getting ws, stride and pad
int ws0, ws1, st0, st1, pd0, pd1;
ws0 = *((npy_intp*)PyArray_GETPTR1(
%(ws)
s, 0));
...
...
theano/tensor/signal/tests/test_pool.py
浏览文件 @
94b43288
...
...
@@ -842,6 +842,7 @@ class TestDownsampleFactorMax(utt.InferShapeTester):
def
test_old_pool_interface
(
self
):
if
sys
.
version_info
[
0
]
!=
3
:
# Only tested with python 3 because of pickling issues.
raise
SkipTest
(
'Skip old pool interface with python 2.x'
)
# 1. Load the old version
testfile_dir
=
os
.
path
.
dirname
(
os
.
path
.
realpath
(
__file__
))
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论