Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
98bd5613
提交
98bd5613
authored
1月 13, 2010
作者:
Frederic Bastien
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
fix gpu test.
上级
a3b4d55a
显示空白字符变更
内嵌
并排
正在显示
1 个修改的文件
包含
18 行增加
和
10 行删除
+18
-10
test_nnet.py
theano/sandbox/cuda/tests/test_nnet.py
+18
-10
没有找到文件。
theano/sandbox/cuda/tests/test_nnet.py
浏览文件 @
98bd5613
import
sys
,
time
import
sys
,
time
import
theano
import
theano
from
theano.compile.s
andbox.s
haredvalue
import
shared
from
theano.compile.sharedvalue
import
shared
from
theano.compile.
sandbox.
pfunc
import
pfunc
from
theano.compile.pfunc
import
pfunc
from
theano
import
tensor
from
theano
import
tensor
import
theano.tensor.nnet
import
theano.tensor.nnet
...
@@ -108,7 +108,11 @@ def test_run_nnet_small():
...
@@ -108,7 +108,11 @@ def test_run_nnet_small():
numpy
.
random
.
seed
(
23456
)
numpy
.
random
.
seed
(
23456
)
rval_cpu
=
run_nnet
(
False
,
10
,
10
,
4
,
4
,
n_iter
=
100000
)
rval_cpu
=
run_nnet
(
False
,
10
,
10
,
4
,
4
,
n_iter
=
100000
)
def
run_conv_nnet1
(
shared_fn
):
def
run_conv_nnet1
(
use_gpu
):
if
use_gpu
:
shared_fn
=
tcn
.
shared_constructor
else
:
shared_fn
=
shared
n_batch
=
16
n_batch
=
16
n_kern
=
20
n_kern
=
20
shape_img
=
(
n_batch
,
1
,
32
,
32
)
shape_img
=
(
n_batch
,
1
,
32
,
32
)
...
@@ -139,7 +143,7 @@ def run_conv_nnet1(shared_fn):
...
@@ -139,7 +143,7 @@ def run_conv_nnet1(shared_fn):
params
=
[
w
,
b
,
v
,
c
]
params
=
[
w
,
b
,
v
,
c
]
gparams
=
tensor
.
grad
(
loss
,
params
)
gparams
=
tensor
.
grad
(
loss
,
params
)
mode
=
get_mode
()
mode
=
get_mode
(
use_gpu
)
print
'building pfunc ...'
print
'building pfunc ...'
train
=
pfunc
([
x
,
y
,
lr
],
[
loss
],
mode
=
mode
,
updates
=
[(
p
,
p
-
g
)
for
p
,
g
in
zip
(
params
,
gparams
)])
train
=
pfunc
([
x
,
y
,
lr
],
[
loss
],
mode
=
mode
,
updates
=
[(
p
,
p
-
g
)
for
p
,
g
in
zip
(
params
,
gparams
)])
...
@@ -159,12 +163,16 @@ def run_conv_nnet1(shared_fn):
...
@@ -159,12 +163,16 @@ def run_conv_nnet1(shared_fn):
def
test_conv_nnet1
():
def
test_conv_nnet1
():
numpy
.
random
.
seed
(
23456
)
numpy
.
random
.
seed
(
23456
)
rval_cpu
=
run_conv_nnet1
(
shared
)
rval_cpu
=
run_conv_nnet1
(
False
)
numpy
.
random
.
seed
(
23456
)
numpy
.
random
.
seed
(
23456
)
rval_gpu
=
run_conv_nnet1
(
tcn
.
shared_constructor
)
rval_gpu
=
run_conv_nnet1
(
True
)
assert
numpy
.
allclose
(
rval_cpu
,
rval_gpu
,
rtol
=
1e-4
,
atol
=
1e-6
)
assert
numpy
.
allclose
(
rval_cpu
,
rval_gpu
,
rtol
=
1e-4
,
atol
=
1e-6
)
def
run_conv_nnet2
(
shared_fn
):
# pretend we are training LeNet for MNIST
def
run_conv_nnet2
(
use_gpu
):
# pretend we are training LeNet for MNIST
if
use_gpu
:
shared_fn
=
tcn
.
shared_constructor
else
:
shared_fn
=
shared
#cumulativ rounding error affect this comparaison of result. So we lower the tolerance.
#cumulativ rounding error affect this comparaison of result. So we lower the tolerance.
#TODO: why the last two example see the error lower? We are converging?
#TODO: why the last two example see the error lower? We are converging?
...
@@ -221,7 +229,7 @@ def run_conv_nnet2(shared_fn): # pretend we are training LeNet for MNIST
...
@@ -221,7 +229,7 @@ def run_conv_nnet2(shared_fn): # pretend we are training LeNet for MNIST
params
=
[
w0
,
b0
,
w1
,
b1
,
v
,
c
]
params
=
[
w0
,
b0
,
w1
,
b1
,
v
,
c
]
gparams
=
tensor
.
grad
(
loss
,
params
)
gparams
=
tensor
.
grad
(
loss
,
params
)
mode
=
get_mode
()
mode
=
get_mode
(
use_gpu
)
print
'building pfunc ...'
print
'building pfunc ...'
train
=
pfunc
([
x
,
y
,
lr
],
[
loss
],
mode
=
mode
,
updates
=
[(
p
,
p
-
g
)
for
p
,
g
in
zip
(
params
,
gparams
)])
train
=
pfunc
([
x
,
y
,
lr
],
[
loss
],
mode
=
mode
,
updates
=
[(
p
,
p
-
g
)
for
p
,
g
in
zip
(
params
,
gparams
)])
...
@@ -240,10 +248,10 @@ def run_conv_nnet2(shared_fn): # pretend we are training LeNet for MNIST
...
@@ -240,10 +248,10 @@ def run_conv_nnet2(shared_fn): # pretend we are training LeNet for MNIST
def
test_conv_nnet2
():
def
test_conv_nnet2
():
numpy
.
random
.
seed
(
23456
)
numpy
.
random
.
seed
(
23456
)
rval_gpu
=
run_conv_nnet2
(
tcn
.
shared_constructor
)
rval_gpu
=
run_conv_nnet2
(
True
)
if
True
:
if
True
:
numpy
.
random
.
seed
(
23456
)
numpy
.
random
.
seed
(
23456
)
rval_cpu
=
run_conv_nnet2
(
shared
)
rval_cpu
=
run_conv_nnet2
(
False
)
print
rval_cpu
[
0
],
rval_gpu
[
0
],
rval_cpu
[
0
]
-
rval_gpu
[
0
]
print
rval_cpu
[
0
],
rval_gpu
[
0
],
rval_cpu
[
0
]
-
rval_gpu
[
0
]
assert
numpy
.
allclose
(
rval_cpu
,
rval_gpu
,
rtol
=
1e-4
,
atol
=
1e-4
)
assert
numpy
.
allclose
(
rval_cpu
,
rval_gpu
,
rtol
=
1e-4
,
atol
=
1e-4
)
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论