Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
c9440869
提交
c9440869
authored
4月 14, 2010
作者:
James Bergstra
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Renamed max_pool2D to max_pool_2d as per ticket #490.
上级
97787b5c
隐藏空白字符变更
内嵌
并排
正在显示
3 个修改的文件
包含
26 行增加
和
22 行删除
+26
-22
downsample.txt
doc/library/tensor/signal/downsample.txt
+1
-1
downsample.py
theano/tensor/signal/downsample.py
+6
-2
test_downsample.py
theano/tensor/signal/tests/test_downsample.py
+19
-19
没有找到文件。
doc/library/tensor/signal/downsample.txt
浏览文件 @
c9440869
...
@@ -10,7 +10,7 @@
...
@@ -10,7 +10,7 @@
.. moduleauthor:: LISA
.. moduleauthor:: LISA
.. autofunction:: theano.tensor.signal.downsample.max_pool
2D
.. autofunction:: theano.tensor.signal.downsample.max_pool
_2d
.. function:: fft(*todo)
.. function:: fft(*todo)
...
...
theano/tensor/signal/downsample.py
浏览文件 @
c9440869
...
@@ -10,7 +10,11 @@ from theano import gof, Op, tensor, Variable, Apply
...
@@ -10,7 +10,11 @@ from theano import gof, Op, tensor, Variable, Apply
import
numpy
,
theano
import
numpy
,
theano
import
__builtin__
import
__builtin__
def
max_pool2D
(
input
,
ds
,
ignore_border
=
False
):
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
(
input
,
ds
,
ignore_border
=
False
):
"""
"""
Takes as input a N-D tensor, where N >= 2. It downscales the input image by
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
the specified factor, by keeping only the maximum value of non-overlapping
...
@@ -24,7 +28,7 @@ def max_pool2D(input, ds, ignore_border=False):
...
@@ -24,7 +28,7 @@ def max_pool2D(input, ds, ignore_border=False):
(2,2) output. (3,3) otherwise.
(2,2) output. (3,3) otherwise.
"""
"""
if
input
.
ndim
<
2
:
if
input
.
ndim
<
2
:
raise
NotImplementedError
(
'max_pool
2D
requires a dimension >= 2'
)
raise
NotImplementedError
(
'max_pool
_2d
requires a dimension >= 2'
)
# extract image dimensions
# extract image dimensions
img_shape
=
input
.
shape
[
-
2
:]
img_shape
=
input
.
shape
[
-
2
:]
...
...
theano/tensor/signal/tests/test_downsample.py
浏览文件 @
c9440869
...
@@ -2,7 +2,7 @@ import unittest, sys, time
...
@@ -2,7 +2,7 @@ import unittest, sys, time
import
numpy
import
numpy
import
theano.tensor
as
tensor
import
theano.tensor
as
tensor
from
theano.tests
import
unittest_tools
as
utt
from
theano.tests
import
unittest_tools
as
utt
from
theano.tensor.signal.downsample
import
DownsampleFactorMax
,
max_pool
2D
from
theano.tensor.signal.downsample
import
DownsampleFactorMax
,
max_pool
_2d
from
theano
import
function
,
Mode
from
theano
import
function
,
Mode
...
@@ -11,8 +11,8 @@ class TestDownsampleFactorMax(unittest.TestCase):
...
@@ -11,8 +11,8 @@ class TestDownsampleFactorMax(unittest.TestCase):
utt
.
seed_rng
()
utt
.
seed_rng
()
@staticmethod
@staticmethod
def
numpy_max_pool
2D
(
input
,
ds
,
ignore_border
=
False
):
def
numpy_max_pool
_2d
(
input
,
ds
,
ignore_border
=
False
):
'''Helper function, implementing max_pool
2D
in pure numpy'''
'''Helper function, implementing max_pool
_2d
in pure numpy'''
if
len
(
input
.
shape
)
<
2
:
if
len
(
input
.
shape
)
<
2
:
raise
NotImplementedError
(
'input should have at least 2 dim, shape is
%
s'
\
raise
NotImplementedError
(
'input should have at least 2 dim, shape is
%
s'
\
%
str
(
input
.
shape
))
%
str
(
input
.
shape
))
...
@@ -54,9 +54,9 @@ class TestDownsampleFactorMax(unittest.TestCase):
...
@@ -54,9 +54,9 @@ class TestDownsampleFactorMax(unittest.TestCase):
print
'ignore_border ='
,
ignore_border
print
'ignore_border ='
,
ignore_border
## Pure Numpy computation
## Pure Numpy computation
numpy_output_val
=
self
.
numpy_max_pool
2D
(
imval
,
maxpoolshp
,
ignore_border
)
numpy_output_val
=
self
.
numpy_max_pool
_2d
(
imval
,
maxpoolshp
,
ignore_border
)
output
=
max_pool
2D
(
images
,
maxpoolshp
,
ignore_border
)
output
=
max_pool
_2d
(
images
,
maxpoolshp
,
ignore_border
)
f
=
function
([
images
,],[
output
,])
f
=
function
([
images
,],[
output
,])
output_val
=
f
(
imval
)
output_val
=
f
(
imval
)
assert
numpy
.
all
(
output_val
==
numpy_output_val
)
assert
numpy
.
all
(
output_val
==
numpy_output_val
)
...
@@ -80,7 +80,7 @@ class TestDownsampleFactorMax(unittest.TestCase):
...
@@ -80,7 +80,7 @@ class TestDownsampleFactorMax(unittest.TestCase):
return
DownsampleFactorMax
(
maxpoolshp
,
ignore_border
=
ignore_border
)(
input
)
return
DownsampleFactorMax
(
maxpoolshp
,
ignore_border
=
ignore_border
)(
input
)
utt
.
verify_grad
(
mp
,
[
imval
],
rng
=
rng
)
utt
.
verify_grad
(
mp
,
[
imval
],
rng
=
rng
)
def
test_max_pool
2D
_2D
(
self
):
def
test_max_pool
_2d
_2D
(
self
):
rng
=
numpy
.
random
.
RandomState
(
utt
.
fetch_seed
())
rng
=
numpy
.
random
.
RandomState
(
utt
.
fetch_seed
())
maxpoolshps
=
((
1
,
1
),(
3
,
2
))
maxpoolshps
=
((
1
,
1
),(
3
,
2
))
...
@@ -91,17 +91,17 @@ class TestDownsampleFactorMax(unittest.TestCase):
...
@@ -91,17 +91,17 @@ class TestDownsampleFactorMax(unittest.TestCase):
for
ignore_border
in
[
True
,
False
]:
for
ignore_border
in
[
True
,
False
]:
print
'maxpoolshp ='
,
maxpoolshp
print
'maxpoolshp ='
,
maxpoolshp
print
'ignore_border ='
,
ignore_border
print
'ignore_border ='
,
ignore_border
numpy_output_val
=
self
.
numpy_max_pool
2D
(
imval
,
maxpoolshp
,
ignore_border
)
numpy_output_val
=
self
.
numpy_max_pool
_2d
(
imval
,
maxpoolshp
,
ignore_border
)
output
=
max_pool
2D
(
images
,
maxpoolshp
,
ignore_border
)
output
=
max_pool
_2d
(
images
,
maxpoolshp
,
ignore_border
)
output_val
=
function
([
images
],
output
)(
imval
)
output_val
=
function
([
images
],
output
)(
imval
)
assert
numpy
.
all
(
output_val
==
numpy_output_val
)
assert
numpy
.
all
(
output_val
==
numpy_output_val
)
def
mp
(
input
):
def
mp
(
input
):
return
max_pool
2D
(
input
,
maxpoolshp
,
ignore_border
)
return
max_pool
_2d
(
input
,
maxpoolshp
,
ignore_border
)
utt
.
verify_grad
(
mp
,
[
imval
],
rng
=
rng
)
utt
.
verify_grad
(
mp
,
[
imval
],
rng
=
rng
)
def
test_max_pool
2D
_3D
(
self
):
def
test_max_pool
_2d
_3D
(
self
):
rng
=
numpy
.
random
.
RandomState
(
utt
.
fetch_seed
())
rng
=
numpy
.
random
.
RandomState
(
utt
.
fetch_seed
())
maxpoolshps
=
[(
1
,
2
)]
maxpoolshps
=
[(
1
,
2
)]
...
@@ -112,9 +112,9 @@ class TestDownsampleFactorMax(unittest.TestCase):
...
@@ -112,9 +112,9 @@ class TestDownsampleFactorMax(unittest.TestCase):
for
ignore_border
in
[
True
,
False
]:
for
ignore_border
in
[
True
,
False
]:
print
'maxpoolshp ='
,
maxpoolshp
print
'maxpoolshp ='
,
maxpoolshp
print
'ignore_border ='
,
ignore_border
print
'ignore_border ='
,
ignore_border
numpy_output_val
=
self
.
numpy_max_pool
2D
(
imval
,
maxpoolshp
,
ignore_border
)
numpy_output_val
=
self
.
numpy_max_pool
_2d
(
imval
,
maxpoolshp
,
ignore_border
)
output
=
max_pool
2D
(
images
,
maxpoolshp
,
ignore_border
)
output
=
max_pool
_2d
(
images
,
maxpoolshp
,
ignore_border
)
output_val
=
function
([
images
],
output
)(
imval
)
output_val
=
function
([
images
],
output
)(
imval
)
assert
numpy
.
all
(
output_val
==
numpy_output_val
)
assert
numpy
.
all
(
output_val
==
numpy_output_val
)
...
@@ -124,14 +124,14 @@ class TestDownsampleFactorMax(unittest.TestCase):
...
@@ -124,14 +124,14 @@ class TestDownsampleFactorMax(unittest.TestCase):
g
=
tensor
.
grad
(
c
,
images
)
g
=
tensor
.
grad
(
c
,
images
)
g_val
=
function
([
images
],
[
g
.
shape
,
tensor
.
min
(
tensor
.
min
(
tensor
.
min
(
g
))),
tensor
.
max
(
tensor
.
max
(
tensor
.
max
(
g
)))])(
imval
)
g_val
=
function
([
images
],
[
g
.
shape
,
tensor
.
min
(
tensor
.
min
(
tensor
.
min
(
g
))),
tensor
.
max
(
tensor
.
max
(
tensor
.
max
(
g
)))])(
imval
)
#removed as already tested in test_max_pool
2D
_2D
#removed as already tested in test_max_pool
_2d
_2D
#This make test in debug mode too slow.
#This make test in debug mode too slow.
# def mp(input):
# def mp(input):
# return max_pool
2D
(input, maxpoolshp, ignore_border)
# return max_pool
_2d
(input, maxpoolshp, ignore_border)
# utt.verify_grad(mp, [imval], rng=rng)
# utt.verify_grad(mp, [imval], rng=rng)
def
test_max_pool
2D
_6D
(
self
):
def
test_max_pool
_2d
_6D
(
self
):
rng
=
numpy
.
random
.
RandomState
(
utt
.
fetch_seed
())
rng
=
numpy
.
random
.
RandomState
(
utt
.
fetch_seed
())
maxpoolshps
=
[(
3
,
2
)]
maxpoolshps
=
[(
3
,
2
)]
...
@@ -142,16 +142,16 @@ class TestDownsampleFactorMax(unittest.TestCase):
...
@@ -142,16 +142,16 @@ class TestDownsampleFactorMax(unittest.TestCase):
for
ignore_border
in
[
True
,
False
]:
for
ignore_border
in
[
True
,
False
]:
print
'maxpoolshp ='
,
maxpoolshp
print
'maxpoolshp ='
,
maxpoolshp
print
'ignore_border ='
,
ignore_border
print
'ignore_border ='
,
ignore_border
numpy_output_val
=
self
.
numpy_max_pool
2D
(
imval
,
maxpoolshp
,
ignore_border
)
numpy_output_val
=
self
.
numpy_max_pool
_2d
(
imval
,
maxpoolshp
,
ignore_border
)
output
=
max_pool
2D
(
images
,
maxpoolshp
,
ignore_border
)
output
=
max_pool
_2d
(
images
,
maxpoolshp
,
ignore_border
)
output_val
=
function
([
images
],
output
)(
imval
)
output_val
=
function
([
images
],
output
)(
imval
)
assert
numpy
.
all
(
output_val
==
numpy_output_val
)
assert
numpy
.
all
(
output_val
==
numpy_output_val
)
#removed as already tested in test_max_pool
2D
_2D
#removed as already tested in test_max_pool
_2d
_2D
#This make test in debug mode too slow.
#This make test in debug mode too slow.
# def mp(input):
# def mp(input):
# return max_pool
2D
(input, maxpoolshp, ignore_border)
# return max_pool
_2d
(input, maxpoolshp, ignore_border)
# utt.verify_grad(mp, [imval], rng=rng)
# utt.verify_grad(mp, [imval], rng=rng)
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论