Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
b18629bd
提交
b18629bd
authored
9月 06, 2012
作者:
Pascal Lamblin
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Test img2neibs with only float32 on GPU, other dtypes on CPU
上级
aa9590f9
隐藏空白字符变更
内嵌
并排
正在显示
2 个修改的文件
包含
167 行增加
和
138 行删除
+167
-138
test_neighbours.py
theano/sandbox/cuda/tests/test_neighbours.py
+1
-0
test_neighbours.py
theano/sandbox/test_neighbours.py
+166
-138
没有找到文件。
theano/sandbox/cuda/tests/test_neighbours.py
浏览文件 @
b18629bd
...
@@ -20,6 +20,7 @@ else:
...
@@ -20,6 +20,7 @@ else:
class
T_GpuImages2Neibs
(
theano
.
sandbox
.
test_neighbours
.
T_Images2Neibs
):
class
T_GpuImages2Neibs
(
theano
.
sandbox
.
test_neighbours
.
T_Images2Neibs
):
mode
=
mode_with_gpu
mode
=
mode_with_gpu
op
=
GpuImages2Neibs
op
=
GpuImages2Neibs
dtypes
=
[
'float32'
]
if
__name__
==
'__main__'
:
if
__name__
==
'__main__'
:
unittest
.
main
()
unittest
.
main
()
theano/sandbox/test_neighbours.py
浏览文件 @
b18629bd
...
@@ -18,9 +18,11 @@ else:
...
@@ -18,9 +18,11 @@ else:
if
not
theano
.
config
.
cxx
:
if
not
theano
.
config
.
cxx
:
raise
SkipTest
(
"G++ not available, so we need to skip this test."
)
raise
SkipTest
(
"G++ not available, so we need to skip this test."
)
class
T_Images2Neibs
(
unittest_tools
.
InferShapeTester
):
class
T_Images2Neibs
(
unittest_tools
.
InferShapeTester
):
mode
=
mode_without_gpu
mode
=
mode_without_gpu
op
=
Images2Neibs
op
=
Images2Neibs
dtypes
=
[
'int64'
,
'float32'
,
'float64'
]
def
test_neibs
(
self
):
def
test_neibs
(
self
):
for
shape
,
pshape
in
[((
100
,
40
,
18
,
18
),
(
2
,
2
)),
for
shape
,
pshape
in
[((
100
,
40
,
18
,
18
),
(
2
,
2
)),
...
@@ -29,124 +31,143 @@ class T_Images2Neibs(unittest_tools.InferShapeTester):
...
@@ -29,124 +31,143 @@ class T_Images2Neibs(unittest_tools.InferShapeTester):
((
10
,
40
,
68
,
66
),
(
34
,
33
))
((
10
,
40
,
68
,
66
),
(
34
,
33
))
]:
]:
for
border
in
[
'valid'
,
'ignore_borders'
]:
for
border
in
[
'valid'
,
'ignore_borders'
]:
images
=
shared
(
numpy
.
arange
(
numpy
.
prod
(
shape
))
.
reshape
(
shape
))
for
dtype
in
self
.
dtypes
:
neib_shape
=
T
.
as_tensor_variable
(
pshape
)
images
=
shared
(
numpy
.
arange
(
numpy
.
prod
(
shape
),
dtype
=
dtype
)
.
reshape
(
shape
))
neib_shape
=
T
.
as_tensor_variable
(
pshape
)
f
=
function
([],
images2neibs
(
images
,
neib_shape
,
mode
=
border
),
mode
=
self
.
mode
)
#print images.get_value(borrow=True)
neibs
=
f
()
#print neibs
g
=
function
([],
neibs2images
(
neibs
,
neib_shape
,
images
.
shape
),
mode
=
self
.
mode
)
if
border
in
[
'valid'
]:
assert
any
([
isinstance
(
node
.
op
,
self
.
op
)
for
node
in
f
.
maker
.
fgraph
.
toposort
()])
#print g()
assert
numpy
.
allclose
(
images
.
get_value
(
borrow
=
True
),
g
())
def
test_neibs_manual
(
self
):
shape
=
(
2
,
3
,
4
,
4
)
for
dtype
in
self
.
dtypes
:
images
=
shared
(
numpy
.
arange
(
numpy
.
prod
(
shape
),
dtype
=
dtype
)
.
reshape
(
shape
))
neib_shape
=
T
.
as_tensor_variable
((
2
,
2
))
for
border
in
[
'valid'
,
'ignore_borders'
]:
f
=
function
([],
images2neibs
(
images
,
neib_shape
,
mode
=
border
),
f
=
function
([],
images2neibs
(
images
,
neib_shape
,
mode
=
border
),
mode
=
self
.
mode
)
mode
=
self
.
mode
)
#print images.get_value(borrow=True)
#print images.get_value(borrow=True)
neibs
=
f
()
neibs
=
f
()
#print neibs
#print neibs
assert
numpy
.
allclose
(
neibs
,[[
0
,
1
,
4
,
5
],
[
2
,
3
,
6
,
7
],
[
8
,
9
,
12
,
13
],
[
10
,
11
,
14
,
15
],
[
16
,
17
,
20
,
21
],
[
18
,
19
,
22
,
23
],
[
24
,
25
,
28
,
29
],
[
26
,
27
,
30
,
31
],
[
32
,
33
,
36
,
37
],
[
34
,
35
,
38
,
39
],
[
40
,
41
,
44
,
45
],
[
42
,
43
,
46
,
47
],
[
48
,
49
,
52
,
53
],
[
50
,
51
,
54
,
55
],
[
56
,
57
,
60
,
61
],
[
58
,
59
,
62
,
63
],
[
64
,
65
,
68
,
69
],
[
66
,
67
,
70
,
71
],
[
72
,
73
,
76
,
77
],
[
74
,
75
,
78
,
79
],
[
80
,
81
,
84
,
85
],
[
82
,
83
,
86
,
87
],
[
88
,
89
,
92
,
93
],
[
90
,
91
,
94
,
95
]])
g
=
function
([],
neibs2images
(
neibs
,
neib_shape
,
images
.
shape
),
g
=
function
([],
neibs2images
(
neibs
,
neib_shape
,
images
.
shape
),
mode
=
self
.
mode
)
mode
=
self
.
mode
)
assert
any
([
isinstance
(
node
.
op
,
self
.
op
)
for
node
in
f
.
maker
.
fgraph
.
toposort
()])
#print g()
assert
numpy
.
allclose
(
images
.
get_value
(
borrow
=
True
),
g
())
assert
numpy
.
allclose
(
images
.
get_value
(
borrow
=
True
),
g
())
def
test_neibs_manual
(
self
):
shape
=
(
2
,
3
,
4
,
4
)
images
=
shared
(
numpy
.
arange
(
numpy
.
prod
(
shape
))
.
reshape
(
shape
))
neib_shape
=
T
.
as_tensor_variable
((
2
,
2
))
for
border
in
[
'valid'
,
'ignore_borders'
]:
f
=
function
([],
images2neibs
(
images
,
neib_shape
,
mode
=
border
),
mode
=
self
.
mode
)
#print images.get_value(borrow=True)
neibs
=
f
()
#print neibs
assert
numpy
.
allclose
(
neibs
,[[
0
,
1
,
4
,
5
],
[
2
,
3
,
6
,
7
],
[
8
,
9
,
12
,
13
],
[
10
,
11
,
14
,
15
],
[
16
,
17
,
20
,
21
],
[
18
,
19
,
22
,
23
],
[
24
,
25
,
28
,
29
],
[
26
,
27
,
30
,
31
],
[
32
,
33
,
36
,
37
],
[
34
,
35
,
38
,
39
],
[
40
,
41
,
44
,
45
],
[
42
,
43
,
46
,
47
],
[
48
,
49
,
52
,
53
],
[
50
,
51
,
54
,
55
],
[
56
,
57
,
60
,
61
],
[
58
,
59
,
62
,
63
],
[
64
,
65
,
68
,
69
],
[
66
,
67
,
70
,
71
],
[
72
,
73
,
76
,
77
],
[
74
,
75
,
78
,
79
],
[
80
,
81
,
84
,
85
],
[
82
,
83
,
86
,
87
],
[
88
,
89
,
92
,
93
],
[
90
,
91
,
94
,
95
]])
g
=
function
([],
neibs2images
(
neibs
,
neib_shape
,
images
.
shape
),
mode
=
self
.
mode
)
assert
numpy
.
allclose
(
images
.
get_value
(
borrow
=
True
),
g
())
def
test_neibs_manual_step
(
self
):
def
test_neibs_manual_step
(
self
):
shape
=
(
2
,
3
,
5
,
5
)
shape
=
(
2
,
3
,
5
,
5
)
images
=
shared
(
numpy
.
asarray
(
numpy
.
arange
(
numpy
.
prod
(
for
dtype
in
self
.
dtypes
:
shape
))
.
reshape
(
shape
),
dtype
=
'float32'
))
images
=
shared
(
numpy
.
asarray
(
numpy
.
arange
(
numpy
.
prod
(
neib_shape
=
T
.
as_tensor_variable
((
3
,
3
))
shape
))
.
reshape
(
shape
),
dtype
=
dtype
))
neib_step
=
T
.
as_tensor_variable
((
2
,
2
))
neib_shape
=
T
.
as_tensor_variable
((
3
,
3
))
for
border
in
[
'valid'
,
'ignore_borders'
]:
neib_step
=
T
.
as_tensor_variable
((
2
,
2
))
f
=
function
([],
images2neibs
(
images
,
neib_shape
,
neib_step
,
mode
=
border
),
for
border
in
[
'valid'
,
'ignore_borders'
]:
mode
=
self
.
mode
)
f
=
function
([],
images2neibs
(
images
,
neib_shape
,
neib_step
,
mode
=
border
),
mode
=
self
.
mode
)
neibs
=
f
()
if
border
in
[
'valid'
]:
assert
self
.
op
in
[
type
(
node
.
op
)
for
node
in
f
.
maker
.
fgraph
.
toposort
()]
assert
numpy
.
allclose
(
neibs
,
[[
0
,
1
,
2
,
5
,
6
,
7
,
10
,
11
,
12
],
[
2
,
3
,
4
,
7
,
8
,
9
,
12
,
13
,
14
],
[
10
,
11
,
12
,
15
,
16
,
17
,
20
,
21
,
22
],
[
12
,
13
,
14
,
17
,
18
,
19
,
22
,
23
,
24
],
[
25
,
26
,
27
,
30
,
31
,
32
,
35
,
36
,
37
],
[
27
,
28
,
29
,
32
,
33
,
34
,
37
,
38
,
39
],
[
35
,
36
,
37
,
40
,
41
,
42
,
45
,
46
,
47
],
[
37
,
38
,
39
,
42
,
43
,
44
,
47
,
48
,
49
],
[
50
,
51
,
52
,
55
,
56
,
57
,
60
,
61
,
62
],
[
52
,
53
,
54
,
57
,
58
,
59
,
62
,
63
,
64
],
[
60
,
61
,
62
,
65
,
66
,
67
,
70
,
71
,
72
],
[
62
,
63
,
64
,
67
,
68
,
69
,
72
,
73
,
74
],
[
75
,
76
,
77
,
80
,
81
,
82
,
85
,
86
,
87
],
[
77
,
78
,
79
,
82
,
83
,
84
,
87
,
88
,
89
],
[
85
,
86
,
87
,
90
,
91
,
92
,
95
,
96
,
97
],
[
87
,
88
,
89
,
92
,
93
,
94
,
97
,
98
,
99
],
[
100
,
101
,
102
,
105
,
106
,
107
,
110
,
111
,
112
],
[
102
,
103
,
104
,
107
,
108
,
109
,
112
,
113
,
114
],
[
110
,
111
,
112
,
115
,
116
,
117
,
120
,
121
,
122
],
[
112
,
113
,
114
,
117
,
118
,
119
,
122
,
123
,
124
],
[
125
,
126
,
127
,
130
,
131
,
132
,
135
,
136
,
137
],
[
127
,
128
,
129
,
132
,
133
,
134
,
137
,
138
,
139
],
[
135
,
136
,
137
,
140
,
141
,
142
,
145
,
146
,
147
],
[
137
,
138
,
139
,
142
,
143
,
144
,
147
,
148
,
149
]])
#neibs2images do not seam to support step != neib_shape
#g = function([], neibs2images(neibs, neib_shape, images.shape),
# mode=self.mode)
neibs
=
f
()
#print g()
assert
self
.
op
in
[
type
(
node
.
op
)
#assert numpy.allclose(images.get_value(borrow=True), g())
for
node
in
f
.
maker
.
fgraph
.
toposort
()]
assert
numpy
.
allclose
(
neibs
,
[[
0
,
1
,
2
,
5
,
6
,
7
,
10
,
11
,
12
],
[
2
,
3
,
4
,
7
,
8
,
9
,
12
,
13
,
14
],
[
10
,
11
,
12
,
15
,
16
,
17
,
20
,
21
,
22
],
[
12
,
13
,
14
,
17
,
18
,
19
,
22
,
23
,
24
],
[
25
,
26
,
27
,
30
,
31
,
32
,
35
,
36
,
37
],
[
27
,
28
,
29
,
32
,
33
,
34
,
37
,
38
,
39
],
[
35
,
36
,
37
,
40
,
41
,
42
,
45
,
46
,
47
],
[
37
,
38
,
39
,
42
,
43
,
44
,
47
,
48
,
49
],
[
50
,
51
,
52
,
55
,
56
,
57
,
60
,
61
,
62
],
[
52
,
53
,
54
,
57
,
58
,
59
,
62
,
63
,
64
],
[
60
,
61
,
62
,
65
,
66
,
67
,
70
,
71
,
72
],
[
62
,
63
,
64
,
67
,
68
,
69
,
72
,
73
,
74
],
[
75
,
76
,
77
,
80
,
81
,
82
,
85
,
86
,
87
],
[
77
,
78
,
79
,
82
,
83
,
84
,
87
,
88
,
89
],
[
85
,
86
,
87
,
90
,
91
,
92
,
95
,
96
,
97
],
[
87
,
88
,
89
,
92
,
93
,
94
,
97
,
98
,
99
],
[
100
,
101
,
102
,
105
,
106
,
107
,
110
,
111
,
112
],
[
102
,
103
,
104
,
107
,
108
,
109
,
112
,
113
,
114
],
[
110
,
111
,
112
,
115
,
116
,
117
,
120
,
121
,
122
],
[
112
,
113
,
114
,
117
,
118
,
119
,
122
,
123
,
124
],
[
125
,
126
,
127
,
130
,
131
,
132
,
135
,
136
,
137
],
[
127
,
128
,
129
,
132
,
133
,
134
,
137
,
138
,
139
],
[
135
,
136
,
137
,
140
,
141
,
142
,
145
,
146
,
147
],
[
137
,
138
,
139
,
142
,
143
,
144
,
147
,
148
,
149
]])
#neibs2images do not seam to support step != neib_shape
#g = function([], neibs2images(neibs, neib_shape, images.shape),
# mode=self.mode)
#print g()
#assert numpy.allclose(images.get_value(borrow=True), g())
def
test_neibs_bad_shape
(
self
):
def
test_neibs_bad_shape
(
self
):
shape
=
(
2
,
3
,
10
,
10
)
shape
=
(
2
,
3
,
10
,
10
)
images
=
shared
(
numpy
.
arange
(
numpy
.
prod
(
shape
))
.
reshape
(
shape
))
for
dtype
in
self
.
dtypes
:
images
=
shared
(
numpy
.
arange
(
for
neib_shape
in
[(
3
,
2
),
(
2
,
3
)]:
numpy
.
prod
(
shape
),
dtype
=
dtype
neib_shape
=
T
.
as_tensor_variable
(
neib_shape
)
)
.
reshape
(
shape
))
f
=
function
([],
images2neibs
(
images
,
neib_shape
),
mode
=
self
.
mode
)
self
.
assertRaises
(
TypeError
,
f
)
for
neib_shape
in
[(
3
,
2
),
(
2
,
3
)]:
neib_shape
=
T
.
as_tensor_variable
(
neib_shape
)
f
=
function
([],
images2neibs
(
images
,
neib_shape
),
mode
=
self
.
mode
)
self
.
assertRaises
(
TypeError
,
f
)
#Test that ignore border work in that case.
#Test that ignore border work in that case.
f
=
function
([],
images2neibs
(
images
,
neib_shape
,
mode
=
'ignore_borders'
),
f
=
function
([],
mode
=
self
.
mode
)
images2neibs
(
images
,
neib_shape
,
f
()
mode
=
'ignore_borders'
),
mode
=
self
.
mode
)
f
()
def
test_neibs_wrap_centered_step_manual
(
self
):
def
test_neibs_wrap_centered_step_manual
(
self
):
...
@@ -197,58 +218,65 @@ class T_Images2Neibs(unittest_tools.InferShapeTester):
...
@@ -197,58 +218,65 @@ class T_Images2Neibs(unittest_tools.InferShapeTester):
[(
1
,
1
,
1045
,
5
),
(
3
,
3
),
(
3
,
3
),
None
],
[(
1
,
1
,
1045
,
5
),
(
3
,
3
),
(
3
,
3
),
None
],
]):
]):
images
=
shared
(
numpy
.
asarray
(
numpy
.
arange
(
numpy
.
prod
(
for
dtype
in
self
.
dtypes
:
shape
))
.
reshape
(
shape
),
dtype
=
'float32'
))
neib_shape
=
T
.
as_tensor_variable
(
neib_shape
)
neib_step
=
T
.
as_tensor_variable
(
neib_step
)
expected
=
numpy
.
asarray
(
expected
)
f
=
function
([],
images2neibs
(
images
,
neib_shape
,
neib_step
,
images
=
shared
(
numpy
.
asarray
(
numpy
.
arange
(
numpy
.
prod
(
mode
=
"wrap_centered"
),
shape
))
.
reshape
(
shape
),
dtype
=
dtype
))
mode
=
self
.
mode
)
neib_shape
=
T
.
as_tensor_variable
(
neib_shape
)
neibs
=
f
()
neib_step
=
T
.
as_tensor_variable
(
neib_step
)
expected
=
numpy
.
asarray
(
expected
)
f
=
function
([],
images2neibs
(
images
,
neib_shape
,
neib_step
,
mode
=
"wrap_centered"
),
mode
=
self
.
mode
)
neibs
=
f
()
if
expected
.
size
>
1
:
if
expected
.
size
>
1
:
for
i
in
range
(
shape
[
0
]
*
shape
[
1
]):
for
i
in
range
(
shape
[
0
]
*
shape
[
1
]):
assert
numpy
.
allclose
(
neibs
[
i
*
expected
.
shape
[
0
]:
assert
numpy
.
allclose
(
(
i
+
1
)
*
expected
.
shape
[
0
],
:],
neibs
[
i
*
expected
.
shape
[
0
]:
expected
+
25
*
i
),
mode_idx
(
i
+
1
)
*
expected
.
shape
[
0
],
:],
expected
+
25
*
i
),
"wrap_centered"
assert
self
.
op
in
[
type
(
node
.
op
)
assert
self
.
op
in
[
type
(
node
.
op
)
for
node
in
f
.
maker
.
fgraph
.
toposort
()]
for
node
in
f
.
maker
.
fgraph
.
toposort
()]
#g = function([], neibs2images(neibs, neib_shape, images.shape), mode=self.mode)
#g = function([], neibs2images(neibs, neib_shape, images.shape), mode=self.mode)
#TODO: why this is commented?
#TODO: why this is commented?
#assert numpy.allclose(images.get_value(borrow=True), g())
#assert numpy.allclose(images.get_value(borrow=True), g())
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
)
images
=
shared
(
numpy
.
arange
(
numpy
.
prod
(
shape
))
.
reshape
(
shape
))
for
neib_shape
in
[(
3
,
2
),
(
2
,
3
)]:
for
dtype
in
self
.
dtypes
:
neib_shape
=
T
.
as_tensor_variable
(
neib_shape
)
images
=
shared
(
numpy
.
arange
(
numpy
.
prod
(
shape
),
dtype
=
dtype
)
.
reshape
(
shape
))
f
=
function
([],
images2neibs
(
images
,
neib_shape
,
for
neib_shape
in
[(
3
,
2
),
(
2
,
3
)]:
mode
=
"wrap_centered"
),
neib_shape
=
T
.
as_tensor_variable
(
neib_shape
)
mode
=
self
.
mode
)
self
.
assertRaises
(
TypeError
,
f
)
for
shape
in
[(
2
,
3
,
2
,
3
),
(
2
,
3
,
3
,
2
)]:
f
=
function
([],
images2neibs
(
images
,
neib_shape
,
mode
=
"wrap_centered"
),
mode
=
self
.
mode
)
self
.
assertRaises
(
TypeError
,
f
)
for
shape
in
[(
2
,
3
,
2
,
3
),
(
2
,
3
,
3
,
2
)]:
images
=
shared
(
numpy
.
arange
(
numpy
.
prod
(
shape
))
.
reshape
(
shape
))
neib_shape
=
T
.
as_tensor_variable
((
3
,
3
))
f
=
function
([],
images2neibs
(
images
,
neib_shape
,
mode
=
"wrap_centered"
),
mode
=
self
.
mode
)
self
.
assertRaises
(
TypeError
,
f
)
# Test a valid shapes
shape
=
(
2
,
3
,
3
,
3
)
images
=
shared
(
numpy
.
arange
(
numpy
.
prod
(
shape
))
.
reshape
(
shape
))
images
=
shared
(
numpy
.
arange
(
numpy
.
prod
(
shape
))
.
reshape
(
shape
))
neib_shape
=
T
.
as_tensor_variable
((
3
,
3
))
neib_shape
=
T
.
as_tensor_variable
((
3
,
3
))
f
=
function
([],
images2neibs
(
images
,
neib_shape
,
mode
=
"wrap_centered"
),
mode
=
self
.
mode
)
self
.
assertRaises
(
TypeError
,
f
)
# Test a valid shapes
f
=
function
([],
images2neibs
(
images
,
neib_shape
,
mode
=
"wrap_centered"
),
shape
=
(
2
,
3
,
3
,
3
)
mode
=
self
.
mode
)
images
=
shared
(
numpy
.
arange
(
numpy
.
prod
(
shape
))
.
reshape
(
shape
))
f
()
neib_shape
=
T
.
as_tensor_variable
((
3
,
3
))
f
=
function
([],
images2neibs
(
images
,
neib_shape
,
mode
=
"wrap_centered"
),
mode
=
self
.
mode
)
f
()
def
test_grad_wrap_centered
(
self
):
def
test_grad_wrap_centered
(
self
):
# It is not implemented for now. So test that we raise an error.
# It is not implemented for now. So test that we raise an error.
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论