Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
4880887e
提交
4880887e
authored
1月 28, 2010
作者:
Frederic Bastien
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
typo fix in last commit. Fix test following the removing of convolve2.
上级
0e9af9c4
隐藏空白字符变更
内嵌
并排
正在显示
2 个修改的文件
包含
5 行增加
和
50 行删除
+5
-50
conv.py
theano/sandbox/conv.py
+1
-1
test_conv.py
theano/sandbox/test_conv.py
+4
-49
没有找到文件。
theano/sandbox/conv.py
浏览文件 @
4880887e
...
@@ -583,7 +583,7 @@ class ConvOp(Op):
...
@@ -583,7 +583,7 @@ class ConvOp(Op):
def
c_support_code
(
self
):
def
c_support_code
(
self
):
return
"""
return
"""
define STRIDES(arr) ((arr)->strides)
#
define STRIDES(arr) ((arr)->strides)
#define FULL 2
#define FULL 2
#define SAME 1
#define SAME 1
#define VALID 0
#define VALID 0
...
...
theano/sandbox/test_conv.py
浏览文件 @
4880887e
...
@@ -7,7 +7,7 @@ from theano.tests import unittest_tools as utt
...
@@ -7,7 +7,7 @@ from theano.tests import unittest_tools as utt
from
theano
import
function
,
Mode
from
theano
import
function
,
Mode
import
theano.tensor
as
T
import
theano.tensor
as
T
from
conv
import
ConvOp
,
convolve2
,
getFilterOutShp
from
conv
import
ConvOp
,
getFilterOutShp
def
flip
(
kern
,
kshp
):
def
flip
(
kern
,
kshp
):
"flip the kernel as scipy.convolv2d do it flipped."
"flip the kernel as scipy.convolv2d do it flipped."
...
@@ -41,7 +41,7 @@ def flip(kern, kshp):
...
@@ -41,7 +41,7 @@ def flip(kern, kshp):
global_rng
=
N
.
random
.
RandomState
(
3423489
)
global_rng
=
N
.
random
.
RandomState
(
3423489
)
dmatrix4
=
T
.
TensorType
(
'float64'
,
(
False
,
False
,
False
,
False
))
dmatrix4
=
T
.
TensorType
(
'float64'
,
(
False
,
False
,
False
,
False
))
def
exec_multilayer_conv_nnet
(
conv_mode
,
ss
,
bsize
,
imshp
,
kshps
,
nkerns
,
unroll_batch
=
0
,
unroll_kern
=
0
,
img
=
T
.
dmatrix
(),
validate
=
True
,
conv_op_py
=
False
,
do_
convolve2
=
False
,
do_
print
=
True
,
repeat
=
1
,
unroll_patch
=
False
,
unroll_patch_size
=
False
,
verbose
=
0
):
def
exec_multilayer_conv_nnet
(
conv_mode
,
ss
,
bsize
,
imshp
,
kshps
,
nkerns
,
unroll_batch
=
0
,
unroll_kern
=
0
,
img
=
T
.
dmatrix
(),
validate
=
True
,
conv_op_py
=
False
,
do_print
=
True
,
repeat
=
1
,
unroll_patch
=
False
,
unroll_patch_size
=
False
,
verbose
=
0
):
# build actual input images
# build actual input images
imgval
=
global_rng
.
rand
(
bsize
,
imshp
[
0
],
imshp
[
1
],
imshp
[
2
])
imgval
=
global_rng
.
rand
(
bsize
,
imshp
[
0
],
imshp
[
1
],
imshp
[
2
])
...
@@ -92,34 +92,6 @@ def exec_multilayer_conv_nnet(conv_mode, ss, bsize, imshp, kshps, nkerns, unroll
...
@@ -92,34 +92,6 @@ def exec_multilayer_conv_nnet(conv_mode, ss, bsize, imshp, kshps, nkerns, unroll
imgval
[
b
,
i
,
...
],
w_flip
[
n
,
i
,
...
],
1
,
val
,
bval
,
0
)[
0
::
ss
[
0
],
0
::
ss
[
1
]]
imgval
[
b
,
i
,
...
],
w_flip
[
n
,
i
,
...
],
1
,
val
,
bval
,
0
)[
0
::
ss
[
0
],
0
::
ss
[
1
]]
ntot
+=
time
.
time
()
-
time1
ntot
+=
time
.
time
()
-
time1
if
do_convolve2
:
####### test with new sp.convolve2 function ######
time1
=
time
.
time
()
hid
,
outshp2
=
convolve2
(
kern
,
kshp
,
nkern
,
img
,
imshp
,
bsize
,
(
ss
[
0
],
ss
[
1
]),
mode
=
conv_mode
)
propup
=
function
([
kern
,
img
],
hid
)
propup1
=
function
([
kern
,
img
],
hid
,
mode
=
Mode
(
linker
=
"py"
))
hidval
=
propup
(
w_flip
.
reshape
(
nkern
,
-
1
),
imgval
.
reshape
(
bsize
,
-
1
))
hidval
=
hidval
.
reshape
(
bsize
,
nkern
,
outshp2
[
-
2
],
outshp2
[
-
1
])
# hidval = hidval[:,:,::ss[0],::ss[1]]
hidval
=
hidval
.
reshape
(
bsize
,
-
1
)
for
i
in
range
(
repeat
):
hidval1
=
propup1
(
w_flip
.
reshape
(
nkern
,
-
1
),
imgval
.
reshape
(
bsize
,
-
1
))
hidval1
=
hidval1
.
reshape
(
bsize
,
nkern
,
outshp2
[
-
2
],
outshp2
[
-
1
])
# hidval1 = hidval1[:,:,::ss[0],::ss[1]]
hidval1
=
hidval1
.
reshape
(
bsize
,
-
1
)
assert
(
N
.
abs
(
hidval
-
hidval1
)
<
1e-5
)
.
all
()
temp
=
N
.
abs
(
outval
.
reshape
(
bsize
,
-
1
)
-
hidval
)
if
validate
:
assert
(
temp
<
1e-5
)
.
all
()
else
:
hid
=
img
#we don't need it, but it make the flow easier flow
hidval
=
outval
.
copy
()
#to keep the same memory
hidval1
=
outval
.
copy
()
# ConvOp
# ConvOp
if
unroll_patch
and
not
unroll_patch_size
:
if
unroll_patch
and
not
unroll_patch_size
:
conv_op
=
ConvOp
(
dx
=
ss
[
0
],
dy
=
ss
[
1
],
output_mode
=
conv_mode
,
conv_op
=
ConvOp
(
dx
=
ss
[
0
],
dy
=
ss
[
1
],
output_mode
=
conv_mode
,
...
@@ -155,7 +127,7 @@ def exec_multilayer_conv_nnet(conv_mode, ss, bsize, imshp, kshps, nkerns, unroll
...
@@ -155,7 +127,7 @@ def exec_multilayer_conv_nnet(conv_mode, ss, bsize, imshp, kshps, nkerns, unroll
temp
=
N
.
abs
(
outval
-
hidval3
)
temp
=
N
.
abs
(
outval
-
hidval3
)
assert
(
temp
<
1e-5
)
.
all
()
assert
(
temp
<
1e-5
)
.
all
()
im
g
,
imshp
=
hid
,
tuple
(
outshp
)
im
shp
=
tuple
(
outshp
)
imgval
=
outval
.
reshape
(
bsize
,
outshp
[
0
],
outshp
[
1
],
outshp
[
2
])
imgval
=
outval
.
reshape
(
bsize
,
outshp
[
0
],
outshp
[
1
],
outshp
[
2
])
return
tctot
,
tpytot
,
ntot
return
tctot
,
tpytot
,
ntot
...
@@ -246,23 +218,9 @@ class TestConvOp(unittest.TestCase):
...
@@ -246,23 +218,9 @@ class TestConvOp(unittest.TestCase):
# 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
filtersflipped
=
flip
(
filters
.
reshape
((
nkern
,)
+
kshp
),
kshp
)
filtersflipped
=
flip
(
filters
.
reshape
((
nkern
,)
+
kshp
),
kshp
)
# compute with new convolve2 (no timing info)
output4
,
outshp4
=
convolve2
(
kerns
,
kshp
,
nkern
,
input
,
\
imshp
,
bsize
,
(
ss
[
0
],
ss
[
1
]),
bias
=
bias
,
mode
=
conv_mode
)
# 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
tconv2
+=
[
time
.
time
()
-
ttime1
]
out4
=
out4
.
reshape
(
bsize
,
nkern
,
outshp4
[
1
],
outshp4
[
2
])
out4
=
out4
#[:,:,0::ss[0],0::ss[1]]
out4
=
out4
.
reshape
(
bsize
,
-
1
)
# compute with ConvOp
# compute with ConvOp
dmatrix3
=
T
.
TensorType
(
'float64'
,
(
False
,
False
,
False
))
dmatrix3
=
T
.
TensorType
(
'float64'
,
(
False
,
False
,
False
))
inputs4
=
dmatrix4
()
inputs4
=
dmatrix4
()
...
@@ -307,9 +265,6 @@ class TestConvOp(unittest.TestCase):
...
@@ -307,9 +265,6 @@ class TestConvOp(unittest.TestCase):
# compare benchmark with ConvOp
# compare benchmark with ConvOp
temp
=
bench1
.
flatten
()
-
out2
.
flatten
()
temp
=
bench1
.
flatten
()
-
out2
.
flatten
()
assert
(
temp
<
1e-5
)
.
all
()
assert
(
temp
<
1e-5
)
.
all
()
# compare benchmark with convolve2
temp
=
bench1
.
flatten
()
-
out4
.
flatten
()
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
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论