Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
5a503ffe
提交
5a503ffe
authored
6月 02, 2009
作者:
Frederic Bastien
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
added a parameter to compute the python version of ConvOp or not.
上级
3b51a87b
隐藏空白字符变更
内嵌
并排
正在显示
1 个修改的文件
包含
30 行增加
和
17 行删除
+30
-17
test_conv.py
theano/sandbox/test_conv.py
+30
-17
没有找到文件。
theano/sandbox/test_conv.py
浏览文件 @
5a503ffe
...
...
@@ -63,7 +63,6 @@ class TestConvOp(unittest.TestCase):
# fixed parameters
bsize
=
7
# batch size
imshp
=
(
5
,
4
)
# image shape
print
>>
sys
.
stderr
,
"WARNING: only square shape tested"
kshps
=
[(
2
,
3
)]
nkern
=
6
# nb kernel
ssizes
=
[(
1
,
1
)]
#step size
...
...
@@ -72,7 +71,6 @@ class TestConvOp(unittest.TestCase):
# fixed parameters
bsize
=
7
# batch size
imshp
=
(
5
,
4
)
# image shape
print
>>
sys
.
stderr
,
"WARNING: only square shape tested"
kshps
=
[(
2
,
3
)]
nkern
=
6
# nb kernel
ssizes
=
[(
1
,
1
)]
#step size
...
...
@@ -112,7 +110,7 @@ class TestConvOp(unittest.TestCase):
# now test with real values
img2d
=
1
+
N
.
arange
(
bsize
*
N
.
prod
(
imshp
))
.
reshape
((
bsize
,)
+
imshp
)
print
'img2d'
,
img2d
#
print 'img2d', img2d
img1d
=
img2d
.
reshape
(
bsize
,
-
1
)
# create filters (need to be flipped to use convolve2d)
...
...
@@ -121,12 +119,12 @@ class TestConvOp(unittest.TestCase):
# compute with new convolve2 (no timing info)
output4
,
outshp4
=
convolve2
(
kerns
,
kshp
,
nkern
,
input
,
\
imshp
,
bsize
,
(
1
,
1
),
bias
=
bias
,
mode
=
conv_mode
)
print
'output4'
,
output4
#
print 'output4', output4
ttime1
=
time
.
time
()
f
=
function
([
kerns
,
bias
,
input
],
output4
)
out4
=
f
(
filtersflipped
.
reshape
(
nkern
,
-
1
),
biasvals
,
img1d
)
print
'out4'
,
out4
,
img1d
,
filtersflipped
#
print 'out4', out4, img1d, filtersflipped
tconv2
+=
[
time
.
time
()
-
ttime1
]
out4
=
out4
.
reshape
(
bsize
,
nkern
,
outshp4
[
1
],
outshp4
[
2
])
out4
=
out4
[:,:,
0
::
ss
[
0
],
0
::
ss
[
1
]]
...
...
@@ -228,7 +226,7 @@ class TestConvOp(unittest.TestCase):
kerns4
=
dmatrix4
()
assert
len
(
kshps
)
==
len
(
nkerns
)
==
len
(
kerns
)
def
do_test
(
conv_mode
,
ss
,
unroll_batch
=
0
,
unroll_kern
=
0
,
img
=
img
,
validate
=
True
):
def
do_test
(
conv_mode
,
ss
,
unroll_batch
=
0
,
unroll_kern
=
0
,
img
=
img
,
validate
=
True
,
conv_op_py
=
False
):
# build actual input images
imgval
=
rng
.
rand
(
bsize
,
imshp_start
[
0
],
imshp_start
[
1
],
imshp_start
[
2
])
...
...
@@ -309,17 +307,21 @@ class TestConvOp(unittest.TestCase):
hidval2
=
hidval2_
[:,:,
0
::
ss
[
0
],
0
::
ss
[
1
]]
tctot
+=
time
.
time
()
-
time1
time1
=
time
.
time
()
# hidval3_ = propup3(imgval,w_flip)
# hidval3 = hidval3_[:,:,0::ss[0],0::ss[1]]
tpytot
+=
time
.
time
()
-
time1
# assert (N.abs(hidval2-hidval3)<1e-5).all()
if
conv_op_py
:
time1
=
time
.
time
()
hidval3_
=
propup3
(
imgval
,
w_flip
)
hidval3
=
hidval3_
[:,:,
0
::
ss
[
0
],
0
::
ss
[
1
]]
tpytot
+=
time
.
time
()
-
time1
assert
(
N
.
abs
(
hidval2
-
hidval3
)
<
1e-5
)
.
all
()
else
:
tpytot
+=
0
if
validate
:
temp
=
N
.
abs
(
outval
-
hidval2
)
assert
(
temp
<
1e-5
)
.
all
()
# temp = N.abs(outval - hidval3)
# assert (temp < 1e-5).all()
if
validate
and
conv_op_py
:
temp
=
N
.
abs
(
outval
-
hidval3
)
assert
(
temp
<
1e-5
)
.
all
()
img
,
imshp
=
hid
,
tuple
(
outshp
)
imgval
=
outval
.
reshape
(
bsize
,
outshp
[
0
],
outshp
[
1
],
outshp
[
2
])
...
...
@@ -332,11 +334,11 @@ class TestConvOp(unittest.TestCase):
validate
=
False
# we don't validate the result to have it much faster!
unroll_batch
=
[
0
,
1
,
2
,
5
,
10
,
20
]
unroll_kern
=
[
0
,
1
,
2
,
5
,
10
,
20
]
unroll_batch
=
[
0
,
1
,
2
,
4
,
5
,
10
,
20
]
unroll_kern
=
[
0
,
2
,
4
,
5
,
10
,
20
]
# unroll_batch = [0,2,5]
# unroll_kern = [0,2,5]
bsize
=
20
# batch size
imshp_start
=
(
1
,
50
,
49
)
#un square shape to test more corner case.
kshps
=
([
11
,
12
],[
12
,
11
])
#un square shape to test more corner case.
...
...
@@ -344,7 +346,11 @@ class TestConvOp(unittest.TestCase):
ssizes
=
[(
1
,
1
),]
#(1,1)]#(2,2) bugged
convmodes
=
[
'valid'
,
'full'
]
do_theano
=
False
a
=
T
.
dmatrix
()
kerns
=
[
a
for
i
in
nkerns
]
assert
len
(
kshps
)
==
len
(
nkerns
)
==
len
(
kerns
)
timing
=
N
.
zeros
((
len
(
unroll_batch
),
len
(
unroll_kern
),
3
))
t_b_k
=
[]
for
unroll_b
,
n_b
in
zip
(
unroll_batch
,
range
(
len
(
unroll_batch
))):
...
...
@@ -353,7 +359,7 @@ class TestConvOp(unittest.TestCase):
tctot
,
tpytot
,
ntot
=
[],[],[]
for
conv_mode
,
n_mode
in
zip
(
convmodes
,
range
(
len
(
convmodes
))):
for
ss
,
n_ss
in
zip
(
ssizes
,
range
(
len
(
ssizes
))):
tctot_
,
tpytot_
,
ntot_
=
do_test
(
conv_mode
,
ss
,
unroll_batch
=
unroll_b
,
unroll_kern
=
unroll_k
,
validate
=
validate
)
tctot_
,
tpytot_
,
ntot_
=
do_test
(
conv_mode
,
ss
,
unroll_batch
=
unroll_b
,
unroll_kern
=
unroll_k
,
validate
=
validate
)
tctot
+=
[
tctot_
]
tpytot
+=
[
tpytot_
]
ntot
+=
[
ntot_
]
...
...
@@ -446,3 +452,10 @@ class TestConvOp(unittest.TestCase):
kernvals
=
kernvals
.
reshape
(
nkern
,
-
1
)
utt
.
verify_grad
(
testf
,
[
imgvals
,
kernvals
])
if
__name__
==
'__main__'
:
t
=
TestConvOp
(
"test_convolution"
)
t
.
test_convolution
()
# t.test_multilayer_conv()
# from theano.tests import main
# main("test_sp")
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论