Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
26c105c9
提交
26c105c9
authored
11月 28, 2014
作者:
Sina Honari
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
applying changes to the case where stride is used for issue #2196
上级
a127689e
隐藏空白字符变更
内嵌
并排
正在显示
2 个修改的文件
包含
34 行增加
和
50 行删除
+34
-50
downsample.py
theano/tensor/signal/downsample.py
+19
-28
test_downsample.py
theano/tensor/signal/tests/test_downsample.py
+15
-22
没有找到文件。
theano/tensor/signal/downsample.py
浏览文件 @
26c105c9
...
@@ -104,40 +104,31 @@ class DownsampleFactorMax(Op):
...
@@ -104,40 +104,31 @@ class DownsampleFactorMax(Op):
out_r
=
(
r
-
ds
[
0
])
//
st
[
0
]
+
1
out_r
=
(
r
-
ds
[
0
])
//
st
[
0
]
+
1
out_c
=
(
c
-
ds
[
1
])
//
st
[
1
]
+
1
out_c
=
(
c
-
ds
[
1
])
//
st
[
1
]
+
1
nr
=
0
nc
=
0
if
isinstance
(
r
,
theano
.
Variable
):
if
isinstance
(
r
,
theano
.
Variable
):
nr
=
tensor
.
switch
(
tensor
.
ge
(
r
-
ds
[
0
],
0
),
out_r
,
0
)
nr
=
tensor
.
maximum
(
out_r
,
0
)
el
if
r
-
ds
[
0
]
>=
0
:
el
se
:
nr
=
out_r
nr
=
numpy
.
maximum
(
out_r
,
0
)
if
isinstance
(
c
,
theano
.
Variable
):
if
isinstance
(
c
,
theano
.
Variable
):
n
r
=
tensor
.
switch
(
tensor
.
ge
(
c
-
ds
[
1
],
0
),
out_c
,
0
)
n
c
=
tensor
.
maximum
(
out_c
,
0
)
el
if
c
-
ds
[
1
]
>=
0
:
el
se
:
nc
=
out_c
nc
=
numpy
.
maximum
(
out_c
,
0
)
out_re
=
0
out_ce
=
0
if
not
ignore_border
:
if
not
ignore_border
:
re
=
r
-
((
out_r
-
1
)
*
st
[
0
]
+
ds
[
0
])
rr
=
r
-
out_r
*
st
[
0
]
ce
=
c
-
((
out_c
-
1
)
*
st
[
1
]
+
ds
[
1
])
cr
=
c
-
out_c
*
st
[
1
]
if
isinstance
(
r
,
theano
.
Variable
):
if
isinstance
(
r
,
theano
.
Variable
):
out_re
=
tensor
.
switch
(
tensor
.
gt
(
nr
,
0
),
tensor
.
switch
(
tensor
.
gt
(
re
,
0
),
tensor
.
switch
(
tensor
.
gt
(
rr
,
0
),
1
,
0
),
0
),
tensor
.
switch
(
tensor
.
gt
(
r
,
0
),
1
,
0
)
)
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
nr
>
0
:
elif
st
[
0
]
>=
ds
[
0
]:
if
re
>
0
and
rr
>
0
:
nr
=
(
r
-
1
)
//
st
[
0
]
+
1
out_re
=
1
else
:
elif
r
>
0
:
nr
=
max
(
0
,
(
r
-
1
-
ds
[
0
])
//
st
[
0
]
+
1
)
+
1
out_re
=
1
if
isinstance
(
c
,
theano
.
Variable
):
if
isinstance
(
c
,
theano
.
Variable
):
out_ce
=
tensor
.
switch
(
tensor
.
gt
(
nc
,
0
),
tensor
.
switch
(
tensor
.
gt
(
ce
,
0
),
tensor
.
switch
(
tensor
.
gt
(
cr
,
0
),
1
,
0
),
0
),
tensor
.
switch
(
tensor
.
gt
(
c
,
0
),
1
,
0
))
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
nc
>
0
:
elif
st
[
1
]
>=
ds
[
1
]:
if
ce
>
0
and
cr
>
0
:
nc
=
(
c
-
1
)
//
st
[
1
]
+
1
out_ce
=
1
else
:
elif
c
>
0
:
nc
=
max
(
0
,
(
c
-
1
-
ds
[
1
])
//
st
[
1
]
+
1
)
+
1
out_ce
=
1
nr
+=
out_re
nc
+=
out_ce
rval
=
list
(
imgshape
[:
-
2
])
+
[
nr
,
nc
]
rval
=
list
(
imgshape
[:
-
2
])
+
[
nr
,
nc
]
return
rval
return
rval
...
...
theano/tensor/signal/tests/test_downsample.py
浏览文件 @
26c105c9
...
@@ -122,7 +122,7 @@ class TestDownsampleFactorMax(utt.InferShapeTester):
...
@@ -122,7 +122,7 @@ class TestDownsampleFactorMax(utt.InferShapeTester):
ignore_border
=
ignore_border
)(
images
)
ignore_border
=
ignore_border
)(
images
)
f
=
function
([
images
],
maxpool_op
)
f
=
function
([
images
],
maxpool_op
)
output_val
=
f
(
imval
)
output_val
=
f
(
imval
)
assert
(
numpy
.
abs
(
output_val
-
numpy_output_val
)
<
1e-5
)
.
all
(
)
utt
.
assert_allclose
(
output_val
,
numpy_output_val
)
def
test_DownsampleFactorMaxStride
(
self
):
def
test_DownsampleFactorMaxStride
(
self
):
rng
=
numpy
.
random
.
RandomState
(
utt
.
fetch_seed
())
rng
=
numpy
.
random
.
RandomState
(
utt
.
fetch_seed
())
...
@@ -142,22 +142,17 @@ class TestDownsampleFactorMax(utt.InferShapeTester):
...
@@ -142,22 +142,17 @@ class TestDownsampleFactorMax(utt.InferShapeTester):
for
stride
in
stridesizes
:
for
stride
in
stridesizes
:
outputshp
=
outputshps
[
indx
]
outputshp
=
outputshps
[
indx
]
indx
+=
1
indx
+=
1
print
'maxpoolshp ='
,
maxpoolshp
print
'ignore_border ='
,
ignore_border
print
'stride ='
,
stride
#DownsampleFactorMax op
#DownsampleFactorMax op
numpy_output_val
=
self
.
numpy_max_pool_2d_stride
(
imval
,
maxpoolshp
,
numpy_output_val
=
self
.
numpy_max_pool_2d_stride
(
imval
,
maxpoolshp
,
ignore_border
,
stride
)
ignore_border
,
stride
)
print
"outshape is
%
s "
%
(
outputshp
,
)
assert
numpy_output_val
.
shape
==
outputshp
,
(
print
"calculated shape is
%
s "
%
(
numpy_output_val
.
shape
,)
"outshape is
%
s, calculated shape is
%
s"
assert
numpy_output_val
.
shape
==
outputshp
%
(
outputshp
,
numpy_output_val
.
shape
))
maxpool_op
=
DownsampleFactorMax
(
maxpoolshp
,
maxpool_op
=
DownsampleFactorMax
(
maxpoolshp
,
ignore_border
=
ignore_border
,
st
=
stride
)(
images
)
ignore_border
=
ignore_border
,
st
=
stride
)(
images
)
f
=
function
([
images
],
maxpool_op
)
f
=
function
([
images
],
maxpool_op
)
output_val
=
f
(
imval
)
output_val
=
f
(
imval
)
print
"numpy_output_val shape is
%
s"
%
(
numpy_output_val
.
shape
,)
utt
.
assert_allclose
(
output_val
,
numpy_output_val
)
assert
(
numpy
.
abs
(
output_val
-
numpy_output_val
)
<
1e-5
)
.
all
()
def
test_DownsampleFactorMaxStrideExtra
(
self
):
def
test_DownsampleFactorMaxStrideExtra
(
self
):
rng
=
numpy
.
random
.
RandomState
(
utt
.
fetch_seed
())
rng
=
numpy
.
random
.
RandomState
(
utt
.
fetch_seed
())
...
@@ -179,23 +174,17 @@ class TestDownsampleFactorMax(utt.InferShapeTester):
...
@@ -179,23 +174,17 @@ class TestDownsampleFactorMax(utt.InferShapeTester):
if
not
ignore_border
:
if
not
ignore_border
:
indx_out
+=
1
indx_out
+=
1
outputshp
=
outputshps
[
indx_out
]
outputshp
=
outputshps
[
indx_out
]
print
'maxpoolshp ='
,
maxpoolshp
print
'ignore_border ='
,
ignore_border
print
'stride ='
,
stride
#DownsampleFactorMax op
#DownsampleFactorMax op
numpy_output_val
=
self
.
numpy_max_pool_2d_stride
(
imval
,
maxpoolshp
,
numpy_output_val
=
self
.
numpy_max_pool_2d_stride
(
imval
,
maxpoolshp
,
ignore_border
,
stride
)
ignore_border
,
stride
)
print
"outshape is
%
s "
%
(
outputshp
,
)
assert
numpy_output_val
.
shape
==
outputshp
,
(
print
"calculated shape is
%
s "
%
(
numpy_output_val
.
shape
,)
"outshape is
%
s, calculated shape is
%
s"
assert
numpy_output_val
.
shape
==
outputshp
%
(
outputshp
,
numpy_output_val
.
shape
))
maxpool_op
=
DownsampleFactorMax
(
maxpoolshp
,
maxpool_op
=
DownsampleFactorMax
(
maxpoolshp
,
ignore_border
=
ignore_border
,
st
=
stride
)(
images
)
ignore_border
=
ignore_border
,
st
=
stride
)(
images
)
f
=
function
([
images
],
maxpool_op
)
f
=
function
([
images
],
maxpool_op
)
output_val
=
f
(
imval
)
output_val
=
f
(
imval
)
print
"numpy_output_val shape is
%
s"
%
(
numpy_output_val
.
shape
,)
utt
.
assert_allclose
(
output_val
,
numpy_output_val
)
print
"output_val shape is
%
s "
%
(
output_val
.
shape
,)
assert
(
numpy
.
abs
(
output_val
-
numpy_output_val
)
<
1e-5
)
.
all
()
def
test_DownsampleFactorMax_grad
(
self
):
def
test_DownsampleFactorMax_grad
(
self
):
rng
=
numpy
.
random
.
RandomState
(
utt
.
fetch_seed
())
rng
=
numpy
.
random
.
RandomState
(
utt
.
fetch_seed
())
...
@@ -266,7 +255,9 @@ class TestDownsampleFactorMax(utt.InferShapeTester):
...
@@ -266,7 +255,9 @@ class TestDownsampleFactorMax(utt.InferShapeTester):
ignore_border
)
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
),
(
"output_val is
%
s, numpy_output_val is
%
s"
%
(
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
)
...
@@ -285,7 +276,9 @@ class TestDownsampleFactorMax(utt.InferShapeTester):
...
@@ -285,7 +276,9 @@ class TestDownsampleFactorMax(utt.InferShapeTester):
ignore_border
)
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
),
(
"output_val is
%
s, numpy_output_val is
%
s"
%
(
output_val
,
numpy_output_val
))
c
=
tensor
.
sum
(
output
)
c
=
tensor
.
sum
(
output
)
c_val
=
function
([
images
],
c
)(
imval
)
c_val
=
function
([
images
],
c
)(
imval
)
g
=
tensor
.
grad
(
c
,
images
)
g
=
tensor
.
grad
(
c
,
images
)
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论