Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
d9ee20e6
提交
d9ee20e6
authored
6月 02, 2009
作者:
bergstra@ip05.m
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
added more conv profiling tests
上级
2bdcd148
隐藏空白字符变更
内嵌
并排
正在显示
1 个修改的文件
包含
100 行增加
和
33 行删除
+100
-33
test_conv.py
theano/sandbox/test_conv.py
+100
-33
没有找到文件。
theano/sandbox/test_conv.py
浏览文件 @
d9ee20e6
...
@@ -50,10 +50,10 @@ class TestConvOp(unittest.TestCase):
...
@@ -50,10 +50,10 @@ class TestConvOp(unittest.TestCase):
nkern
=
5
# nb kernel
nkern
=
5
# nb kernel
ssizes
=
((
1
,
1
),(
2
,
2
),(
3
,
3
),(
4
,
4
))
#step size
ssizes
=
((
1
,
1
),(
2
,
2
),(
3
,
3
),(
4
,
4
))
#step size
convmodes
=
(
'full'
,
'valid'
)
convmodes
=
(
'full'
,
'valid'
)
elif
0
:
elif
1
:
# fixed parameters
# fixed parameters
like NORB JOB
bsize
=
10
# batch size
bsize
=
4
# batch size
imshp
=
(
50
,
50
)
# image shape
imshp
=
(
96
,
96
)
# image shape
print
>>
sys
.
stderr
,
"WARNING: only square shape tested"
print
>>
sys
.
stderr
,
"WARNING: only square shape tested"
kshps
=
[(
12
,
12
),
(
12
,
12
)]
kshps
=
[(
12
,
12
),
(
12
,
12
)]
nkern
=
20
# nb kernel
nkern
=
20
# nb kernel
...
@@ -102,6 +102,8 @@ class TestConvOp(unittest.TestCase):
...
@@ -102,6 +102,8 @@ class TestConvOp(unittest.TestCase):
#profmode = wraplinker.ProfileMode(OpWiseCLinker(), 'fast_run')
#profmode = wraplinker.ProfileMode(OpWiseCLinker(), 'fast_run')
tconvop
,
tscipy
,
tconv2
=
[],
[],
[]
tconvop
,
tscipy
,
tconv2
=
[],
[],
[]
tconvop_kern
,
tconvop_batch
=
[],
[]
tconvop_gemm
=
[]
for
conv_mode
in
convmodes
:
for
conv_mode
in
convmodes
:
for
kshp
in
kshps
:
for
kshp
in
kshps
:
...
@@ -112,7 +114,7 @@ class TestConvOp(unittest.TestCase):
...
@@ -112,7 +114,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,37 +123,100 @@ class TestConvOp(unittest.TestCase):
...
@@ -121,37 +123,100 @@ 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
]]
out4
=
out4
.
reshape
(
bsize
,
-
1
)
out4
=
out4
.
reshape
(
bsize
,
-
1
)
# compute with ConvOp
if
1
:
# compute with ConvOp (code_a)
dmatrix3
=
T
.
TensorType
(
'float64'
,
(
False
,
False
,
False
))
dmatrix3
=
T
.
TensorType
(
'float64'
,
(
False
,
False
,
False
))
inputs
=
dmatrix3
()
inputs
=
dmatrix3
()
kerns3
=
dmatrix3
()
kerns3
=
dmatrix3
()
bia
=
T
.
dscalar
()
bia
=
T
.
dscalar
()
conv_op
=
ConvOp
(
imshp
,
kshp
,
nkern
,
bsize
,
1
,
1
,
conv_mode
)(
inputs
,
kerns3
)
conv_op
=
ConvOp
(
imshp
,
kshp
,
nkern
,
bsize
,
1
,
1
,
conv_mode
,
use_gemm
=
False
)(
inputs
,
kerns3
)
f2
=
function
([
inputs
,
kerns3
],
conv_op
,
mode
=
Mode
(
linker
=
"c"
))
f2
=
function
([
inputs
,
kerns3
],
conv_op
,
mode
=
Mode
(
linker
=
"c"
))
f3
=
function
([
inputs
,
kerns3
],
conv_op
,
mode
=
Mode
(
linker
=
"py"
))
f3
=
function
([
inputs
,
kerns3
],
conv_op
,
mode
=
Mode
(
linker
=
"py"
))
ttime1
=
time
.
time
()
ttime1
=
time
.
time
()
out2_
=
f2
(
img2d
,
filtersflipped
)
out2_
=
f2
(
img2d
,
filtersflipped
)
out2__
=
out2_
[:,:,
0
::
ss
[
0
],
0
::
ss
[
1
]]
out2__
=
out2_
[:,:,
0
::
ss
[
0
],
0
::
ss
[
1
]]
tconvop
+=
[
time
.
time
()
-
ttime1
]
tconvop
+=
[
time
.
time
()
-
ttime1
]
out2___
=
out2__
.
copy
()
out2___
=
out2__
.
copy
()
out2
=
out2___
+
biasvals
.
reshape
(
1
,
nkern
,
1
,
1
)
out2
=
out2___
+
biasvals
.
reshape
(
1
,
nkern
,
1
,
1
)
out3_
=
f3
(
img2d
,
filtersflipped
)
out3_
=
f3
(
img2d
,
filtersflipped
)
out3__
=
out3_
[:,:,
0
::
ss
[
0
],
0
::
ss
[
1
]]
out3__
=
out3_
[:,:,
0
::
ss
[
0
],
0
::
ss
[
1
]]
out3___
=
out3__
.
copy
()
out3___
=
out3__
.
copy
()
out3
=
out3___
+
biasvals
.
reshape
(
1
,
nkern
,
1
,
1
)
out3
=
out3___
+
biasvals
.
reshape
(
1
,
nkern
,
1
,
1
)
assert
(
N
.
abs
(
out2_
-
out3_
)
<
1e-5
)
.
all
()
assert
(
N
.
abs
(
out2_
-
out3_
)
<
1e-5
)
.
all
()
if
1
:
# compute with ConvOp with gemm if possible
dmatrix3
=
T
.
TensorType
(
'float64'
,
(
False
,
False
,
False
))
inputs
=
dmatrix3
()
kerns3
=
dmatrix3
()
bia
=
T
.
dscalar
()
conv_op
=
ConvOp
(
imshp
,
kshp
,
nkern
,
bsize
,
1
,
1
,
conv_mode
,
use_gemm
=
True
)(
inputs
,
kerns3
)
f2
=
function
([
inputs
,
kerns3
],
conv_op
,
mode
=
Mode
(
linker
=
"c"
))
f3
=
function
([
inputs
,
kerns3
],
conv_op
,
mode
=
Mode
(
linker
=
"py"
))
ttime1
=
time
.
time
()
out2_
=
f2
(
img2d
,
filtersflipped
)
out2__
=
out2_
[:,:,
0
::
ss
[
0
],
0
::
ss
[
1
]]
tconvop_gemm
+=
[
time
.
time
()
-
ttime1
]
out2___
=
out2__
.
copy
()
out2
=
out2___
+
biasvals
.
reshape
(
1
,
nkern
,
1
,
1
)
out3_
=
f3
(
img2d
,
filtersflipped
)
out3__
=
out3_
[:,:,
0
::
ss
[
0
],
0
::
ss
[
1
]]
out3___
=
out3__
.
copy
()
out3
=
out3___
+
biasvals
.
reshape
(
1
,
nkern
,
1
,
1
)
assert
(
N
.
abs
(
out2_
-
out3_
)
<
1e-5
)
.
all
()
if
1
:
# compute with ConvOp with unroll_batch
dmatrix3
=
T
.
TensorType
(
'float64'
,
(
False
,
False
,
False
))
inputs
=
dmatrix3
()
kerns3
=
dmatrix3
()
bia
=
T
.
dscalar
()
conv_op
=
ConvOp
(
imshp
,
kshp
,
nkern
,
bsize
,
1
,
1
,
conv_mode
,
use_gemm
=
False
,
unroll_batch
=
bsize
)(
inputs
,
kerns3
)
f2
=
function
([
inputs
,
kerns3
],
conv_op
,
mode
=
Mode
(
linker
=
"c"
))
f3
=
function
([
inputs
,
kerns3
],
conv_op
,
mode
=
Mode
(
linker
=
"py"
))
ttime1
=
time
.
time
()
out2_
=
f2
(
img2d
,
filtersflipped
)
out2__
=
out2_
[:,:,
0
::
ss
[
0
],
0
::
ss
[
1
]]
tconvop_batch
+=
[
time
.
time
()
-
ttime1
]
out2___
=
out2__
.
copy
()
out2
=
out2___
+
biasvals
.
reshape
(
1
,
nkern
,
1
,
1
)
out3_
=
f3
(
img2d
,
filtersflipped
)
out3__
=
out3_
[:,:,
0
::
ss
[
0
],
0
::
ss
[
1
]]
out3___
=
out3__
.
copy
()
out3
=
out3___
+
biasvals
.
reshape
(
1
,
nkern
,
1
,
1
)
assert
(
N
.
abs
(
out2_
-
out3_
)
<
1e-5
)
.
all
()
if
1
:
# compute with ConvOp with unroll_kern
dmatrix3
=
T
.
TensorType
(
'float64'
,
(
False
,
False
,
False
))
inputs
=
dmatrix3
()
kerns3
=
dmatrix3
()
bia
=
T
.
dscalar
()
conv_op
=
ConvOp
(
imshp
,
kshp
,
nkern
,
bsize
,
1
,
1
,
conv_mode
,
use_gemm
=
False
,
unroll_kern
=
bsize
)(
inputs
,
kerns3
)
f2
=
function
([
inputs
,
kerns3
],
conv_op
,
mode
=
Mode
(
linker
=
"c"
))
f3
=
function
([
inputs
,
kerns3
],
conv_op
,
mode
=
Mode
(
linker
=
"py"
))
ttime1
=
time
.
time
()
out2_
=
f2
(
img2d
,
filtersflipped
)
out2__
=
out2_
[:,:,
0
::
ss
[
0
],
0
::
ss
[
1
]]
tconvop_kern
+=
[
time
.
time
()
-
ttime1
]
out2___
=
out2__
.
copy
()
out2
=
out2___
+
biasvals
.
reshape
(
1
,
nkern
,
1
,
1
)
out3_
=
f3
(
img2d
,
filtersflipped
)
out3__
=
out3_
[:,:,
0
::
ss
[
0
],
0
::
ss
[
1
]]
out3___
=
out3__
.
copy
()
out3
=
out3___
+
biasvals
.
reshape
(
1
,
nkern
,
1
,
1
)
assert
(
N
.
abs
(
out2_
-
out3_
)
<
1e-5
)
.
all
()
# REFERENCE IMPLEMENTATION: compute output with convolve2d
# REFERENCE IMPLEMENTATION: compute output with convolve2d
fulloutshp
=
N
.
array
(
imshp
)
-
N
.
array
(
kshp
)
+
1
if
conv_mode
==
'valid'
\
fulloutshp
=
N
.
array
(
imshp
)
-
N
.
array
(
kshp
)
+
1
if
conv_mode
==
'valid'
\
...
@@ -179,12 +244,14 @@ class TestConvOp(unittest.TestCase):
...
@@ -179,12 +244,14 @@ class TestConvOp(unittest.TestCase):
assert
(
temp
<
1e-5
)
.
all
()
assert
(
temp
<
1e-5
)
.
all
()
print
'**** Convolution Profiling Results ****'
print
'**** Convolution Profiling Results ****'
print
'Scipy convolve2d processing time:
%.3
fs'
%
sum
(
tscipy
),
tscipy
print
'Scipy convolve2d processing time:
%.3
fs'
%
sum
(
tscipy
)
#
,tscipy
print
'ConvOp processing time:
%.3
fs'
%
sum
(
tconvop
),
tconvop
print
'ConvOp processing time:
%.3
fs'
%
sum
(
tconvop
)
#
,tconvop
print
'convolve2 processing time:
%.3
fs'
%
sum
(
tconv2
),
tconv2
print
'convolve2 processing time:
%.3
fs'
%
sum
(
tconv2
)
#
,tconv2
d
=
N
.
asarray
(
tscipy
)
/
tconvop
print
'speed up ConvOp vs convolve2d:
%.3
f'
%
(
N
.
asarray
(
tscipy
)
/
tconvop
)
.
mean
()
print
'speed up ConvOp vs convolve2d:
%.3
f'
%
d
.
mean
(),
d
print
'speed up use_gemm :
%.3
f'
%
(
N
.
asarray
(
tconvop
)
/
tconvop_gemm
)
.
mean
()
print
'speed up unroll_batch :
%.3
f'
%
(
N
.
asarray
(
tconvop
)
/
tconvop_batch
)
.
mean
()
print
'speed up unroll_kern :
%.3
f'
%
(
N
.
asarray
(
tconvop
)
/
tconvop_kern
)
.
mean
()
def
test_multilayer_conv
(
self
):
def
test_multilayer_conv
(
self
):
# causes an atexit problem
# causes an atexit problem
...
@@ -350,7 +417,7 @@ class TestConvOp(unittest.TestCase):
...
@@ -350,7 +417,7 @@ class TestConvOp(unittest.TestCase):
visdim
=
1
if
len
(
imshp
)
!=
3
else
imshp
[
0
]
visdim
=
1
if
len
(
imshp
)
!=
3
else
imshp
[
0
]
for
kshp
in
kshps
:
for
kshp
in
kshps
:
imgvals
=
N
.
random
.
random
(
N
.
hstack
((
bsize
,
imshp
)))
imgvals
=
N
.
random
.
random
(
N
.
hstack
((
bsize
,
imshp
)))
print
'imgvals.shape = '
,
imgvals
.
shape
#
print 'imgvals.shape = ', imgvals.shape
imgvals
=
imgvals
.
reshape
(
bsize
,
-
1
)
imgvals
=
imgvals
.
reshape
(
bsize
,
-
1
)
if
visdim
==
1
:
if
visdim
==
1
:
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论