Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
c4522b51
提交
c4522b51
authored
3月 09, 2010
作者:
Frederic Bastien
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
enable cuda test when cuda is available. make some helper fct to use…
enable cuda test when cuda is available. make some helper fct to use theano._asarray when needed and make the code more readable.
上级
3322b1a2
隐藏空白字符变更
内嵌
并排
正在显示
1 个修改的文件
包含
41 行增加
和
34 行删除
+41
-34
test_nnet.py
theano/sandbox/cuda/tests/test_nnet.py
+41
-34
没有找到文件。
theano/sandbox/cuda/tests/test_nnet.py
浏览文件 @
c4522b51
...
@@ -14,7 +14,7 @@ import numpy
...
@@ -14,7 +14,7 @@ import numpy
# Skip test if cuda_ndarray is not available.
# Skip test if cuda_ndarray is not available.
from
nose.plugins.skip
import
SkipTest
from
nose.plugins.skip
import
SkipTest
import
theano.sandbox.cuda
as
cuda_ndarray
import
theano.sandbox.cuda
as
cuda_ndarray
if
cuda_ndarray
.
cuda_
enabled
==
False
:
if
cuda_ndarray
.
cuda_
available
==
False
:
raise
SkipTest
(
'Optional package cuda disabled'
)
raise
SkipTest
(
'Optional package cuda disabled'
)
import
theano.sandbox.cuda
as
tcn
import
theano.sandbox.cuda
as
tcn
...
@@ -23,6 +23,13 @@ import logging
...
@@ -23,6 +23,13 @@ import logging
logging
.
getLogger
(
'theano.sandbox.cuda.tests.test_nnet'
)
.
setLevel
(
logging
.
INFO
)
logging
.
getLogger
(
'theano.sandbox.cuda.tests.test_nnet'
)
.
setLevel
(
logging
.
INFO
)
def
my_rand
(
*
shape
):
return
theano
.
_asarray
(
numpy
.
random
.
rand
(
*
shape
),
dtype
=
'float32'
)
def
my_randn
(
*
shape
):
return
theano
.
_asarray
(
numpy
.
random
.
randn
(
*
shape
),
dtype
=
'float32'
)
def
my_zeros
(
*
shape
):
return
theano
.
_asarray
(
numpy
.
zeros
(
*
shape
),
dtype
=
'float32'
)
def
get_mode
(
use_gpu
):
def
get_mode
(
use_gpu
):
ret
=
theano
.
compile
.
get_default_mode
()
ret
=
theano
.
compile
.
get_default_mode
()
if
isinstance
(
ret
,
theano
.
compile
.
ProfileMode
):
if
isinstance
(
ret
,
theano
.
compile
.
ProfileMode
):
...
@@ -44,15 +51,15 @@ def print_diff_mode(a,b):
...
@@ -44,15 +51,15 @@ def print_diff_mode(a,b):
def
run_nnet
(
use_gpu
,
n_batch
=
60
,
n_in
=
1024
,
n_hid
=
2048
,
n_out
=
10
,
n_iter
=
100
):
def
run_nnet
(
use_gpu
,
n_batch
=
60
,
n_in
=
1024
,
n_hid
=
2048
,
n_out
=
10
,
n_iter
=
100
):
if
use_gpu
:
if
use_gpu
:
w
=
tcn
.
shared_constructor
(
0.01
*
(
numpy
.
random
.
rand
(
n_in
,
n_hid
)
-
0.5
),
'w'
)
w
=
tcn
.
shared_constructor
(
0.01
*
(
my_
rand
(
n_in
,
n_hid
)
-
0.5
),
'w'
)
b
=
tcn
.
shared_constructor
(
numpy
.
zeros
(
n_hid
),
'b'
)
b
=
tcn
.
shared_constructor
(
my_
zeros
(
n_hid
),
'b'
)
v
=
tcn
.
shared_constructor
(
numpy
.
zeros
((
n_hid
,
n_out
)),
'c'
)
v
=
tcn
.
shared_constructor
(
my_
zeros
((
n_hid
,
n_out
)),
'c'
)
c
=
tcn
.
shared_constructor
(
numpy
.
zeros
(
n_out
),
'c'
)
c
=
tcn
.
shared_constructor
(
my_
zeros
(
n_out
),
'c'
)
else
:
else
:
w
=
shared
(
theano
.
_asarray
(
0.01
*
(
numpy
.
random
.
rand
(
n_in
,
n_hid
)
-
0.5
),
dtype
=
'float32'
),
'w'
)
w
=
shared
(
0.01
*
(
my_rand
(
n_in
,
n_hid
)
-
0.5
),
'w'
)
b
=
shared
(
theano
.
_asarray
(
numpy
.
zeros
(
n_hid
),
dtype
=
'float32'
),
'b'
)
b
=
shared
(
my_zeros
(
n_hid
),
'b'
)
v
=
shared
(
theano
.
_asarray
(
numpy
.
zeros
((
n_hid
,
n_out
)),
dtype
=
'float32'
),
'c'
)
v
=
shared
(
my_zeros
((
n_hid
,
n_out
)
),
'c'
)
c
=
shared
(
theano
.
_asarray
(
numpy
.
zeros
(
n_out
),
dtype
=
'float32'
),
'c'
)
c
=
shared
(
my_zeros
(
n_out
),
'c'
)
x
=
tensor
.
fmatrix
(
'x'
)
x
=
tensor
.
fmatrix
(
'x'
)
y
=
tensor
.
fmatrix
(
'y'
)
y
=
tensor
.
fmatrix
(
'y'
)
...
@@ -75,8 +82,8 @@ def run_nnet(use_gpu, n_batch=60, n_in=1024, n_hid=2048, n_out=10, n_iter=100):
...
@@ -75,8 +82,8 @@ def run_nnet(use_gpu, n_batch=60, n_in=1024, n_hid=2048, n_out=10, n_iter=100):
for
i
,
n
in
enumerate
(
train
.
maker
.
env
.
toposort
()):
for
i
,
n
in
enumerate
(
train
.
maker
.
env
.
toposort
()):
print
i
,
n
print
i
,
n
xval
=
theano
.
_asarray
(
numpy
.
random
.
rand
(
n_batch
,
n_in
),
dtype
=
'float32'
)
xval
=
my_rand
(
n_batch
,
n_in
)
yval
=
theano
.
_asarray
(
numpy
.
random
.
rand
(
n_batch
,
n_out
),
dtype
=
'float32'
)
yval
=
my_rand
(
n_batch
,
n_out
)
lr
=
theano
.
_asarray
(
0.01
,
dtype
=
'float32'
)
lr
=
theano
.
_asarray
(
0.01
,
dtype
=
'float32'
)
t0
=
time
.
time
()
t0
=
time
.
time
()
...
@@ -123,10 +130,10 @@ def run_conv_nnet1(use_gpu):
...
@@ -123,10 +130,10 @@ def run_conv_nnet1(use_gpu):
n_hid
=
n_kern
*
logical_hid_shape
[
0
]
*
logical_hid_shape
[
1
]
n_hid
=
n_kern
*
logical_hid_shape
[
0
]
*
logical_hid_shape
[
1
]
n_out
=
10
n_out
=
10
w
=
shared_fn
(
theano
.
_asarray
(
0.01
*
(
numpy
.
random
.
rand
(
*
shape_kern
)
-
0.5
),
dtype
=
'float32'
),
'w'
)
w
=
shared_fn
(
0.01
*
(
my_rand
(
*
shape_kern
)
-
0.5
),
'w'
)
b
=
shared_fn
(
theano
.
_asarray
(
numpy
.
zeros
((
n_kern
,)),
dtype
=
'float32'
),
'b'
)
b
=
shared_fn
(
my_zeros
((
n_kern
,)
),
'b'
)
v
=
shared_fn
(
theano
.
_asarray
(
numpy
.
zeros
((
n_hid
,
n_out
)),
dtype
=
'float32'
),
'c'
)
v
=
shared_fn
(
my_zeros
((
n_hid
,
n_out
)
),
'c'
)
c
=
shared_fn
(
theano
.
_asarray
(
numpy
.
zeros
(
n_out
),
dtype
=
'float32'
),
'c'
)
c
=
shared_fn
(
my_zeros
(
n_out
),
'c'
)
x
=
tensor
.
Tensor
(
dtype
=
'float32'
,
broadcastable
=
(
0
,
1
,
0
,
0
))(
'x'
)
x
=
tensor
.
Tensor
(
dtype
=
'float32'
,
broadcastable
=
(
0
,
1
,
0
,
0
))(
'x'
)
y
=
tensor
.
fmatrix
(
'y'
)
y
=
tensor
.
fmatrix
(
'y'
)
...
@@ -152,8 +159,8 @@ def run_conv_nnet1(use_gpu):
...
@@ -152,8 +159,8 @@ def run_conv_nnet1(use_gpu):
# for i, n in enumerate(train.maker.env.toposort()):
# for i, n in enumerate(train.maker.env.toposort()):
# print i, n
# print i, n
xval
=
theano
.
_asarray
(
numpy
.
random
.
rand
(
*
shape_img
),
dtype
=
'float32'
)
xval
=
my_rand
(
*
shape_img
)
yval
=
theano
.
_asarray
(
numpy
.
random
.
rand
(
n_batch
,
n_out
),
dtype
=
'float32'
)
yval
=
my_rand
(
n_batch
,
n_out
)
lr
=
theano
.
_asarray
(
0.01
,
dtype
=
'float32'
)
lr
=
theano
.
_asarray
(
0.01
,
dtype
=
'float32'
)
for
i
in
xrange
(
10
):
for
i
in
xrange
(
10
):
...
@@ -204,12 +211,12 @@ def run_conv_nnet2(use_gpu): # pretend we are training LeNet for MNIST
...
@@ -204,12 +211,12 @@ def run_conv_nnet2(use_gpu): # pretend we are training LeNet for MNIST
n_hid
=
n_kern1
*
logical_hid_shape1
[
0
]
*
logical_hid_shape1
[
1
]
n_hid
=
n_kern1
*
logical_hid_shape1
[
0
]
*
logical_hid_shape1
[
1
]
n_out
=
10
n_out
=
10
w0
=
shared_fn
(
theano
.
_asarray
(
0.01
*
(
numpy
.
random
.
rand
(
*
shape_kern
)
-
0.5
),
dtype
=
'float32'
),
'w0'
)
w0
=
shared_fn
(
0.01
*
(
my_rand
(
*
shape_kern
)
-
0.5
),
'w0'
)
b0
=
shared_fn
(
theano
.
_asarray
(
numpy
.
zeros
((
n_kern
,)),
dtype
=
'float32'
),
'b0'
)
b0
=
shared_fn
(
my_zeros
((
n_kern
,)
),
'b0'
)
w1
=
shared_fn
(
theano
.
_asarray
(
0.01
*
(
numpy
.
random
.
rand
(
*
shape_kern1
)
-
0.5
),
dtype
=
'float32'
),
'w1'
)
w1
=
shared_fn
(
0.01
*
(
my_rand
(
*
shape_kern1
)
-
0.5
),
'w1'
)
b1
=
shared_fn
(
theano
.
_asarray
(
numpy
.
zeros
((
n_kern1
,)),
dtype
=
'float32'
),
'b1'
)
b1
=
shared_fn
(
my_zeros
((
n_kern1
,)
),
'b1'
)
v
=
shared_fn
(
theano
.
_asarray
(
numpy
.
zeros
((
n_hid
,
n_out
)),
dtype
=
'float32'
),
'c'
)
v
=
shared_fn
(
my_zeros
((
n_hid
,
n_out
)
),
'c'
)
c
=
shared_fn
(
theano
.
_asarray
(
numpy
.
zeros
(
n_out
),
dtype
=
'float32'
),
'c'
)
c
=
shared_fn
(
my_zeros
(
n_out
),
'c'
)
x
=
tensor
.
Tensor
(
dtype
=
'float32'
,
broadcastable
=
(
0
,
1
,
0
,
0
))(
'x'
)
x
=
tensor
.
Tensor
(
dtype
=
'float32'
,
broadcastable
=
(
0
,
1
,
0
,
0
))(
'x'
)
y
=
tensor
.
fmatrix
(
'y'
)
y
=
tensor
.
fmatrix
(
'y'
)
...
@@ -238,8 +245,8 @@ def run_conv_nnet2(use_gpu): # pretend we are training LeNet for MNIST
...
@@ -238,8 +245,8 @@ def run_conv_nnet2(use_gpu): # pretend we are training LeNet for MNIST
# for i, n in enumerate(train.maker.env.toposort()):
# for i, n in enumerate(train.maker.env.toposort()):
# print i, n
# print i, n
xval
=
theano
.
_asarray
(
numpy
.
random
.
rand
(
*
shape_img
),
dtype
=
'float32'
)
xval
=
my_rand
(
*
shape_img
)
yval
=
theano
.
_asarray
(
numpy
.
random
.
rand
(
n_batch
,
n_out
),
dtype
=
'float32'
)
#int32 make all 0...
yval
=
my_rand
(
n_batch
,
n_out
)
#int32 make all 0...
lr
=
theano
.
_asarray
(
0.01
,
dtype
=
'float32'
)
lr
=
theano
.
_asarray
(
0.01
,
dtype
=
'float32'
)
for
i
in
xrange
(
n_train
):
for
i
in
xrange
(
n_train
):
rval
=
train
(
xval
,
yval
,
lr
)
rval
=
train
(
xval
,
yval
,
lr
)
...
@@ -284,12 +291,12 @@ def run_conv_nnet2_classif(use_gpu, isize, ksize, n_batch, n_iter,
...
@@ -284,12 +291,12 @@ def run_conv_nnet2_classif(use_gpu, isize, ksize, n_batch, n_iter,
n_out
=
10
n_out
=
10
w0
=
shared_fn
(
theano
.
_asarray
(
0.01
*
(
numpy
.
random
.
rand
(
*
shape_kern
)
-
0.5
),
dtype
=
'float32'
),
'w0'
)
w0
=
shared_fn
(
0.01
*
(
my_rand
(
*
shape_kern
)
-
0.5
),
'w0'
)
b0
=
shared_fn
(
theano
.
_asarray
(
numpy
.
zeros
((
n_kern
,)),
dtype
=
'float32'
),
'b0'
)
b0
=
shared_fn
(
my_zeros
((
n_kern
,)
),
'b0'
)
w1
=
shared_fn
(
theano
.
_asarray
(
0.01
*
(
numpy
.
random
.
rand
(
*
shape_kern1
)
-
0.5
),
dtype
=
'float32'
),
'w1'
)
w1
=
shared_fn
(
0.01
*
(
my_rand
(
*
shape_kern1
)
-
0.5
),
'w1'
)
b1
=
shared_fn
(
theano
.
_asarray
(
numpy
.
zeros
((
n_kern1
,)),
dtype
=
'float32'
),
'b1'
)
b1
=
shared_fn
(
my_zeros
((
n_kern1
,)
),
'b1'
)
v
=
shared_fn
(
theano
.
_asarray
(
0.01
*
numpy
.
random
.
randn
(
n_hid
,
n_out
),
dtype
=
'float32'
),
'v'
)
v
=
shared_fn
(
0.01
*
my_randn
(
n_hid
,
n_out
),
'v'
)
c
=
shared_fn
(
theano
.
_asarray
(
numpy
.
zeros
(
n_out
),
dtype
=
'float32'
),
'c'
)
c
=
shared_fn
(
my_zeros
(
n_out
),
'c'
)
print
'ALLOCATING ARCH: w0 shape'
,
w0
.
value
.
shape
print
'ALLOCATING ARCH: w0 shape'
,
w0
.
value
.
shape
print
'ALLOCATING ARCH: w1 shape'
,
w1
.
value
.
shape
print
'ALLOCATING ARCH: w1 shape'
,
w1
.
value
.
shape
...
@@ -330,11 +337,11 @@ def run_conv_nnet2_classif(use_gpu, isize, ksize, n_batch, n_iter,
...
@@ -330,11 +337,11 @@ def run_conv_nnet2_classif(use_gpu, isize, ksize, n_batch, n_iter,
for
i
,
n
in
enumerate
(
train
.
maker
.
env
.
toposort
()):
for
i
,
n
in
enumerate
(
train
.
maker
.
env
.
toposort
()):
print
i
,
n
print
i
,
n
xval
=
theano
.
_asarray
(
numpy
.
random
.
rand
(
*
shape_img
),
dtype
=
'float32'
)
xval
=
my_rand
(
*
shape_img
)
yval
=
theano
.
_asarray
(
numpy
.
random
.
rand
(
n_batch
,
n_out
),
dtype
=
'float32'
)
yval
=
my_rand
(
n_batch
,
n_out
)
lr
=
theano
.
_asarray
(
0.01
,
dtype
=
'float32'
)
lr
=
theano
.
_asarray
(
0.01
,
dtype
=
'float32'
)
rvals
=
numpy
.
zeros
(
n_iter
)
rvals
=
my_
zeros
(
n_iter
)
t0
=
time
.
time
()
t0
=
time
.
time
()
for
i
in
xrange
(
n_iter
):
for
i
in
xrange
(
n_iter
):
rvals
[
i
]
=
train
(
xval
,
yval
,
lr
)[
0
]
rvals
[
i
]
=
train
(
xval
,
yval
,
lr
)[
0
]
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论