Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
9982dc5c
提交
9982dc5c
authored
7月 09, 2009
作者:
Frederic Bastien
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
fix test TestConvOp.test_convolution. We only support 4d images and kernels.
上级
26fe6416
隐藏空白字符变更
内嵌
并排
正在显示
1 个修改的文件
包含
21 行增加
和
18 行删除
+21
-18
test_conv.py
theano/sandbox/test_conv.py
+21
-18
没有找到文件。
theano/sandbox/test_conv.py
浏览文件 @
9982dc5c
...
...
@@ -158,6 +158,9 @@ def exec_multilayer_conv_nnet(conv_mode, ss, bsize, imshp, kshps, nkerns, unroll
class
TestConvOp
(
unittest
.
TestCase
):
"""NOTE: we test only when we pass 4d tensor.
"""
def
setUp
(
self
):
utt
.
seed_rng
()
...
...
@@ -170,7 +173,7 @@ class TestConvOp(unittest.TestCase):
if
0
:
# fixed parameters
bsize
=
10
# batch size
imshp
=
(
28
,
28
)
# image shape
imshp
=
(
1
,
28
,
28
)
# image shape
kshps
=
[(
5
,
5
),(
6
,
7
),(
12
,
8
)]
# kernel shaped
nkern
=
5
# nb kernel
ssizes
=
((
1
,
1
),(
2
,
2
),(
3
,
3
),(
4
,
4
))
#step size
...
...
@@ -178,7 +181,7 @@ class TestConvOp(unittest.TestCase):
elif
0
:
# fixed parameters
bsize
=
10
# batch size
imshp
=
(
50
,
50
)
# image shape
imshp
=
(
1
,
50
,
50
)
# image shape
print
>>
sys
.
stderr
,
"WARNING: only square shape tested"
kshps
=
[(
12
,
12
),
(
12
,
12
)]
nkern
=
20
# nb kernel
...
...
@@ -187,7 +190,7 @@ class TestConvOp(unittest.TestCase):
elif
0
:
# fixed parameters
bsize
=
7
# batch size
imshp
=
(
5
,
4
)
# image shape
imshp
=
(
1
,
5
,
4
)
# image shape
kshps
=
[(
2
,
3
)]
nkern
=
6
# nb kernel
ssizes
=
[(
1
,
1
)]
#step size
...
...
@@ -195,7 +198,7 @@ class TestConvOp(unittest.TestCase):
else
:
# fixed parameters
bsize
=
7
# batch size
imshp
=
(
5
,
4
)
# image shape
imshp
=
(
1
,
5
,
4
)
# image shape
kshps
=
[(
2
,
3
)]
nkern
=
6
# nb kernel
ssizes
=
[(
1
,
1
)]
#step size
...
...
@@ -204,13 +207,13 @@ class TestConvOp(unittest.TestCase):
# TODO: ask Fred about this
# this combination trigered a bug.
# bsize=1
# imshp=(9,9)#fail with 9,9
# imshp=(
1,
9,9)#fail with 9,9
# kshp=(2,2)
# nkern=5
# ssizes=((1,1),)
# this combination trigered a bug.
# bsize = 1 # batch size
# imshp = (3,3)# image shape
# imshp = (
1,
3,3)# image shape
# kshp = (2,3)#(5,5) # kernel shaped
# nkern = 1 # nb kernel
# ssizes = ((1,1),)#(2,2),(3,3),(4,4))#step size
...
...
@@ -257,34 +260,34 @@ class TestConvOp(unittest.TestCase):
# compute with ConvOp
dmatrix3
=
T
.
TensorType
(
'float64'
,
(
False
,
False
,
False
))
inputs
=
dmatrix3
()
kerns
3
=
dmatrix3
()
inputs
4
=
dmatrix4
()
kerns
4
=
dmatrix4
()
bia
=
T
.
dscalar
()
conv_op
=
ConvOp
(
imshp
,
kshp
,
nkern
,
bsize
,
ss
[
0
],
ss
[
1
],
conv_mode
)(
inputs
,
kerns3
)
f2
=
function
([
inputs
,
kerns3
],
conv_op
,
mode
=
Mode
(
linker
=
"c"
))
f3
=
function
([
inputs
,
kerns3
],
conv_op
,
mode
=
Mode
(
linker
=
"py"
))
conv_op
=
ConvOp
(
imshp
,
kshp
,
nkern
,
bsize
,
ss
[
0
],
ss
[
1
],
conv_mode
)(
inputs
4
,
kerns4
)
f2
=
function
([
inputs
4
,
kerns4
],
conv_op
,
mode
=
Mode
(
linker
=
"c"
))
f3
=
function
([
inputs
4
,
kerns4
],
conv_op
,
mode
=
Mode
(
linker
=
"py"
))
ttime1
=
time
.
time
()
out2_
=
f2
(
img2d
,
filtersflipped
)
out2__
=
out2_
#[:,:,0::ss[0],0::ss[1]]
out2_
=
f2
(
img2d
,
filtersflipped
.
reshape
(
nkern
,
1
,
*
kshp
)
)
out2__
=
out2_
tconvop
+=
[
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_
=
f3
(
img2d
,
filtersflipped
.
reshape
(
nkern
,
1
,
*
kshp
)
)
out3__
=
out3_
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
fulloutshp
=
N
.
array
(
imshp
)
-
N
.
array
(
kshp
)
+
1
if
conv_mode
==
'valid'
\
else
N
.
array
(
imshp
)
+
N
.
array
(
kshp
)
-
1
fulloutshp
=
N
.
array
(
imshp
[
1
:]
)
-
N
.
array
(
kshp
)
+
1
if
conv_mode
==
'valid'
\
else
N
.
array
(
imshp
[
1
:]
)
+
N
.
array
(
kshp
)
-
1
ntime1
=
time
.
time
()
refout
=
N
.
zeros
((
bsize
,)
+
tuple
(
fulloutshp
)
+
(
nkern
,))
for
b
in
range
(
bsize
):
for
n
in
range
(
nkern
):
refout
[
b
,
...
,
n
]
=
convolve2d
(
\
img2d
[
b
,:,:],
filtersflipped
[
n
,
...
],
conv_mode
)
img2d
[
b
,
0
,
:,:],
filtersflipped
[
n
,
...
],
conv_mode
)
tscipy
+=
[
time
.
time
()
-
ntime1
]
# need to flatten images
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论