Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
a8dc2e3b
提交
a8dc2e3b
authored
5月 19, 2017
作者:
botev
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Addressed all suggestions.
上级
bae4eb91
显示空白字符变更
内嵌
并排
正在显示
2 个修改的文件
包含
21 行增加
和
26 行删除
+21
-26
neighbours.py
theano/tensor/nnet/neighbours.py
+4
-13
test_neighbours.py
theano/tensor/nnet/tests/test_neighbours.py
+17
-13
没有找到文件。
theano/tensor/nnet/neighbours.py
浏览文件 @
a8dc2e3b
...
@@ -30,8 +30,8 @@ class Images2Neibs(Op):
...
@@ -30,8 +30,8 @@ class Images2Neibs(Op):
- 'wrap_centered' :
- 'wrap_centered' :
?? TODO comment
?? TODO comment
- 'half' :
- 'half' :
Equivalent to 'valid' if we pre-pad
the input on each side by
Equivalent to 'valid' if we pre-pad
with zeros the input on
(neib_shape[0]//2, neib_shape[1]//2)
each side by
(neib_shape[0]//2, neib_shape[1]//2)
"""
"""
...
@@ -525,12 +525,6 @@ class Images2Neibs(Op):
...
@@ -525,12 +525,6 @@ class Images2Neibs(Op):
if (ten4_2 < 0 | ten4_2 >= height) {
if (ten4_2 < 0 | ten4_2 >= height) {
dtype_
%(z)
s* curr_z = (dtype_
%(z)
s*) PyArray_GETPTR2(
%(z)
s, z_row, d * i);
dtype_
%(z)
s* curr_z = (dtype_
%(z)
s*) PyArray_GETPTR2(
%(z)
s, z_row, d * i);
memset(curr_z, 0, d*sizeof(*curr_z));
memset(curr_z, 0, d*sizeof(*curr_z));
// for (int j = 0; j < d; j++) // loop over d
// {
// int z_col = j + d * i;
// dtype_
%(z)
s* curr_z = (dtype_
%(z)
s*) PyArray_GETPTR2(
%(z)
s, z_row, z_col);
// *curr_z = 0;
// }
} else {
} else {
for (int j = 0; j < d; j++) // loop over d
for (int j = 0; j < d; j++) // loop over d
{
{
...
@@ -549,9 +543,6 @@ class Images2Neibs(Op):
...
@@ -549,9 +543,6 @@ class Images2Neibs(Op):
} else {
} else {
*curr_z = *( (dtype_
%(ten4)
s*) PyArray_GETPTR4(
%(ten4)
s, n, s, ten4_2, ten4_3));
*curr_z = *( (dtype_
%(ten4)
s*) PyArray_GETPTR4(
%(ten4)
s, n, s, ten4_2, ten4_3));
}
}
//printf("
\\
n(
%%
i,
%%
i,
%%
i,
%%
i) --> (
%%
i,
%%
i)",
// n, s, ten4_2, ten4_3, z_row, z_col);
//printf("
%%
f ", *curr_z);
}
}
}
}
}
}
...
@@ -598,8 +589,8 @@ def images2neibs(ten4, neib_shape, neib_step=None, mode='valid'):
...
@@ -598,8 +589,8 @@ def images2neibs(ten4, neib_shape, neib_step=None, mode='valid'):
``wrap_centered``
``wrap_centered``
?? TODO comment
?? TODO comment
``half``
``half``
Equivalent to 'valid' if we pre-pad
the input on each side by
Equivalent to 'valid' if we pre-pad
with zeros the input on
(neib_shape[0]//2, neib_shape[1]//2)
each side by
(neib_shape[0]//2, neib_shape[1]//2)
Returns
Returns
-------
-------
...
...
theano/tensor/nnet/tests/test_neighbours.py
浏览文件 @
a8dc2e3b
...
@@ -237,17 +237,18 @@ class T_Images2Neibs(unittest_tools.InferShapeTester):
...
@@ -237,17 +237,18 @@ class T_Images2Neibs(unittest_tools.InferShapeTester):
# assert numpy.allclose(images.get_value(borrow=True), g())
# assert numpy.allclose(images.get_value(borrow=True), g())
def
test_neibs_half_step_by_valid
(
self
):
def
test_neibs_half_step_by_valid
(
self
):
for
shp_idx
,
(
shape
,
neib_s
hape
,
neib_s
tep
)
in
enumerate
([
for
shp_idx
,
(
shape
,
neib_step
)
in
enumerate
([
[(
7
,
8
,
5
,
5
),
(
3
,
3
),
(
1
,
1
)],
[(
7
,
8
,
5
,
5
),
(
1
,
1
)],
[(
7
,
8
,
5
,
5
),
(
3
,
3
),
(
2
,
2
)],
[(
7
,
8
,
5
,
5
),
(
2
,
2
)],
[(
7
,
8
,
5
,
5
),
(
3
,
3
),
(
4
,
4
)],
[(
7
,
8
,
5
,
5
),
(
4
,
4
)],
[(
7
,
8
,
5
,
5
),
(
3
,
3
),
(
1
,
4
)],
[(
7
,
8
,
5
,
5
),
(
1
,
4
)],
[(
7
,
8
,
5
,
5
),
(
3
,
3
),
(
4
,
1
)],
[(
7
,
8
,
5
,
5
),
(
4
,
1
)],
[(
80
,
90
,
5
,
5
),
(
3
,
3
),
(
1
,
2
)],
[(
80
,
90
,
5
,
5
),
(
1
,
2
)],
[(
1025
,
9
,
5
,
5
),
(
3
,
3
),
(
2
,
1
)],
[(
1025
,
9
,
5
,
5
),
(
2
,
1
)],
[(
1
,
1
,
5
,
1037
),
(
3
,
3
),
(
2
,
4
)],
[(
1
,
1
,
5
,
1037
),
(
2
,
4
)],
[(
1
,
1
,
1045
,
5
),
(
3
,
3
),
(
4
,
2
)]]
[(
1
,
1
,
1045
,
5
),
(
4
,
2
)]]
):
):
for
neib_shape
in
[(
3
,
3
),
(
3
,
5
),
(
5
,
3
)]:
for
dtype
in
self
.
dtypes
:
for
dtype
in
self
.
dtypes
:
x
=
theano
.
shared
(
np
.
random
.
randn
(
*
shape
)
.
astype
(
dtype
))
x
=
theano
.
shared
(
np
.
random
.
randn
(
*
shape
)
.
astype
(
dtype
))
extra
=
(
neib_shape
[
0
]
//
2
,
neib_shape
[
1
]
//
2
)
extra
=
(
neib_shape
[
0
]
//
2
,
neib_shape
[
1
]
//
2
)
...
@@ -257,7 +258,8 @@ class T_Images2Neibs(unittest_tools.InferShapeTester):
...
@@ -257,7 +258,8 @@ class T_Images2Neibs(unittest_tools.InferShapeTester):
x_using_valid
=
images2neibs
(
padded_x
,
neib_shape
,
neib_step
,
mode
=
"valid"
)
x_using_valid
=
images2neibs
(
padded_x
,
neib_shape
,
neib_step
,
mode
=
"valid"
)
x_using_half
=
images2neibs
(
x
,
neib_shape
,
neib_step
,
mode
=
"half"
)
x_using_half
=
images2neibs
(
x
,
neib_shape
,
neib_step
,
mode
=
"half"
)
close
=
T
.
allclose
(
x_using_valid
,
x_using_half
)
close
=
T
.
allclose
(
x_using_valid
,
x_using_half
)
assert
close
.
eval
()
f
=
theano
.
function
([],
close
,
mode
=
self
.
mode
)
assert
f
()
def
test_neibs_bad_shape_wrap_centered
(
self
):
def
test_neibs_bad_shape_wrap_centered
(
self
):
shape
=
(
2
,
3
,
10
,
10
)
shape
=
(
2
,
3
,
10
,
10
)
...
@@ -387,7 +389,8 @@ class T_Images2Neibs(unittest_tools.InferShapeTester):
...
@@ -387,7 +389,8 @@ class T_Images2Neibs(unittest_tools.InferShapeTester):
img
=
T
.
tensor4
(
'img'
)
img
=
T
.
tensor4
(
'img'
)
patches
=
T
.
nnet
.
neighbours
.
images2neibs
(
img
,
[
16
,
16
])
patches
=
T
.
nnet
.
neighbours
.
images2neibs
(
img
,
[
16
,
16
])
extractPatches
=
theano
.
function
([
img
],
patches
)
extractPatches
=
theano
.
function
([
img
],
patches
,
mode
=
self
.
mode
)
patsRecovery
=
T
.
matrix
(
'patsRecovery'
)
patsRecovery
=
T
.
matrix
(
'patsRecovery'
)
original_size
=
T
.
ivector
(
'original_size'
)
original_size
=
T
.
ivector
(
'original_size'
)
...
@@ -395,7 +398,8 @@ class T_Images2Neibs(unittest_tools.InferShapeTester):
...
@@ -395,7 +398,8 @@ class T_Images2Neibs(unittest_tools.InferShapeTester):
for
mode
in
[
'valid'
,
'ignore_borders'
]:
for
mode
in
[
'valid'
,
'ignore_borders'
]:
out
=
neibs2images
(
patsRecovery
,
(
16
,
16
),
out
=
neibs2images
(
patsRecovery
,
(
16
,
16
),
original_size
,
mode
=
mode
)
original_size
,
mode
=
mode
)
f
=
theano
.
function
([
patsRecovery
,
original_size
],
out
)
f
=
theano
.
function
([
patsRecovery
,
original_size
],
out
,
mode
=
self
.
mode
)
im_val
=
np
.
ones
((
1
,
3
,
320
,
320
),
dtype
=
np
.
float32
)
im_val
=
np
.
ones
((
1
,
3
,
320
,
320
),
dtype
=
np
.
float32
)
neibs
=
extractPatches
(
im_val
)
neibs
=
extractPatches
(
im_val
)
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论