Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
57489fbe
提交
57489fbe
authored
6月 02, 2009
作者:
Frederic Bastien
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
added option to ConvOp that allow using the unroll version of the code. The…
added option to ConvOp that allow using the unroll version of the code. The default is to don't use this version of the code.
上级
fdd808d7
隐藏空白字符变更
内嵌
并排
正在显示
2 个修改的文件
包含
28 行增加
和
16 行删除
+28
-16
conv.py
theano/sandbox/conv.py
+15
-3
test_conv.py
theano/sandbox/test_conv.py
+13
-13
没有找到文件。
theano/sandbox/conv.py
浏览文件 @
57489fbe
...
@@ -16,8 +16,11 @@ class ConvOp(Op):
...
@@ -16,8 +16,11 @@ class ConvOp(Op):
In development.
In development.
"""
"""
def
__init__
(
self
,
imshp
,
kshp
,
nkern
,
bsize
,
dx
,
dy
,
output_mode
=
'valid'
):
def
__init__
(
self
,
imshp
,
kshp
,
nkern
,
bsize
,
dx
,
dy
,
output_mode
=
'valid'
,
unroll_batch
=
0
,
unroll_kern
=
0
):
"""
unroll_batch. If >0 will use a version that will unroll the batch loop by the value of the option. By default don't use this version of the code.
unroll_nkern. idem as unroll_batch but unroll the kernel loop.
"""
imshp
=
tuple
(
imshp
)
imshp
=
tuple
(
imshp
)
if
len
(
imshp
)
==
2
:
if
len
(
imshp
)
==
2
:
self
.
imshp
=
(
1
,)
+
imshp
self
.
imshp
=
(
1
,)
+
imshp
...
@@ -31,6 +34,11 @@ class ConvOp(Op):
...
@@ -31,6 +34,11 @@ class ConvOp(Op):
self
.
bsize
=
bsize
self
.
bsize
=
bsize
self
.
dx
=
dx
self
.
dx
=
dx
self
.
dy
=
dy
self
.
dy
=
dy
self
.
unroll_batch
=
unroll_batch
self
.
unroll_kern
=
unroll_kern
assert
not
(
unroll_batch
>
0
and
unroll_kern
>
0
)
if
self
.
dx
!=
1
or
self
.
dy
!=
1
:
if
self
.
dx
!=
1
or
self
.
dy
!=
1
:
print
"Warning, dx!=1 or dy!=1 only supported in python mode!"
print
"Warning, dx!=1 or dy!=1 only supported in python mode!"
raise
NotImplementedError
()
raise
NotImplementedError
()
...
@@ -164,7 +172,9 @@ using namespace std;
...
@@ -164,7 +172,9 @@ using namespace std;
if
node
.
inputs
[
0
]
.
type
.
dtype
==
"float32"
:
d
[
"type"
]
=
"float"
if
node
.
inputs
[
0
]
.
type
.
dtype
==
"float32"
:
d
[
"type"
]
=
"float"
elif
node
.
inputs
[
0
]
.
type
.
dtype
==
"float64"
:
d
[
"type"
]
=
"double"
elif
node
.
inputs
[
0
]
.
type
.
dtype
==
"float64"
:
d
[
"type"
]
=
"double"
else
:
raise
Exception
(
"Type
%
s not implemented"
%
node
.
inputs
[
0
]
.
type
.
dtype
)
else
:
raise
Exception
(
"Type
%
s not implemented"
%
node
.
inputs
[
0
]
.
type
.
dtype
)
if
self
.
unroll_batch
>
0
:
return
gen_conv_code_unroll_bsize
(
d
,
self
.
unroll_batch
)
#TODO: should we choose the unroll size automatically with the bigger divisor under 5? under 10?
if
self
.
out_mode
==
'valid'
:
if
self
.
out_mode
==
'valid'
:
return
_conv_op_code_valid_gemm
%
d
return
_conv_op_code_valid_gemm
%
d
else
:
else
:
...
@@ -617,6 +627,8 @@ Py_XDECREF(img2d);
...
@@ -617,6 +627,8 @@ Py_XDECREF(img2d);
def
gen_conv_code_unroll_bsize
(
d
,
unloop_bsize
=
1
):
def
gen_conv_code_unroll_bsize
(
d
,
unloop_bsize
=
1
):
""" c_code for ConvOp that unroll the batch size loop
"""
d
[
"unloop_bsize"
]
=
unloop_bsize
d
[
"unloop_bsize"
]
=
unloop_bsize
def
my_dup
(
st
):
def
my_dup
(
st
):
s
=
""
s
=
""
...
...
theano/sandbox/test_conv.py
浏览文件 @
57489fbe
...
@@ -207,13 +207,13 @@ class TestConvOp(unittest.TestCase):
...
@@ -207,13 +207,13 @@ class TestConvOp(unittest.TestCase):
ssizes
=
[(
1
,
1
),(
2
,
2
)]
#2,2)]
ssizes
=
[(
1
,
1
),(
2
,
2
)]
#2,2)]
#test speed
#test speed
#
bsize = 10 # batch size
bsize
=
10
# batch size
#
imshp_start = (1,50,50)
imshp_start
=
(
1
,
50
,
50
)
#
kshps = ([12,12],[12,12])
kshps
=
([
12
,
12
],[
12
,
12
])
#
nkerns = [20,20] # per output pixel
nkerns
=
[
20
,
20
]
# per output pixel
# ssizes = [(1,1),
(1,1)]#(2,2) bugged
ssizes
=
[(
1
,
1
),]
#
(1,1)]#(2,2) bugged
#
convmodes = ['valid','full']
convmodes
=
[
'valid'
,
'full'
]
# do_theano=Tru
e
do_theano
=
Fals
e
N
.
set_printoptions
(
threshold
=
N
.
nan
)
N
.
set_printoptions
(
threshold
=
N
.
nan
)
...
@@ -297,7 +297,7 @@ class TestConvOp(unittest.TestCase):
...
@@ -297,7 +297,7 @@ class TestConvOp(unittest.TestCase):
hidval1
=
outval
.
copy
()
hidval1
=
outval
.
copy
()
# ConvOp
# ConvOp
conv_op
=
ConvOp
(
imshp
,
kshp
,
nkern
,
bsize
,
1
,
1
,
conv_mode
)(
inputs4
,
kerns4
)
conv_op
=
ConvOp
(
imshp
,
kshp
,
nkern
,
bsize
,
1
,
1
,
conv_mode
,
unroll_batch
=
10
)(
inputs4
,
kerns4
)
l1shp
=
N
.
hstack
((
nkern
,
l1shp
=
N
.
hstack
((
nkern
,
getFilterOutShp
(
imshp
,
kshp
,
ss
,
conv_mode
)))
getFilterOutShp
(
imshp
,
kshp
,
ss
,
conv_mode
)))
propup2
=
function
([
inputs4
,
kerns4
],
conv_op
)
propup2
=
function
([
inputs4
,
kerns4
],
conv_op
)
...
@@ -309,15 +309,15 @@ class TestConvOp(unittest.TestCase):
...
@@ -309,15 +309,15 @@ class TestConvOp(unittest.TestCase):
t2ctot
+=
[
time
.
time
()
-
time1
]
t2ctot
+=
[
time
.
time
()
-
time1
]
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]]
t2pytot
+=
[
time
.
time
()
-
time1
]
t2pytot
+=
[
time
.
time
()
-
time1
]
assert
(
N
.
abs
(
hidval2
-
hidval3
)
<
1e-5
)
.
all
()
#
assert (N.abs(hidval2-hidval3)<1e-5).all()
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
)
#
temp = N.abs(outval - hidval3)
assert
(
temp
<
1e-5
)
.
all
()
#
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
])
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论