Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
eb7e5d93
提交
eb7e5d93
authored
6月 30, 2010
作者:
Frederic Bastien
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
added test for GpuImages2Neibs
上级
0abf9bd8
隐藏空白字符变更
内嵌
并排
正在显示
1 个修改的文件
包含
57 行增加
和
12 行删除
+57
-12
test_neighbours.py
theano/sandbox/test_neighbours.py
+57
-12
没有找到文件。
theano/sandbox/test_neighbours.py
浏览文件 @
eb7e5d93
from
numpy
import
*
import
numpy
import
theano
import
theano
from
theano
import
shared
,
function
from
theano
import
shared
,
function
import
theano.tensor
as
T
import
theano.tensor
as
T
from
neighbours
import
images2neibs
,
neibs2images
from
neighbours
import
images2neibs
,
neibs2images
,
GpuImages2Neibs
# Skip test if cuda_ndarray is not available.
from
nose.plugins.skip
import
SkipTest
import
theano.sandbox.cuda
as
cuda
mode
=
theano
.
config
.
mode
if
theano
.
config
.
mode
==
'FAST_COMPILE'
:
if
mode
==
"FAST_COMPILE"
:
mode_with_gpu
=
theano
.
compile
.
mode
.
get_mode
(
'FAST_RUN'
)
.
including
(
'gpu'
)
mode
=
'FAST_RUN'
mode_without_gpu
=
theano
.
compile
.
mode
.
get_mode
(
'FAST_RUN'
)
.
excluding
(
'gpu'
)
else
:
mode_with_gpu
=
theano
.
compile
.
mode
.
get_default_mode
()
.
including
(
'gpu'
)
mode_without_gpu
=
theano
.
compile
.
mode
.
get_default_mode
()
.
excluding
(
'gpu'
)
def
neibs_test
():
def
test_neibs
():
shape
=
(
100
,
40
,
18
,
18
)
shape
=
(
100
,
40
,
18
,
18
)
images
=
shared
(
arange
(
prod
(
shape
),
dtype
=
'float32'
)
.
reshape
(
shape
))
images
=
shared
(
numpy
.
arange
(
numpy
.
prod
(
shape
)
)
.
reshape
(
shape
))
neib_shape
=
T
.
as_tensor_variable
((
2
,
2
))
#(array((2,2), dtype='float32'))
neib_shape
=
T
.
as_tensor_variable
((
2
,
2
))
#(array((2,2), dtype='float32'))
f
=
function
([],
images2neibs
(
images
,
neib_shape
),
mode
=
mode
)
f
=
function
([],
images2neibs
(
images
,
neib_shape
),
mode
=
mode
_without_gpu
)
#print images.value
#print images.value
neibs
=
f
()
neibs
=
f
()
#print neibs
#print neibs
g
=
function
([],
neibs2images
(
neibs
,
neib_shape
,
images
.
shape
),
mode
=
mode
)
g
=
function
([],
neibs2images
(
neibs
,
neib_shape
,
images
.
shape
),
mode
=
mode
_without_gpu
)
#print g()
#print g()
assert
allclose
(
images
.
value
,
g
())
assert
numpy
.
allclose
(
images
.
value
,
g
())
def
test_neibs_gpu
():
if
cuda
.
cuda_available
==
False
:
raise
SkipTest
(
'Optional package cuda disabled'
)
shape
=
(
100
,
40
,
18
,
18
)
images
=
shared
(
numpy
.
arange
(
numpy
.
prod
(
shape
),
dtype
=
'float32'
)
.
reshape
(
shape
))
neib_shape
=
T
.
as_tensor_variable
((
2
,
2
))
#(array((2,2), dtype='float32'))
from
theano.sandbox.cuda.basic_ops
import
gpu_from_host
f
=
function
([],
images2neibs
(
images
,
neib_shape
),
mode
=
mode_with_gpu
)
assert
any
([
isinstance
(
node
.
op
,
GpuImages2Neibs
)
for
node
in
f
.
maker
.
env
.
toposort
()])
#print images.value
res1
=
[[[[
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.
]]]]
neibs
=
numpy
.
asarray
(
f
())
numpy
.
allclose
(
neibs
,
res1
)
#print neibs
g
=
function
([],
neibs2images
(
neibs
,
neib_shape
,
images
.
shape
),
mode
=
mode_with_gpu
)
assert
any
([
isinstance
(
node
.
op
,
GpuImages2Neibs
)
for
node
in
f
.
maker
.
env
.
toposort
()])
#print numpy.asarray(g())
assert
numpy
.
allclose
(
images
.
value
,
g
())
neibs_test
()
if
__name__
==
'__main__'
:
test_neibs_gpu
()
test_neibs
()
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论