Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
0581942d
提交
0581942d
authored
1月 21, 2010
作者:
gdesjardins
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Added max_pool2D function. Takes as input an N-d tensor and creates/calls
DownsampleFactorMax to perform max pooling over the trailing two dimensions.
上级
8d11831d
隐藏空白字符变更
内嵌
并排
正在显示
1 个修改的文件
包含
43 行增加
和
2 行删除
+43
-2
downsample.py
theano/sandbox/downsample.py
+43
-2
没有找到文件。
theano/sandbox/downsample.py
浏览文件 @
0581942d
...
@@ -12,6 +12,7 @@ import numpy
...
@@ -12,6 +12,7 @@ import numpy
import
__builtin__
import
__builtin__
class
DownsampleFactorMaxGrad
(
Op
):
class
DownsampleFactorMaxGrad
(
Op
):
def
__init__
(
self
,
ds
,
ignore_border
):
def
__init__
(
self
,
ds
,
ignore_border
):
self
.
ds
=
tuple
(
ds
)
self
.
ds
=
tuple
(
ds
)
self
.
ignore_border
=
ignore_border
self
.
ignore_border
=
ignore_border
...
@@ -147,10 +148,48 @@ class DownsampleFactorMaxGrad(Op):
...
@@ -147,10 +148,48 @@ class DownsampleFactorMaxGrad(Op):
return
()
return
()
def
max_pool2D
(
input
,
ds
,
ignore_border
=
False
):
"""
Takes as input a N-D tensor, where N >= 2. It downscales the input image by
the specified factor, by keeping only the maximum value of non-overlapping
patches of size (ds[0],ds[1])
:type input: N-D theano tensor of input images.
:param input: input images. Max pooling will be done over the 2 last dimensions.
:type ds: tuple of length 2
:param ds: factor by which to downscale. (2,2) will halve the image in each
dimension.
:param ignore_border: boolean value. When True, (5,5) input with ds=(2,2)
will generate a (2,2) output. (3,3) otherwise.
"""
if
input
.
ndim
<
2
:
raise
NotImplementedError
(
'max_pool2D requires a dimension >= 2'
)
# extract image dimensions
img_shape
=
input
.
shape
[
-
2
:]
# count the number of "leading" dimensions, store as dmatrix
batch_size
=
tensor
.
prod
(
input
.
shape
[:
-
2
])
batch_size
=
tensor
.
shape_padright
(
batch_size
,
1
)
# store as 4D tensor with shape: (batch_size,1,height,width)
new_shape
=
tensor
.
cast
(
tensor
.
join
(
0
,
batch_size
,
tensor
.
as_tensor
([
1
,]),
img_shape
),
'int64'
)
input_4D
=
tensor
.
reshape
(
input
,
new_shape
,
ndim
=
4
)
# downsample mini-batch of images
op
=
DownsampleFactorMax
(
ds
,
ignore_border
)
output
=
op
(
input_4D
)
# restore to original shape
outshp
=
tensor
.
join
(
0
,
input
.
shape
[:
-
2
],
output
.
shape
[
-
2
:])
return
tensor
.
reshape
(
output
,
outshp
,
ndim
=
input
.
ndim
)
class
DownsampleFactorMax
(
Op
):
class
DownsampleFactorMax
(
Op
):
"""
"""
For N-dimensional tensors, consider that the last two dimensions span images.
For N-dimensional tensors, consider that the last two dimensions span images.
This Op downsamples these images by taking the max over non-overlapping rectangular regions.
This Op downsamples these images by a factor ds, by taking the max over non-
overlapping rectangular regions.
"""
"""
@staticmethod
@staticmethod
...
@@ -192,6 +231,8 @@ class DownsampleFactorMax(Op):
...
@@ -192,6 +231,8 @@ class DownsampleFactorMax(Op):
:param ignore_border: if ds doesn't divide imgshape, do we include an extra row/col of
:param ignore_border: if ds doesn't divide imgshape, do we include an extra row/col of
partial downsampling (False) or ignore it (True).
partial downsampling (False) or ignore it (True).
:type ignore_border: bool
:type ignore_border: bool
TODO: why is poolsize an op parameter here?
"""
"""
self
.
ds
=
tuple
(
ds
)
self
.
ds
=
tuple
(
ds
)
self
.
ignore_border
=
ignore_border
self
.
ignore_border
=
ignore_border
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论