Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
5a8eaaf6
提交
5a8eaaf6
authored
3月 27, 2015
作者:
rolf
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
implements max_pool_2d_same_size + test
上级
055d1774
隐藏空白字符变更
内嵌
并排
正在显示
2 个修改的文件
包含
41 行增加
和
2 行删除
+41
-2
downsample.py
theano/tensor/signal/downsample.py
+17
-1
test_downsample.py
theano/tensor/signal/tests/test_downsample.py
+24
-1
没有找到文件。
theano/tensor/signal/downsample.py
100644 → 100755
浏览文件 @
5a8eaaf6
...
...
@@ -18,6 +18,23 @@ def max_pool2D(*args, **kwargs):
print
>>
sys
.
stderr
,
"DEPRECATION: max_pool2D renamed to max_pool_2d"
return
max_pool_2d
(
*
args
,
**
kwargs
)
def
max_pool_2d_same_size
(
input
,
patch_size
):
"""
Takes as input a 4-D tensor. It sets all non maximum values
of non-overlapping patches of size (patch_size[0],patch_size[1]) to zero,
keeping only the maximum values. The output has the same dimensions as
the input.
:type input: 4-D theano tensor of input images.
:param input: input images. Max pooling will be done over the 2 last
dimensions.
:type patch_size: tuple of length 2
:param patch_size: size of the patch (patch height, patch width).
(2,2) will retain only one non-zero value per patch of 4 values.
"""
output
=
DownsampleFactorMax
(
patch_size
,
True
)(
input
)
outs
=
DownsampleFactorMaxGrad
(
patch_size
,
True
)(
input
,
output
,
output
)
return
outs
def
max_pool_2d
(
input
,
ds
,
ignore_border
=
False
,
st
=
None
,
padding
=
(
0
,
0
)):
"""
...
...
@@ -43,7 +60,6 @@ def max_pool_2d(input, ds, ignore_border=False, st=None, padding=(0, 0)):
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.
:type padding: tuple of two ints
"""
if
input
.
ndim
<
2
:
raise
NotImplementedError
(
'max_pool_2d requires a dimension >= 2'
)
...
...
theano/tensor/signal/tests/test_downsample.py
100644 → 100755
浏览文件 @
5a8eaaf6
...
...
@@ -4,7 +4,7 @@ import numpy
import
theano.tensor
as
tensor
from
theano.tests
import
unittest_tools
as
utt
from
theano.tensor.signal.downsample
import
(
DownsampleFactorMax
,
max_pool_2d
,
DownsampleFactorMaxGrad
)
DownsampleFactorMaxGrad
,
max_pool_2d_same_size
)
from
theano
import
function
...
...
@@ -464,6 +464,29 @@ class TestDownsampleFactorMax(utt.InferShapeTester):
return
max_pool_2d
(
input
,
maxpoolshp
,
ignore_border
)
utt
.
verify_grad
(
mp
,
[
imval
],
rng
=
rng
)
def
test_max_pool_2d_2D_same_size
(
self
):
rng
=
numpy
.
random
.
RandomState
(
utt
.
fetch_seed
())
test_input_array
=
numpy
.
array
([[[
[
1.
,
2.
,
3.
,
4.
],
[
5.
,
6.
,
7.
,
8.
]
]]])
test_answer_array
=
numpy
.
array
([[[
[
0.
,
0.
,
0.
,
0.
],
[
0.
,
6.
,
0.
,
8.
]
]]])
input
=
tensor
.
tensor4
(
name
=
'input'
)
patch_size
=
(
2
,
2
)
op
=
max_pool_2d_same_size
(
input
,
patch_size
)
op_output
=
function
([
input
],
op
)(
test_input_array
)
assert
numpy
.
all
(
op_output
==
test_answer_array
),
(
"op_output is
%
s, test_answer_array is
%
s"
%
(
op_output
,
numpy_output_val
)
)
def
mp
(
input
):
return
max_pool_2d_same_size
(
input
,
patch_size
)
utt
.
verify_grad
(
mp
,
[
test_input_array
],
rng
=
rng
)
def
test_max_pool_2d_3D
(
self
):
rng
=
numpy
.
random
.
RandomState
(
utt
.
fetch_seed
())
maxpoolshps
=
[(
1
,
2
)]
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论