Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
179d6fba
提交
179d6fba
authored
12月 03, 2015
作者:
Frederic
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Remove useless code
上级
4201bf7c
显示空白字符变更
内嵌
并排
正在显示
2 个修改的文件
包含
3 行增加
和
83 行删除
+3
-83
downsample.py
theano/tensor/signal/downsample.py
+2
-82
test_downsample.py
theano/tensor/signal/tests/test_downsample.py
+1
-1
没有找到文件。
theano/tensor/signal/downsample.py
浏览文件 @
179d6fba
...
@@ -900,84 +900,6 @@ class AveragePoolGrad(PoolGrad):
...
@@ -900,84 +900,6 @@ class AveragePoolGrad(PoolGrad):
class
DownsampleFactorMaxGradGrad
(
Op
):
class
DownsampleFactorMaxGradGrad
(
Op
):
__props__
=
(
'ds'
,
'ignore_border'
,
'st'
,
'padding'
,
'mode'
)
__props__
=
(
'ds'
,
'ignore_border'
,
'st'
,
'padding'
,
'mode'
)
@staticmethod
def
out_shape
(
imgshape
,
ds
,
ignore_border
=
False
,
st
=
None
,
padding
=
(
0
,
0
)):
"""
Return the shape of the output from this op, for input of given
shape and flags.
Parameters
----------
imgshape : tuple, list, or similar of integer or scalar Theano variable
The shape of a tensor of images. The last two elements
are interpreted as the number of rows, and the number of cols.
ds : list or tuple of two ints
Downsample factor over rows and columns this parameter indicates the
size of the pooling region.
st: list or tuple of two ints
The stride size. This is the distance between the pooling regions.
If it's set to None, in which case it equlas ds.
ignore_border: bool
If ds doesn't divide imgshape, do we include an
extra row/col of partial downsampling (False) or ignore it (True).
padding : tuple of two ints
(pad_h, pad_w), pad zeros to extend beyond four borders
of the images, pad_h is the size of the top and bottom margins,
and pad_w is the size of the left and right margins.
Returns
-------
list
The shape of the output from this op, for input of given shape.
This will have the same length as imgshape, but with last two
elements reduced as per the downsampling & ignore_border flags.
"""
if
len
(
imgshape
)
<
2
:
raise
TypeError
(
'imgshape must have at least two elements '
'(rows, cols)'
)
if
st
is
None
:
st
=
ds
r
,
c
=
imgshape
[
-
2
:]
r
+=
padding
[
0
]
*
2
c
+=
padding
[
1
]
*
2
if
ignore_border
:
out_r
=
(
r
-
ds
[
0
])
//
st
[
0
]
+
1
out_c
=
(
c
-
ds
[
1
])
//
st
[
1
]
+
1
if
isinstance
(
r
,
theano
.
Variable
):
nr
=
tensor
.
maximum
(
out_r
,
0
)
else
:
nr
=
numpy
.
maximum
(
out_r
,
0
)
if
isinstance
(
c
,
theano
.
Variable
):
nc
=
tensor
.
maximum
(
out_c
,
0
)
else
:
nc
=
numpy
.
maximum
(
out_c
,
0
)
else
:
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
)
elif
st
[
0
]
>=
ds
[
0
]:
nr
=
(
r
-
1
)
//
st
[
0
]
+
1
else
:
nr
=
max
(
0
,
(
r
-
1
-
ds
[
0
])
//
st
[
0
]
+
1
)
+
1
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
)
elif
st
[
1
]
>=
ds
[
1
]:
nc
=
(
c
-
1
)
//
st
[
1
]
+
1
else
:
nc
=
max
(
0
,
(
c
-
1
-
ds
[
1
])
//
st
[
1
]
+
1
)
+
1
rval
=
list
(
imgshape
[:
-
2
])
+
[
nr
,
nc
]
return
rval
def
__init__
(
self
,
ds
,
ignore_border
,
st
=
None
,
padding
=
(
0
,
0
),
mode
=
'max'
):
def
__init__
(
self
,
ds
,
ignore_border
,
st
=
None
,
padding
=
(
0
,
0
),
mode
=
'max'
):
self
.
ds
=
tuple
(
ds
)
self
.
ds
=
tuple
(
ds
)
if
not
all
([
isinstance
(
d
,
int
)
for
d
in
ds
]):
if
not
all
([
isinstance
(
d
,
int
)
for
d
in
ds
]):
...
@@ -1017,10 +939,8 @@ class DownsampleFactorMaxGradGrad(Op):
...
@@ -1017,10 +939,8 @@ class DownsampleFactorMaxGradGrad(Op):
if
len
(
x
.
shape
)
!=
4
:
if
len
(
x
.
shape
)
!=
4
:
raise
NotImplementedError
(
raise
NotImplementedError
(
'DownsampleFactorMaxGradGrad requires 4D input for now'
)
'DownsampleFactorMaxGradGrad requires 4D input for now'
)
z_shape
=
self
.
out_shape
(
x
.
shape
,
self
.
ds
,
self
.
ignore_border
,
if
(
z
[
0
]
is
None
)
or
(
z
[
0
]
.
shape
!=
x
.
shape
):
self
.
st
,
self
.
padding
)
z
[
0
]
=
numpy
.
zeros
(
x
.
shape
,
dtype
=
x
.
dtype
)
if
(
z
[
0
]
is
None
)
or
(
z
[
0
]
.
shape
!=
z_shape
):
z
[
0
]
=
numpy
.
zeros
(
z_shape
,
dtype
=
x
.
dtype
)
ggz
=
z
[
0
]
# grad wrt maxout_grad has the same shape as maxout
ggz
=
z
[
0
]
# grad wrt maxout_grad has the same shape as maxout
# number of pooling output rows
# number of pooling output rows
pr
=
ggz
.
shape
[
-
2
]
pr
=
ggz
.
shape
[
-
2
]
...
...
theano/tensor/signal/tests/test_downsample.py
浏览文件 @
179d6fba
...
@@ -582,7 +582,7 @@ class TestDownsampleFactorMax(utt.InferShapeTester):
...
@@ -582,7 +582,7 @@ class TestDownsampleFactorMax(utt.InferShapeTester):
stridesize
=
stridesizes
[
i
]
stridesize
=
stridesizes
[
i
]
paddingsize
=
paddingsizes
[
i
]
paddingsize
=
paddingsizes
[
i
]
grad_shape
=
DownsampleFactorMax
GradGrad
.
out_shape
(
imval
.
shape
,
grad_shape
=
DownsampleFactorMax
.
out_shape
(
imval
.
shape
,
maxpoolsize
,
st
=
stridesize
,
maxpoolsize
,
st
=
stridesize
,
ignore_border
=
True
,
ignore_border
=
True
,
padding
=
paddingsize
)
padding
=
paddingsize
)
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论