Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
6a231fea
提交
6a231fea
authored
5月 15, 2013
作者:
lamblin
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #1369 from nouiz/neibs
Image2Neibs.perform
上级
7ab1708e
8f96af1b
全部展开
隐藏空白字符变更
内嵌
并排
正在显示
2 个修改的文件
包含
14 行增加
和
21 行删除
+14
-21
neighbours.py
theano/sandbox/neighbours.py
+0
-0
test_neighbours.py
theano/sandbox/test_neighbours.py
+14
-21
没有找到文件。
theano/sandbox/neighbours.py
浏览文件 @
6a231fea
差异被折叠。
点击展开。
theano/sandbox/test_neighbours.py
浏览文件 @
6a231fea
from
nose.plugins.skip
import
SkipTest
from
nose.plugins.skip
import
SkipTest
import
numpy
import
numpy
import
unittest
import
theano
import
theano
from
theano
import
shared
,
function
from
theano
import
shared
,
function
...
@@ -9,14 +10,7 @@ from neighbours import images2neibs, neibs2images, Images2Neibs
...
@@ -9,14 +10,7 @@ from neighbours import images2neibs, neibs2images, Images2Neibs
from
theano.tests
import
unittest_tools
from
theano.tests
import
unittest_tools
if
theano
.
config
.
mode
==
'FAST_COMPILE'
:
mode_without_gpu
=
theano
.
compile
.
mode
.
get_default_mode
()
.
excluding
(
'gpu'
)
mode_without_gpu
=
theano
.
compile
.
mode
.
get_mode
(
'FAST_RUN'
)
.
excluding
(
'gpu'
)
else
:
mode_without_gpu
=
theano
.
compile
.
mode
.
get_default_mode
()
.
excluding
(
'gpu'
)
if
not
theano
.
config
.
cxx
:
raise
SkipTest
(
"G++ not available, so we need to skip this test."
)
class
T_Images2Neibs
(
unittest_tools
.
InferShapeTester
):
class
T_Images2Neibs
(
unittest_tools
.
InferShapeTester
):
...
@@ -25,10 +19,10 @@ class T_Images2Neibs(unittest_tools.InferShapeTester):
...
@@ -25,10 +19,10 @@ class T_Images2Neibs(unittest_tools.InferShapeTester):
dtypes
=
[
'int64'
,
'float32'
,
'float64'
]
dtypes
=
[
'int64'
,
'float32'
,
'float64'
]
def
test_neibs
(
self
):
def
test_neibs
(
self
):
for
shape
,
pshape
in
[((
10
0
,
40
,
18
,
18
),
(
2
,
2
)),
for
shape
,
pshape
in
[((
10
,
7
,
18
,
18
),
(
2
,
2
)),
((
10
0
,
40
,
6
,
18
),
(
3
,
2
)),
((
10
,
7
,
6
,
18
),
(
3
,
2
)),
((
10
,
40
,
66
,
66
),
(
33
,
33
)),
((
5
,
7
,
66
,
66
),
(
33
,
33
)),
((
10
,
40
,
68
,
66
),
(
34
,
33
))
((
5
,
7
,
68
,
66
),
(
34
,
33
))
]:
]:
for
border
in
[
'valid'
,
'ignore_borders'
]:
for
border
in
[
'valid'
,
'ignore_borders'
]:
for
dtype
in
self
.
dtypes
:
for
dtype
in
self
.
dtypes
:
...
@@ -69,7 +63,8 @@ class T_Images2Neibs(unittest_tools.InferShapeTester):
...
@@ -69,7 +63,8 @@ class T_Images2Neibs(unittest_tools.InferShapeTester):
#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
],
assert
numpy
.
allclose
(
neibs
,
[[
0
,
1
,
4
,
5
],
[
2
,
3
,
6
,
7
],
[
2
,
3
,
6
,
7
],
[
8
,
9
,
12
,
13
],
[
8
,
9
,
12
,
13
],
[
10
,
11
,
14
,
15
],
[
10
,
11
,
14
,
15
],
...
@@ -274,7 +269,8 @@ class T_Images2Neibs(unittest_tools.InferShapeTester):
...
@@ -274,7 +269,8 @@ class T_Images2Neibs(unittest_tools.InferShapeTester):
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"
),
f
=
function
([],
images2neibs
(
images
,
neib_shape
,
mode
=
"wrap_centered"
),
mode
=
self
.
mode
)
mode
=
self
.
mode
)
f
()
f
()
...
@@ -289,7 +285,6 @@ class T_Images2Neibs(unittest_tools.InferShapeTester):
...
@@ -289,7 +285,6 @@ class T_Images2Neibs(unittest_tools.InferShapeTester):
self
.
assertRaises
(
TypeError
,
unittest_tools
.
verify_grad
,
self
.
assertRaises
(
TypeError
,
unittest_tools
.
verify_grad
,
fn
,
[
images_val
],
mode
=
self
.
mode
)
fn
,
[
images_val
],
mode
=
self
.
mode
)
def
test_grad_valid
(
self
):
def
test_grad_valid
(
self
):
shape
=
(
2
,
3
,
4
,
4
)
shape
=
(
2
,
3
,
4
,
4
)
images_val
=
numpy
.
random
.
rand
(
*
shape
)
.
astype
(
'float32'
)
images_val
=
numpy
.
random
.
rand
(
*
shape
)
.
astype
(
'float32'
)
...
@@ -310,7 +305,6 @@ class T_Images2Neibs(unittest_tools.InferShapeTester):
...
@@ -310,7 +305,6 @@ class T_Images2Neibs(unittest_tools.InferShapeTester):
def
test_grad_ignore_border
(
self
):
def
test_grad_ignore_border
(
self
):
shape
=
(
2
,
3
,
5
,
5
)
shape
=
(
2
,
3
,
5
,
5
)
images
=
T
.
dtensor4
()
images_val
=
numpy
.
random
.
rand
(
*
shape
)
.
astype
(
'float32'
)
images_val
=
numpy
.
random
.
rand
(
*
shape
)
.
astype
(
'float32'
)
def
fn
(
images
):
def
fn
(
images
):
...
@@ -321,13 +315,12 @@ class T_Images2Neibs(unittest_tools.InferShapeTester):
...
@@ -321,13 +315,12 @@ class T_Images2Neibs(unittest_tools.InferShapeTester):
eps
=
0.1
)
eps
=
0.1
)
def
test_neibs2images_grad
(
self
):
def
test_neibs2images_grad
(
self
):
# say we had images of size (2, 3, 20, 20)
# say we had images of size (2, 3, 10, 10)
# then we extracted 2x2 neighbors on this, we get (2 * 3 * 10 * 10, 4)
# then we extracted 2x2 neighbors on this, we get (2 * 3 * 5 * 5, 4)
neibs
=
T
.
dmatrix
()
neibs_val
=
numpy
.
random
.
rand
(
150
,
4
)
neibs_val
=
numpy
.
random
.
rand
(
600
,
4
)
def
fn
(
neibs
):
def
fn
(
neibs
):
return
neibs2images
(
neibs
,
(
2
,
2
),
(
2
,
3
,
20
,
2
0
))
return
neibs2images
(
neibs
,
(
2
,
2
),
(
2
,
3
,
10
,
1
0
))
unittest_tools
.
verify_grad
(
fn
,
[
neibs_val
],
mode
=
self
.
mode
,
unittest_tools
.
verify_grad
(
fn
,
[
neibs_val
],
mode
=
self
.
mode
,
eps
=
0.1
)
eps
=
0.1
)
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论