Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
096c375f
提交
096c375f
authored
3月 11, 2010
作者:
Frederic Bastien
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
make the test faster in debug mode.
上级
d5c66369
隐藏空白字符变更
内嵌
并排
正在显示
1 个修改的文件
包含
30 行增加
和
22 行删除
+30
-22
test_nnet.py
theano/sandbox/cuda/tests/test_nnet.py
+30
-22
没有找到文件。
theano/sandbox/cuda/tests/test_nnet.py
浏览文件 @
096c375f
...
...
@@ -5,6 +5,7 @@ from theano.compile.sharedvalue import shared
from
theano.compile.pfunc
import
pfunc
from
theano
import
tensor
import
theano.tensor.nnet
from
theano
import
config
import
theano.tensor.nnet.conv
as
conv
import
theano.tensor.signal.downsample
as
downsample
...
...
@@ -48,8 +49,10 @@ def print_diff_mode(a,b):
if
a
!=
None
and
isinstance
(
a
,(
theano
.
compile
.
ProfileMode
,))
and
isinstance
(
b
,(
theano
.
compile
.
ProfileMode
,)):
a
.
print_diff_summary
(
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_
train
=
100
):
if
config
.
mode
==
'DEBUG_MODE'
:
n_train
=
1
if
use_gpu
:
w
=
tcn
.
shared_constructor
(
0.01
*
(
my_rand
(
n_in
,
n_hid
)
-
0.5
),
'w'
)
b
=
tcn
.
shared_constructor
(
my_zeros
(
n_hid
),
'b'
)
...
...
@@ -88,7 +91,7 @@ def run_nnet(use_gpu, n_batch=60, n_in=1024, n_hid=2048, n_out=10, n_iter=100):
t0
=
time
.
time
()
rval
=
[]
for
i
in
xrange
(
n_
iter
):
for
i
in
xrange
(
n_
train
):
rval
.
append
(
train
(
xval
,
yval
,
lr
))
dt
=
time
.
time
()
-
t0
...
...
@@ -110,11 +113,11 @@ def test_run_nnet():
def
test_run_nnet_med
():
numpy
.
random
.
seed
(
23456
)
rval_cpu
=
run_nnet
(
False
,
10
,
128
,
50
,
4
,
n_
iter
=
10000
)
rval_cpu
=
run_nnet
(
False
,
10
,
128
,
50
,
4
,
n_
train
=
10000
)
def
test_run_nnet_small
():
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_
train
=
100000
)
def
run_conv_nnet1
(
use_gpu
):
if
use_gpu
:
...
...
@@ -125,6 +128,8 @@ def run_conv_nnet1(use_gpu):
n_kern
=
20
shape_img
=
(
n_batch
,
1
,
32
,
32
)
shape_kern
=
(
n_kern
,
1
,
5
,
5
)
n_train
=
10
if
config
.
mode
==
'DEBUG_MODE'
:
n_train
=
1
logical_hid_shape
=
tcn
.
blas
.
GpuConv
.
logical_output_shape_2d
(
shape_img
[
2
:],
shape_kern
[
2
:],
'valid'
)
n_hid
=
n_kern
*
logical_hid_shape
[
0
]
*
logical_hid_shape
[
1
]
...
...
@@ -163,7 +168,7 @@ def run_conv_nnet1(use_gpu):
yval
=
my_rand
(
n_batch
,
n_out
)
lr
=
theano
.
_asarray
(
0.01
,
dtype
=
'float32'
)
for
i
in
xrange
(
10
):
for
i
in
xrange
(
n_train
):
rval
=
train
(
xval
,
yval
,
lr
)
print
'training done'
print_mode
(
mode
)
...
...
@@ -205,6 +210,7 @@ def run_conv_nnet2(use_gpu): # pretend we are training LeNet for MNIST
shape_kern1
=
(
n_kern1
,
n_kern
,
5
,
5
)
n_train
=
30
if
config
.
mode
==
'DEBUG_MODE'
:
n_train
=
1
logical_hid_shape
=
tcn
.
blas
.
GpuConv
.
logical_output_shape_2d
(
tuple
(
shape_img
[
2
:]),
tuple
(
shape_kern
[
2
:]),
'valid'
)
logical_hid_shape1
=
tcn
.
blas
.
GpuConv
.
logical_output_shape_2d
((
logical_hid_shape
[
0
]
/
2
,
logical_hid_shape
[
1
]
/
2
),
tuple
(
shape_kern1
[
2
:]),
'valid'
)
...
...
@@ -263,7 +269,7 @@ def test_conv_nnet2():
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
)
def
run_conv_nnet2_classif
(
use_gpu
,
isize
,
ksize
,
n_batch
,
n_
iter
,
def
run_conv_nnet2_classif
(
use_gpu
,
isize
,
ksize
,
n_batch
,
n_
train
,
downsample_ops
=
True
,
verbose
=
0
,
version
=-
1
):
if
use_gpu
:
shared_fn
=
tcn
.
shared_constructor
...
...
@@ -341,9 +347,9 @@ def run_conv_nnet2_classif(use_gpu, isize, ksize, n_batch, n_iter,
yval
=
my_rand
(
n_batch
,
n_out
)
lr
=
theano
.
_asarray
(
0.01
,
dtype
=
'float32'
)
rvals
=
my_zeros
(
n_
iter
)
rvals
=
my_zeros
(
n_
train
)
t0
=
time
.
time
()
for
i
in
xrange
(
n_
iter
):
for
i
in
xrange
(
n_
train
):
rvals
[
i
]
=
train
(
xval
,
yval
,
lr
)[
0
]
t1
=
time
.
time
()
print_mode
(
mode
)
...
...
@@ -351,7 +357,7 @@ def run_conv_nnet2_classif(use_gpu, isize, ksize, n_batch, n_iter,
def
cmp_run_conv_nnet2_classif
(
seed
,
isize
,
ksize
,
bsize
,
ignore_error
=
False
,
n_
iter
=
10
,
n_
train
=
10
,
gpu_only
=
False
,
cpu_only
=
False
,
float_atol
=
1e-06
,
...
...
@@ -364,6 +370,8 @@ def cmp_run_conv_nnet2_classif(seed, isize, ksize, bsize,
check_isfinite: the debug mode option. We forward this value to debug mode.
For some parameter CrossentropyCategorical1Hot op generate inf when not optimized.
"""
if
config
.
mode
==
'DEBUG_MODE'
:
n_train
=
1
numpy
.
random
.
seed
(
seed
)
import
theano.tensor.basic
...
...
@@ -381,7 +389,7 @@ def cmp_run_conv_nnet2_classif(seed, isize, ksize, bsize,
theano
.
tensor
.
basic
.
float32_atol
=
float_atol
if
not
cpu_only
:
rval_gpu
,
tg
,
gpu_mode
=
run_conv_nnet2_classif
(
True
,
isize
,
ksize
,
bsize
,
n_
iter
,
verbose
=
verbose
,
version
=
version
)
isize
,
ksize
,
bsize
,
n_
train
,
verbose
=
verbose
,
version
=
version
)
finally
:
predefined_modes
[
"DEBUG_MODE"
]
.
check_isfinite
=
orig_check_isfinite
theano
.
tensor
.
basic
.
float32_atol
=
orig_float32_atol
...
...
@@ -393,7 +401,7 @@ def cmp_run_conv_nnet2_classif(seed, isize, ksize, bsize,
try
:
predefined_modes
[
"DEBUG_MODE"
]
.
check_isfinite
=
check_isfinite
numpy
.
random
.
seed
(
seed
)
rval_cpu
,
tc
,
cpu_mode
=
run_conv_nnet2_classif
(
False
,
isize
,
ksize
,
bsize
,
n_
iter
,
rval_cpu
,
tc
,
cpu_mode
=
run_conv_nnet2_classif
(
False
,
isize
,
ksize
,
bsize
,
n_
train
,
verbose
=
verbose
,
version
=
version
)
if
pickle
and
isinstance
(
cpu_mode
,(
theano
.
compile
.
ProfileMode
,)):
import
pickle
...
...
@@ -414,11 +422,11 @@ def cmp_run_conv_nnet2_classif(seed, isize, ksize, bsize,
print
"gpu:"
,
rval_gpu
print
"abs diff:"
,
numpy
.
absolute
(
rval_gpu
-
rval_cpu
)
print
"time cpu:
%.3
f, time gpu:
%.3
f, speed up
%
f"
%
(
tc
,
tg
,
tc
/
tg
)
print
"estimated time for one pass through MNIST with cpu:
%
f"
%
(
tc
*
(
60000.0
/
(
n_
iter
*
bsize
)))
print
"estimated time for one pass through MNIST with gpu:
%
f"
%
(
tg
*
(
60000.0
/
(
n_
iter
*
bsize
)))
print
"estimated time for one pass through MNIST with cpu:
%
f"
%
(
tc
*
(
60000.0
/
(
n_
train
*
bsize
)))
print
"estimated time for one pass through MNIST with gpu:
%
f"
%
(
tg
*
(
60000.0
/
(
n_
train
*
bsize
)))
else
:
print
"time cpu:
%.3
f"
%
(
tc
)
print
"estimated time for one pass through MNIST with cpu:
%
f"
%
(
tc
*
(
60000.0
/
(
n_
iter
*
bsize
)))
print
"estimated time for one pass through MNIST with cpu:
%
f"
%
(
tc
*
(
60000.0
/
(
n_
train
*
bsize
)))
if
not
ignore_error
and
not
cpu_only
and
not
gpu_only
:
assert
numpy
.
allclose
(
rval_cpu
,
rval_gpu
,
rtol
=
1e-3
,
atol
=
float_atol
)
...
...
@@ -430,52 +438,52 @@ verbose=0
version
=-
1
def
test_lenet_28
():
#MNIST
cmp_run_conv_nnet2_classif
(
23485
,
28
,
5
,
60
,
n_
iter
=
10
,
cmp_run_conv_nnet2_classif
(
23485
,
28
,
5
,
60
,
n_
train
=
10
,
ignore_error
=
ignore_error
,
gpu_only
=
gpu_only
,
cpu_only
=
cpu_only
,
verbose
=
verbose
,
version
=
version
)
def
test_lenet_32
():
#CIFAR10 / Shapeset
cmp_run_conv_nnet2_classif
(
23485
,
32
,
5
,
60
,
n_
iter
=
10
,
cmp_run_conv_nnet2_classif
(
23485
,
32
,
5
,
60
,
n_
train
=
10
,
ignore_error
=
ignore_error
,
gpu_only
=
gpu_only
,
verbose
=
verbose
,
version
=
version
)
def
test_lenet_32_long
():
#CIFAR10 / Shapeset
# this tests the gradient of downsample on the GPU,
# which does not recieve specific testing
cmp_run_conv_nnet2_classif
(
23485
,
32
,
5
,
30
,
n_
iter
=
50
,
cmp_run_conv_nnet2_classif
(
23485
,
32
,
5
,
30
,
n_
train
=
50
,
ignore_error
=
ignore_error
,
gpu_only
=
gpu_only
,
cpu_only
=
cpu_only
,
verbose
=
verbose
,
version
=
version
)
def
test_lenet_64
():
# ???
#float_atol need to pass in debug mode
#needed as cpu use extended precision and gpu don't
cmp_run_conv_nnet2_classif
(
23485
,
64
,
7
,
10
,
n_
iter
=
10
,
cmp_run_conv_nnet2_classif
(
23485
,
64
,
7
,
10
,
n_
train
=
10
,
ignore_error
=
ignore_error
,
gpu_only
=
gpu_only
,
cpu_only
=
cpu_only
,
verbose
=
verbose
,
float_atol
=
5e-4
,
check_isfinite
=
True
,
version
=
version
)
def
test_lenet_108
():
# NORB
cmp_run_conv_nnet2_classif
(
23485
,
108
,
7
,
5
,
n_
iter
=
4
,
cmp_run_conv_nnet2_classif
(
23485
,
108
,
7
,
5
,
n_
train
=
4
,
ignore_error
=
ignore_error
,
gpu_only
=
gpu_only
,
cpu_only
=
cpu_only
,
verbose
=
verbose
,
check_isfinite
=
True
,
version
=
version
,
float_atol
=
7e-2
)
def
test_lenet_256
():
# ImageNet
cmp_run_conv_nnet2_classif
(
23485
,
256
,
9
,
2
,
n_
iter
=
5
,
cmp_run_conv_nnet2_classif
(
23485
,
256
,
9
,
2
,
n_
train
=
5
,
ignore_error
=
ignore_error
,
gpu_only
=
gpu_only
,
cpu_only
=
cpu_only
,
verbose
=
verbose
,
check_isfinite
=
True
,
version
=
version
)
#I did a wanted error in the name as we don't want it to execute automatically for now as it don't work
def
tes_lenet_hd
():
#HD 720p: 1280(wid)x720(len)
cmp_run_conv_nnet2_classif
(
23485
,
(
720
,
1280
),
9
,
2
,
n_
iter
=
3
,
cmp_run_conv_nnet2_classif
(
23485
,
(
720
,
1280
),
9
,
2
,
n_
train
=
3
,
ignore_error
=
ignore_error
,
gpu_only
=
gpu_only
,
cpu_only
=
cpu_only
,
verbose
=
verbose
,
check_isfinite
=
True
,
version
=
version
)
#I did a wanted error in the name as we don't want it to execute automatically for now as it don't work
def
tes_lenet_full_hd
():
#HD 1080p: 1920(wid)x1080(len)
cmp_run_conv_nnet2_classif
(
23485
,
(
1080
,
1920
),
9
,
2
,
n_
iter
=
3
,
cmp_run_conv_nnet2_classif
(
23485
,
(
1080
,
1920
),
9
,
2
,
n_
train
=
3
,
ignore_error
=
ignore_error
,
gpu_only
=
gpu_only
,
cpu_only
=
cpu_only
,
verbose
=
verbose
,
check_isfinite
=
True
,
version
=
version
)
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论