Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
bf825258
提交
bf825258
authored
8月 22, 2009
作者:
James Bergstra
浏览文件
操作
浏览文件
下载
差异文件
merge
上级
ab345880
954600b4
全部展开
隐藏空白字符变更
内嵌
并排
正在显示
2 个修改的文件
包含
29 行增加
和
16 行删除
+29
-16
basic_ops.py
basic_ops.py
+0
-0
test_nnet.py
tests/test_nnet.py
+29
-16
没有找到文件。
basic_ops.py
浏览文件 @
bf825258
差异被折叠。
点击展开。
tests/test_nnet.py
浏览文件 @
bf825258
...
...
@@ -20,7 +20,8 @@ def print_mode(mode):
mode
.
print_summary
()
def
run_nnet
(
use_gpu
):
n_batch
=
16
#n_batch = 16
n_batch
=
60
#Fred recommends a nice big batch
n_in
=
1024
n_hid
=
2048
n_out
=
10
...
...
@@ -213,19 +214,20 @@ 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
(
shared_fn
):
# pretend we are training LeNet for MNIST
def
run_conv_nnet2_classif
(
shared_fn
,
isize
,
ksize
):
n_batch
=
60
shape_img
=
(
n_batch
,
1
,
32
,
32
)
shape_img
=
(
n_batch
,
1
,
isize
,
isize
)
n_kern
=
20
shape_kern
=
(
n_kern
,
1
,
5
,
5
)
n_kern
=
20
# 6 were used in LeNet5
shape_kern
=
(
n_kern
,
1
,
ksize
,
ksize
)
n_kern1
=
30
shape_kern1
=
(
n_kern1
,
n_kern
,
5
,
5
)
n_kern1
=
30
# 16 were used in LeNet5
shape_kern1
=
(
n_kern1
,
n_kern
,
ksize
,
ksize
)
logical_hid_shape
=
tcn
.
blas
.
GpuConv
.
logical_output_shape_2d
((
32
,
32
),
(
5
,
5
),
'valid'
)
logical_hid_shape1
=
tcn
.
blas
.
GpuConv
.
logical_output_shape_2d
((
logical_hid_shape
[
0
]
/
2
,
logical_hid_shape
[
1
]
/
2
),
(
5
,
5
),
'valid'
)
logical_hid_shape
=
tcn
.
blas
.
GpuConv
.
logical_output_shape_2d
((
isize
,
isize
),
(
ksize
,
ksize
),
'valid'
)
logical_hid_shape1
=
tcn
.
blas
.
GpuConv
.
logical_output_shape_2d
((
logical_hid_shape
[
0
]
/
2
,
logical_hid_shape
[
1
]
/
2
),
(
ksize
,
ksize
),
'valid'
)
n_hid
=
n_kern1
*
logical_hid_shape1
[
0
]
*
logical_hid_shape1
[
1
]
n_out
=
10
...
...
@@ -246,8 +248,8 @@ def run_conv_nnet2_classif(shared_fn): # pretend we are training LeNet for MNIST
hid
=
tensor
.
tanh
(
conv_op
(
x
,
w0
)
+
b0
)
hid1
=
tensor
.
tanh
(
conv_op1
(
hid
[:,:,::
2
,::
2
],
w1
)
+
b1
)
hid_flat
=
hid1
.
reshape
((
n_batch
,
n_hid
))
out
=
tensor
.
tanh
(
tensor
.
dot
(
hid_flat
,
v
)
+
c
)
loss
=
tensor
.
sum
(
0.5
*
(
out
-
y
)
**
2
*
lr
)
out
=
tensor
.
nnet
.
softmax
(
tensor
.
dot
(
hid_flat
,
v
)
+
c
)
loss
=
tensor
.
sum
(
tensor
.
nnet
.
crossentropy_categorical_1hot
(
out
,
tensor
.
argmax
(
y
,
axis
=
1
))
*
lr
)
print
'loss type'
,
loss
.
type
params
=
[
w0
,
b0
,
w1
,
b1
,
v
,
c
]
...
...
@@ -270,10 +272,21 @@ def run_conv_nnet2_classif(shared_fn): # pretend we are training LeNet for MNIST
print_mode
(
mode
)
return
rval
def
test_conv_nnet2_classif
(
):
numpy
.
random
.
seed
(
23456
)
rval_cpu
=
run_conv_nnet2
(
shared
)
numpy
.
random
.
seed
(
23456
)
rval_gpu
=
run_conv_nnet2
(
tcn
.
shared_constructor
)
def
run_test_conv_nnet2_classif
(
seed
,
isize
,
ksize
):
numpy
.
random
.
seed
(
seed
)
rval_cpu
=
run_conv_nnet2
_classif
(
shared
,
isize
,
ksize
)
numpy
.
random
.
seed
(
seed
)
rval_gpu
=
run_conv_nnet2
_classif
(
tcn
.
shared_constructor
,
isize
,
ksize
)
assert
numpy
.
allclose
(
rval_cpu
,
rval_gpu
,
rtol
=
1e-4
,
atol
=
1e-6
)
def
test_lenet_28
():
#MNIST
run_test_conv_nnet2_classif
(
23485
,
28
,
5
)
def
test_lenet_32
():
#CIFAR10 / Shapeset
run_test_conv_nnet2_classif
(
23485
,
32
,
5
)
def
test_lenet_108
():
# NORB
run_test_conv_nnet2_classif
(
23485
,
108
,
7
)
def
test_lenet_256
():
# ImageNet
run_test_conv_nnet2_classif
(
23485
,
256
,
9
)
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论