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 个修改的文件
包含
27 行增加
和
14 行删除
+27
-14
test_conv.py
theano/sandbox/test_conv.py
+27
-14
没有找到文件。
theano/sandbox/test_conv.py
浏览文件 @
5a503ffe
...
@@ -63,7 +63,6 @@ class TestConvOp(unittest.TestCase):
...
@@ -63,7 +63,6 @@ class TestConvOp(unittest.TestCase):
# fixed parameters
# fixed parameters
bsize
=
7
# batch size
bsize
=
7
# batch size
imshp
=
(
5
,
4
)
# image shape
imshp
=
(
5
,
4
)
# image shape
print
>>
sys
.
stderr
,
"WARNING: only square shape tested"
kshps
=
[(
2
,
3
)]
kshps
=
[(
2
,
3
)]
nkern
=
6
# nb kernel
nkern
=
6
# nb kernel
ssizes
=
[(
1
,
1
)]
#step size
ssizes
=
[(
1
,
1
)]
#step size
...
@@ -72,7 +71,6 @@ class TestConvOp(unittest.TestCase):
...
@@ -72,7 +71,6 @@ class TestConvOp(unittest.TestCase):
# fixed parameters
# fixed parameters
bsize
=
7
# batch size
bsize
=
7
# batch size
imshp
=
(
5
,
4
)
# image shape
imshp
=
(
5
,
4
)
# image shape
print
>>
sys
.
stderr
,
"WARNING: only square shape tested"
kshps
=
[(
2
,
3
)]
kshps
=
[(
2
,
3
)]
nkern
=
6
# nb kernel
nkern
=
6
# nb kernel
ssizes
=
[(
1
,
1
)]
#step size
ssizes
=
[(
1
,
1
)]
#step size
...
@@ -112,7 +110,7 @@ class TestConvOp(unittest.TestCase):
...
@@ -112,7 +110,7 @@ class TestConvOp(unittest.TestCase):
# now test with real values
# now test with real values
img2d
=
1
+
N
.
arange
(
bsize
*
N
.
prod
(
imshp
))
.
reshape
((
bsize
,)
+
imshp
)
img2d
=
1
+
N
.
arange
(
bsize
*
N
.
prod
(
imshp
))
.
reshape
((
bsize
,)
+
imshp
)
print
'img2d'
,
img2d
#
print 'img2d', img2d
img1d
=
img2d
.
reshape
(
bsize
,
-
1
)
img1d
=
img2d
.
reshape
(
bsize
,
-
1
)
# create filters (need to be flipped to use convolve2d)
# create filters (need to be flipped to use convolve2d)
...
@@ -121,12 +119,12 @@ class TestConvOp(unittest.TestCase):
...
@@ -121,12 +119,12 @@ class TestConvOp(unittest.TestCase):
# compute with new convolve2 (no timing info)
# compute with new convolve2 (no timing info)
output4
,
outshp4
=
convolve2
(
kerns
,
kshp
,
nkern
,
input
,
\
output4
,
outshp4
=
convolve2
(
kerns
,
kshp
,
nkern
,
input
,
\
imshp
,
bsize
,
(
1
,
1
),
bias
=
bias
,
mode
=
conv_mode
)
imshp
,
bsize
,
(
1
,
1
),
bias
=
bias
,
mode
=
conv_mode
)
print
'output4'
,
output4
#
print 'output4', output4
ttime1
=
time
.
time
()
ttime1
=
time
.
time
()
f
=
function
([
kerns
,
bias
,
input
],
output4
)
f
=
function
([
kerns
,
bias
,
input
],
output4
)
out4
=
f
(
filtersflipped
.
reshape
(
nkern
,
-
1
),
biasvals
,
img1d
)
out4
=
f
(
filtersflipped
.
reshape
(
nkern
,
-
1
),
biasvals
,
img1d
)
print
'out4'
,
out4
,
img1d
,
filtersflipped
#
print 'out4', out4, img1d, filtersflipped
tconv2
+=
[
time
.
time
()
-
ttime1
]
tconv2
+=
[
time
.
time
()
-
ttime1
]
out4
=
out4
.
reshape
(
bsize
,
nkern
,
outshp4
[
1
],
outshp4
[
2
])
out4
=
out4
.
reshape
(
bsize
,
nkern
,
outshp4
[
1
],
outshp4
[
2
])
out4
=
out4
[:,:,
0
::
ss
[
0
],
0
::
ss
[
1
]]
out4
=
out4
[:,:,
0
::
ss
[
0
],
0
::
ss
[
1
]]
...
@@ -228,7 +226,7 @@ class TestConvOp(unittest.TestCase):
...
@@ -228,7 +226,7 @@ class TestConvOp(unittest.TestCase):
kerns4
=
dmatrix4
()
kerns4
=
dmatrix4
()
assert
len
(
kshps
)
==
len
(
nkerns
)
==
len
(
kerns
)
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
# build actual input images
imgval
=
rng
.
rand
(
bsize
,
imshp_start
[
0
],
imshp_start
[
1
],
imshp_start
[
2
])
imgval
=
rng
.
rand
(
bsize
,
imshp_start
[
0
],
imshp_start
[
1
],
imshp_start
[
2
])
...
@@ -309,17 +307,21 @@ class TestConvOp(unittest.TestCase):
...
@@ -309,17 +307,21 @@ class TestConvOp(unittest.TestCase):
hidval2
=
hidval2_
[:,:,
0
::
ss
[
0
],
0
::
ss
[
1
]]
hidval2
=
hidval2_
[:,:,
0
::
ss
[
0
],
0
::
ss
[
1
]]
tctot
+=
time
.
time
()
-
time1
tctot
+=
time
.
time
()
-
time1
if
conv_op_py
:
time1
=
time
.
time
()
time1
=
time
.
time
()
#
hidval3_ = propup3(imgval,w_flip)
hidval3_
=
propup3
(
imgval
,
w_flip
)
#
hidval3 = hidval3_[:,:,0::ss[0],0::ss[1]]
hidval3
=
hidval3_
[:,:,
0
::
ss
[
0
],
0
::
ss
[
1
]]
tpytot
+=
time
.
time
()
-
time1
tpytot
+=
time
.
time
()
-
time1
# assert (N.abs(hidval2-hidval3)<1e-5).all()
assert
(
N
.
abs
(
hidval2
-
hidval3
)
<
1e-5
)
.
all
()
else
:
tpytot
+=
0
if
validate
:
if
validate
:
temp
=
N
.
abs
(
outval
-
hidval2
)
temp
=
N
.
abs
(
outval
-
hidval2
)
assert
(
temp
<
1e-5
)
.
all
()
assert
(
temp
<
1e-5
)
.
all
()
# temp = N.abs(outval - hidval3)
if
validate
and
conv_op_py
:
# assert (temp < 1e-5).all()
temp
=
N
.
abs
(
outval
-
hidval3
)
assert
(
temp
<
1e-5
)
.
all
()
img
,
imshp
=
hid
,
tuple
(
outshp
)
img
,
imshp
=
hid
,
tuple
(
outshp
)
imgval
=
outval
.
reshape
(
bsize
,
outshp
[
0
],
outshp
[
1
],
outshp
[
2
])
imgval
=
outval
.
reshape
(
bsize
,
outshp
[
0
],
outshp
[
1
],
outshp
[
2
])
...
@@ -332,8 +334,8 @@ class TestConvOp(unittest.TestCase):
...
@@ -332,8 +334,8 @@ class TestConvOp(unittest.TestCase):
validate
=
False
# we don't validate the result to have it much faster!
validate
=
False
# we don't validate the result to have it much faster!
unroll_batch
=
[
0
,
1
,
2
,
5
,
10
,
20
]
unroll_batch
=
[
0
,
1
,
2
,
4
,
5
,
10
,
20
]
unroll_kern
=
[
0
,
1
,
2
,
5
,
10
,
20
]
unroll_kern
=
[
0
,
2
,
4
,
5
,
10
,
20
]
# unroll_batch = [0,2,5]
# unroll_batch = [0,2,5]
# unroll_kern = [0,2,5]
# unroll_kern = [0,2,5]
...
@@ -344,6 +346,10 @@ class TestConvOp(unittest.TestCase):
...
@@ -344,6 +346,10 @@ class TestConvOp(unittest.TestCase):
ssizes
=
[(
1
,
1
),]
#(1,1)]#(2,2) bugged
ssizes
=
[(
1
,
1
),]
#(1,1)]#(2,2) bugged
convmodes
=
[
'valid'
,
'full'
]
convmodes
=
[
'valid'
,
'full'
]
do_theano
=
False
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
))
timing
=
N
.
zeros
((
len
(
unroll_batch
),
len
(
unroll_kern
),
3
))
t_b_k
=
[]
t_b_k
=
[]
...
@@ -353,7 +359,7 @@ class TestConvOp(unittest.TestCase):
...
@@ -353,7 +359,7 @@ class TestConvOp(unittest.TestCase):
tctot
,
tpytot
,
ntot
=
[],[],[]
tctot
,
tpytot
,
ntot
=
[],[],[]
for
conv_mode
,
n_mode
in
zip
(
convmodes
,
range
(
len
(
convmodes
))):
for
conv_mode
,
n_mode
in
zip
(
convmodes
,
range
(
len
(
convmodes
))):
for
ss
,
n_ss
in
zip
(
ssizes
,
range
(
len
(
ssizes
))):
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_
]
tctot
+=
[
tctot_
]
tpytot
+=
[
tpytot_
]
tpytot
+=
[
tpytot_
]
ntot
+=
[
ntot_
]
ntot
+=
[
ntot_
]
...
@@ -446,3 +452,10 @@ class TestConvOp(unittest.TestCase):
...
@@ -446,3 +452,10 @@ class TestConvOp(unittest.TestCase):
kernvals
=
kernvals
.
reshape
(
nkern
,
-
1
)
kernvals
=
kernvals
.
reshape
(
nkern
,
-
1
)
utt
.
verify_grad
(
testf
,
[
imgvals
,
kernvals
])
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
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论