Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
92b16a0a
提交
92b16a0a
authored
4月 09, 2015
作者:
Li Yao
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
all tests passed in DebugMode
上级
34db0b63
隐藏空白字符变更
内嵌
并排
正在显示
2 个修改的文件
包含
40 行增加
和
8 行删除
+40
-8
downsample.py
theano/tensor/signal/downsample.py
+39
-7
test_downsample.py
theano/tensor/signal/tests/test_downsample.py
+1
-1
没有找到文件。
theano/tensor/signal/downsample.py
浏览文件 @
92b16a0a
...
@@ -311,16 +311,38 @@ class DownsampleFactorMax(Op):
...
@@ -311,16 +311,38 @@ class DownsampleFactorMax(Op):
c = PyArray_DIMS(
%(x)
s)[3];
c = PyArray_DIMS(
%(x)
s)[3];
r +=
%(pd0)
s * 2;
r +=
%(pd0)
s * 2;
c +=
%(pd1)
s * 2;
c +=
%(pd1)
s * 2;
if (
%(pd0)
s != 0 &&
%(pd1)
s != 0 && !
%(ignore_border)
s)
{
PyErr_SetString(PyExc_ValueError,
"padding must be (0,0) when ignore border is False");
%(fail)
s;
}
if (
%(ignore_border)
s)
if (
%(ignore_border)
s)
{
{
z_r = (r -
%(ds0)
s) /
%(st0)
s + 1;
z_c = (c -
%(ds1)
s) /
%(st1)
s + 1;
// '/' in C is different from '/' in python
if (r -
%(ds0)
s < 0)
{
z_r = 0;
}
else
{
z_r = (r -
%(ds0)
s) /
%(st0)
s + 1;
}
if (c -
%(ds1)
s < 0)
{
z_c = 0;
}
else
{
z_c = (c -
%(ds1)
s) /
%(st1)
s + 1;
}
}
}
else
else
{
{
// decide how many rows the output has
// decide how many rows the output has
if (
%(st0)
s >
%(ds0)
s)
if (
%(st0)
s >
=
%(ds0)
s)
{
{
z_r = (r - 1) /
%(st0)
s + 1;
z_r = (r - 1) /
%(st0)
s + 1;
}
}
...
@@ -329,7 +351,7 @@ class DownsampleFactorMax(Op):
...
@@ -329,7 +351,7 @@ class DownsampleFactorMax(Op):
z_r = std::max(0, (r - 1 -
%(ds0)
s) /
%(st0)
s + 1) + 1;
z_r = std::max(0, (r - 1 -
%(ds0)
s) /
%(st0)
s + 1) + 1;
}
}
// decide how many columns the output has
// decide how many columns the output has
if (
%(st1)
s >
%(ds1)
s)
if (
%(st1)
s >
=
%(ds1)
s)
{
{
z_c = (c - 1) /
%(st1)
s + 1;
z_c = (c - 1) /
%(st1)
s + 1;
}
}
...
@@ -373,6 +395,12 @@ class DownsampleFactorMax(Op):
...
@@ -373,6 +395,12 @@ class DownsampleFactorMax(Op):
// from padded_img space to img space
// from padded_img space to img space
r_st -=
%(pd0)
s;
r_st -=
%(pd0)
s;
r_end -=
%(pd0)
s;
r_end -=
%(pd0)
s;
// handle the case where no padding, ignore border is True
if (
%(ignore_border)
s)
{
r_end = r_end > r ? r : r_end;
}
for(int j=0; j<z_c; j++){
for(int j=0; j<z_c; j++){
c_st = j *
%(st1)
s;
c_st = j *
%(st1)
s;
c_end = c_st +
%(ds1)
s;
c_end = c_st +
%(ds1)
s;
...
@@ -384,6 +412,11 @@ class DownsampleFactorMax(Op):
...
@@ -384,6 +412,11 @@ class DownsampleFactorMax(Op):
// change coordinates from padding_img space into img space
// change coordinates from padding_img space into img space
c_st -=
%(pd1)
s;
c_st -=
%(pd1)
s;
c_end -=
%(pd1)
s;
c_end -=
%(pd1)
s;
// handle the case where no padding, ignore border is True
if (
%(ignore_border)
s)
{
c_end = c_end > c ? c : c_end;
}
// use the first element as the initial value of maximum
// use the first element as the initial value of maximum
maximum = ((dtype_
%(x)
s*)(PyArray_GETPTR4(
%(x)
s,b,k,r_st,c_st)))[0];
maximum = ((dtype_
%(x)
s*)(PyArray_GETPTR4(
%(x)
s,b,k,r_st,c_st)))[0];
// go through the pooled region in the unpadded input
// go through the pooled region in the unpadded input
...
@@ -404,7 +437,7 @@ class DownsampleFactorMax(Op):
...
@@ -404,7 +437,7 @@ class DownsampleFactorMax(Op):
"""
%
locals
()
"""
%
locals
()
def
c_code_cache_version
(
self
):
def
c_code_cache_version
(
self
):
return
(
0
,
5
)
return
(
0
,
6
)
class
DownsampleFactorMaxGrad
(
Op
):
class
DownsampleFactorMaxGrad
(
Op
):
...
@@ -448,7 +481,6 @@ class DownsampleFactorMaxGrad(Op):
...
@@ -448,7 +481,6 @@ class DownsampleFactorMaxGrad(Op):
pad_w
=
self
.
padding
[
1
]
pad_w
=
self
.
padding
[
1
]
img_rows
=
x
.
shape
[
-
2
]
+
2
*
pad_h
img_rows
=
x
.
shape
[
-
2
]
+
2
*
pad_h
img_cols
=
x
.
shape
[
-
1
]
+
2
*
pad_w
img_cols
=
x
.
shape
[
-
1
]
+
2
*
pad_w
# pad the image
# pad the image
if
self
.
padding
!=
(
0
,
0
):
if
self
.
padding
!=
(
0
,
0
):
fill
=
x
.
min
()
-
1
fill
=
x
.
min
()
-
1
...
...
theano/tensor/signal/tests/test_downsample.py
浏览文件 @
92b16a0a
...
@@ -472,7 +472,7 @@ class TestDownsampleFactorMax(utt.InferShapeTester):
...
@@ -472,7 +472,7 @@ class TestDownsampleFactorMax(utt.InferShapeTester):
[
0.
,
0.
,
0.
,
0.
],
[
0.
,
0.
,
0.
,
0.
],
[
0.
,
6.
,
0.
,
8.
]
[
0.
,
6.
,
0.
,
8.
]
]]])
]]])
input
=
tensor
.
tensor4
(
name
=
'input'
)
input
=
tensor
.
d
tensor4
(
name
=
'input'
)
patch_size
=
(
2
,
2
)
patch_size
=
(
2
,
2
)
op
=
max_pool_2d_same_size
(
input
,
patch_size
)
op
=
max_pool_2d_same_size
(
input
,
patch_size
)
op_output
=
function
([
input
],
op
)(
test_input_array
)
op_output
=
function
([
input
],
op
)(
test_input_array
)
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论