Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
1d2eec53
提交
1d2eec53
authored
11月 29, 2014
作者:
Sina Honari
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
applying the changes for the case of ignore_border plus the changes for pep8 for issue #2196
上级
26c105c9
全部展开
隐藏空白字符变更
内嵌
并排
正在显示
2 个修改的文件
包含
41 行增加
和
30 行删除
+41
-30
downsample.py
theano/tensor/signal/downsample.py
+41
-30
test_downsample.py
theano/tensor/signal/tests/test_downsample.py
+0
-0
没有找到文件。
theano/tensor/signal/downsample.py
浏览文件 @
1d2eec53
...
@@ -29,8 +29,8 @@ def max_pool_2d(input, ds, ignore_border=False):
...
@@ -29,8 +29,8 @@ def max_pool_2d(input, ds, ignore_border=False):
:param input: input images. Max pooling will be done over the 2 last
:param input: input images. Max pooling will be done over the 2 last
dimensions.
dimensions.
:type ds: tuple of length 2
:type ds: tuple of length 2
:param ds: factor by which to downscale (vertical ds, horizontal ds).
:param ds: factor by which to downscale (vertical ds, horizontal ds).
(2,2) will halve the image in each dimension.
(2,2) will halve the image in each dimension.
:param ignore_border: boolean value. When True, (5,5) input with ds=(2,2)
:param ignore_border: boolean value. When True, (5,5) input with ds=(2,2)
will generate a (2,2) output. (3,3) otherwise.
will generate a (2,2) output. (3,3) otherwise.
"""
"""
...
@@ -81,7 +81,7 @@ class DownsampleFactorMax(Op):
...
@@ -81,7 +81,7 @@ class DownsampleFactorMax(Op):
this parameter indicates the size of the pooling region
this parameter indicates the size of the pooling region
:type ds: list or tuple of two ints
:type ds: list or tuple of two ints
:param st: the stride size. This is the distance between the pooling
:param st: the stride size. This is the distance between the pooling
regions. If it's set to None, in which case it equlas ds.
regions. If it's set to None, in which case it equlas ds.
:type st: list or tuple of two ints
:type st: list or tuple of two ints
...
@@ -102,29 +102,34 @@ class DownsampleFactorMax(Op):
...
@@ -102,29 +102,34 @@ class DownsampleFactorMax(Op):
st
=
ds
st
=
ds
r
,
c
=
imgshape
[
-
2
:]
r
,
c
=
imgshape
[
-
2
:]
out_r
=
(
r
-
ds
[
0
])
//
st
[
0
]
+
1
if
ignore_border
:
out_c
=
(
c
-
ds
[
1
])
//
st
[
1
]
+
1
out_r
=
(
r
-
ds
[
0
])
//
st
[
0
]
+
1
out_c
=
(
c
-
ds
[
1
])
//
st
[
1
]
+
1
if
isinstance
(
r
,
theano
.
Variable
):
if
isinstance
(
r
,
theano
.
Variable
):
nr
=
tensor
.
maximum
(
out_r
,
0
)
nr
=
tensor
.
maximum
(
out_r
,
0
)
else
:
else
:
nr
=
numpy
.
maximum
(
out_r
,
0
)
nr
=
numpy
.
maximum
(
out_r
,
0
)
if
isinstance
(
c
,
theano
.
Variable
):
if
isinstance
(
c
,
theano
.
Variable
):
nc
=
tensor
.
maximum
(
out_c
,
0
)
nc
=
tensor
.
maximum
(
out_c
,
0
)
else
:
nc
=
numpy
.
maximum
(
out_c
,
0
)
else
:
else
:
nc
=
numpy
.
maximum
(
out_c
,
0
)
if
not
ignore_border
:
if
isinstance
(
r
,
theano
.
Variable
):
if
isinstance
(
r
,
theano
.
Variable
):
nr
=
tensor
.
switch
(
tensor
.
ge
(
st
[
0
],
ds
[
0
]),
(
r
-
1
)
//
st
[
0
]
+
1
,
tensor
.
maximum
(
0
,
(
r
-
1
-
ds
[
0
])
//
st
[
0
]
+
1
)
+
1
)
nr
=
tensor
.
switch
(
tensor
.
ge
(
st
[
0
],
ds
[
0
]),
elif
st
[
0
]
>=
ds
[
0
]:
(
r
-
1
)
//
st
[
0
]
+
1
,
tensor
.
maximum
(
0
,
(
r
-
1
-
ds
[
0
])
//
st
[
0
]
+
1
)
+
1
)
elif
st
[
0
]
>=
ds
[
0
]:
nr
=
(
r
-
1
)
//
st
[
0
]
+
1
nr
=
(
r
-
1
)
//
st
[
0
]
+
1
else
:
else
:
nr
=
max
(
0
,
(
r
-
1
-
ds
[
0
])
//
st
[
0
]
+
1
)
+
1
nr
=
max
(
0
,
(
r
-
1
-
ds
[
0
])
//
st
[
0
]
+
1
)
+
1
if
isinstance
(
c
,
theano
.
Variable
):
if
isinstance
(
c
,
theano
.
Variable
):
nc
=
tensor
.
switch
(
tensor
.
ge
(
st
[
1
],
ds
[
1
]),
(
c
-
1
)
//
st
[
1
]
+
1
,
tensor
.
maximum
(
0
,
(
c
-
1
-
ds
[
1
])
//
st
[
1
]
+
1
)
+
1
)
nc
=
tensor
.
switch
(
tensor
.
ge
(
st
[
1
],
ds
[
1
]),
elif
st
[
1
]
>=
ds
[
1
]:
(
c
-
1
)
//
st
[
1
]
+
1
,
tensor
.
maximum
(
0
,
(
c
-
1
-
ds
[
1
])
//
st
[
1
]
+
1
)
+
1
)
elif
st
[
1
]
>=
ds
[
1
]:
nc
=
(
c
-
1
)
//
st
[
1
]
+
1
nc
=
(
c
-
1
)
//
st
[
1
]
+
1
else
:
else
:
nc
=
max
(
0
,
(
c
-
1
-
ds
[
1
])
//
st
[
1
]
+
1
)
+
1
nc
=
max
(
0
,
(
c
-
1
-
ds
[
1
])
//
st
[
1
]
+
1
)
+
1
...
@@ -134,14 +139,15 @@ class DownsampleFactorMax(Op):
...
@@ -134,14 +139,15 @@ class DownsampleFactorMax(Op):
def
__init__
(
self
,
ds
,
ignore_border
=
False
,
st
=
None
):
def
__init__
(
self
,
ds
,
ignore_border
=
False
,
st
=
None
):
"""
"""
:param ds: downsample factor over rows and column. ds indicates the pool region size
:param ds: downsample factor over rows and column.
ds indicates the pool region size.
:type ds: list or tuple of two ints
:type ds: list or tuple of two ints
: param st: stride size, which is the number of shifts
: param st: stride size, which is the number of shifts
over rows/cols to get the the next pool region.
over rows/cols to get the the next pool region.
if st is None, it is considered equal to ds
if st is None, it is considered equal to ds
(no overlap on pooling regions)
(no overlap on pooling regions)
: type st: list or tuple of two ints
: type st: list or tuple of two ints
:param ignore_border: if ds doesn't divide imgshape, do we include
:param ignore_border: if ds doesn't divide imgshape, do we include
an extra row/col of partial downsampling (False) or
an extra row/col of partial downsampling (False) or
...
@@ -167,11 +173,12 @@ class DownsampleFactorMax(Op):
...
@@ -167,11 +173,12 @@ class DownsampleFactorMax(Op):
self
.
ignore_border
==
other
.
ignore_border
)
self
.
ignore_border
==
other
.
ignore_border
)
def
__hash__
(
self
):
def
__hash__
(
self
):
return
hash
(
type
(
self
))
^
hash
(
self
.
ds
)
^
hash
(
self
.
st
)
^
hash
(
self
.
ignore_border
)
return
hash
(
type
(
self
))
^
hash
(
self
.
ds
)
^
\
hash
(
self
.
st
)
^
hash
(
self
.
ignore_border
)
def
__str__
(
self
):
def
__str__
(
self
):
return
'
%
s{
%
s,
%
s,
%
s}'
%
(
self
.
__class__
.
__name__
,
return
'
%
s{
%
s,
%
s,
%
s}'
%
(
self
.
__class__
.
__name__
,
self
.
ds
,
self
.
st
,
self
.
ignore_border
)
self
.
ds
,
self
.
st
,
self
.
ignore_border
)
def
make_node
(
self
,
x
):
def
make_node
(
self
,
x
):
if
x
.
type
.
ndim
!=
4
:
if
x
.
type
.
ndim
!=
4
:
...
@@ -196,8 +203,10 @@ class DownsampleFactorMax(Op):
...
@@ -196,8 +203,10 @@ class DownsampleFactorMax(Op):
## zz needs to be initialized with -inf for the following to work
## zz needs to be initialized with -inf for the following to work
zz
-=
numpy
.
inf
zz
-=
numpy
.
inf
pr
=
zz
.
shape
[
-
2
]
# number of pooling output rows
#number of pooling output rows
pc
=
zz
.
shape
[
-
1
]
# number of pooling output cols
pr
=
zz
.
shape
[
-
2
]
#number of pooling output cols
pc
=
zz
.
shape
[
-
1
]
ds0
,
ds1
=
self
.
ds
ds0
,
ds1
=
self
.
ds
st0
,
st1
=
self
.
st
st0
,
st1
=
self
.
st
img_rows
=
x
.
shape
[
-
2
]
img_rows
=
x
.
shape
[
-
2
]
...
@@ -213,11 +222,13 @@ class DownsampleFactorMax(Op):
...
@@ -213,11 +222,13 @@ class DownsampleFactorMax(Op):
col_end
=
__builtin__
.
min
(
col_st
+
ds1
,
img_cols
)
col_end
=
__builtin__
.
min
(
col_st
+
ds1
,
img_cols
)
for
row_ind
in
xrange
(
row_st
,
row_end
):
for
row_ind
in
xrange
(
row_st
,
row_end
):
for
col_ind
in
xrange
(
col_st
,
col_end
):
for
col_ind
in
xrange
(
col_st
,
col_end
):
zz
[
n
,
k
,
r
,
c
]
=
__builtin__
.
max
(
zz
[
n
,
k
,
r
,
c
],
zz
[
n
,
k
,
r
,
c
]
=
\
x
[
n
,
k
,
row_ind
,
col_ind
])
__builtin__
.
max
(
zz
[
n
,
k
,
r
,
c
],
x
[
n
,
k
,
row_ind
,
col_ind
])
def
infer_shape
(
self
,
node
,
in_shapes
):
def
infer_shape
(
self
,
node
,
in_shapes
):
shp
=
self
.
out_shape
(
in_shapes
[
0
],
self
.
ds
,
self
.
ignore_border
,
self
.
st
)
shp
=
self
.
out_shape
(
in_shapes
[
0
],
self
.
ds
,
self
.
ignore_border
,
self
.
st
)
return
[
shp
]
return
[
shp
]
def
grad
(
self
,
inp
,
grads
):
def
grad
(
self
,
inp
,
grads
):
...
...
theano/tensor/signal/tests/test_downsample.py
浏览文件 @
1d2eec53
差异被折叠。
点击展开。
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论