Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
efd4d4b9
提交
efd4d4b9
authored
1月 25, 2016
作者:
Pascal Lamblin
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #3908 from vmichals/abstract_conv_keep_stacktrace
keep stacktrace in abstract_conv optimizations
上级
8020a38f
3805e3b5
隐藏空白字符变更
内嵌
并排
正在显示
3 个修改的文件
包含
26 行增加
和
3 行删除
+26
-3
.gitignore
.gitignore
+1
-1
test_abstractconv.py
theano/sandbox/gpuarray/tests/test_abstractconv.py
+5
-1
opt.py
theano/tensor/nnet/opt.py
+20
-1
没有找到文件。
.gitignore
浏览文件 @
efd4d4b9
...
@@ -36,4 +36,4 @@ distribute-*.tar.gz
...
@@ -36,4 +36,4 @@ distribute-*.tar.gz
Theano.suo
Theano.suo
.ipynb_checkpoints
.ipynb_checkpoints
.pydevproject
.pydevproject
.ropeproject
theano/sandbox/gpuarray/tests/test_abstractconv.py
浏览文件 @
efd4d4b9
...
@@ -93,11 +93,13 @@ class TestConv2d(unittest.TestCase):
...
@@ -93,11 +93,13 @@ class TestConv2d(unittest.TestCase):
assert
any
([
isinstance
(
n
.
op
,
target_op
)
for
n
assert
any
([
isinstance
(
n
.
op
,
target_op
)
for
n
in
f
.
maker
.
fgraph
.
toposort
()])
in
f
.
maker
.
fgraph
.
toposort
()])
self
.
assertTrue
(
hasattr
(
f
.
maker
.
fgraph
.
outputs
[
0
]
.
tag
,
'trace'
))
res_ref
=
numpy
.
array
(
f_ref
())
res_ref
=
numpy
.
array
(
f_ref
())
res
=
numpy
.
array
(
f
())
res
=
numpy
.
array
(
f
())
utt
.
assert_allclose
(
res_ref
,
res
)
utt
.
assert_allclose
(
res_ref
,
res
)
if
verify_grad
:
if
verify_grad
:
utt
.
verify_grad
(
conv
.
AbstractConv2d
(
border_mode
=
"valid"
,
imshp
=
imshp
,
kshp
=
kshp
,
utt
.
verify_grad
(
conv
.
AbstractConv2d
(
border_mode
=
"valid"
,
imshp
=
imshp
,
kshp
=
kshp
,
subsample
=
subsample
),
subsample
=
subsample
),
[
inputs_val
,
filters_val
],
[
inputs_val
,
filters_val
],
mode
=
mode
)
mode
=
mode
)
...
@@ -136,6 +138,7 @@ class TestConv2d(unittest.TestCase):
...
@@ -136,6 +138,7 @@ class TestConv2d(unittest.TestCase):
subsample
=
subsample
,
subsample
=
subsample
,
conv_mode
=
conv_mode
)
conv_mode
=
conv_mode
)
f
=
theano
.
function
([],
c
,
mode
)
f
=
theano
.
function
([],
c
,
mode
)
self
.
assertTrue
(
hasattr
(
f
.
maker
.
fgraph
.
outputs
[
0
]
.
tag
,
'trace'
))
f_ref
=
theano
.
function
([],
c_ref
,
mode
)
f_ref
=
theano
.
function
([],
c_ref
,
mode
)
if
target_op
is
not
None
:
if
target_op
is
not
None
:
...
@@ -186,6 +189,7 @@ class TestConv2d(unittest.TestCase):
...
@@ -186,6 +189,7 @@ class TestConv2d(unittest.TestCase):
border_mode
=
border_mode
,
subsample
=
subsample
,
border_mode
=
border_mode
,
subsample
=
subsample
,
conv_mode
=
conv_mode
)
conv_mode
=
conv_mode
)
f
=
theano
.
function
([],
c
,
mode
)
f
=
theano
.
function
([],
c
,
mode
)
self
.
assertTrue
(
hasattr
(
f
.
maker
.
fgraph
.
outputs
[
0
]
.
tag
,
'trace'
))
f_ref
=
theano
.
function
([],
c_ref
,
mode
)
f_ref
=
theano
.
function
([],
c_ref
,
mode
)
if
target_op
is
not
None
:
if
target_op
is
not
None
:
...
...
theano/tensor/nnet/opt.py
浏览文件 @
efd4d4b9
...
@@ -17,7 +17,8 @@ from theano.tensor.nnet.abstract_conv import (AbstractConv2d,
...
@@ -17,7 +17,8 @@ from theano.tensor.nnet.abstract_conv import (AbstractConv2d,
AbstractConv2d_gradWeights
,
AbstractConv2d_gradWeights
,
AbstractConv2d_gradInputs
)
AbstractConv2d_gradInputs
)
from
theano.tensor.nnet.abstract_conv
import
get_conv_output_shape
from
theano.tensor.nnet.abstract_conv
import
get_conv_output_shape
from
theano.tensor.opt
import
register_specialize_device
from
theano.tensor.opt
import
(
copy_stack_trace
,
register_specialize_device
)
from
theano.tensor
import
TensorType
from
theano.tensor
import
TensorType
# Cpu implementation
# Cpu implementation
...
@@ -75,6 +76,7 @@ def local_abstractconv_gemm(node):
...
@@ -75,6 +76,7 @@ def local_abstractconv_gemm(node):
kern
=
kern
[:,
:,
::
-
1
,
::
-
1
]
kern
=
kern
[:,
:,
::
-
1
,
::
-
1
]
rval
=
CorrMM
(
border_mode
=
node
.
op
.
border_mode
,
rval
=
CorrMM
(
border_mode
=
node
.
op
.
border_mode
,
subsample
=
node
.
op
.
subsample
)(
img
,
kern
)
subsample
=
node
.
op
.
subsample
)(
img
,
kern
)
copy_stack_trace
(
node
.
outputs
[
0
],
rval
)
return
[
rval
]
return
[
rval
]
...
@@ -92,10 +94,13 @@ def local_abstractconv_gradweight_gemm(node):
...
@@ -92,10 +94,13 @@ def local_abstractconv_gradweight_gemm(node):
rval
=
CorrMM_gradWeights
(
border_mode
=
node
.
op
.
border_mode
,
rval
=
CorrMM_gradWeights
(
border_mode
=
node
.
op
.
border_mode
,
subsample
=
node
.
op
.
subsample
)(
img
,
topgrad
,
shape
)
subsample
=
node
.
op
.
subsample
)(
img
,
topgrad
,
shape
)
copy_stack_trace
(
node
.
outputs
[
0
],
rval
)
# need to flip the kernel if necessary
# need to flip the kernel if necessary
if
node
.
op
.
filter_flip
:
if
node
.
op
.
filter_flip
:
rval
=
rval
[:,
:,
::
-
1
,
::
-
1
]
rval
=
rval
[:,
:,
::
-
1
,
::
-
1
]
rval
=
theano
.
tensor
.
patternbroadcast
(
rval
,
node
.
outputs
[
0
]
.
broadcastable
)
rval
=
theano
.
tensor
.
patternbroadcast
(
rval
,
node
.
outputs
[
0
]
.
broadcastable
)
copy_stack_trace
(
node
.
outputs
[
0
],
rval
)
return
[
rval
]
return
[
rval
]
...
@@ -117,6 +122,7 @@ def local_abstractconv_gradinputs_gemm(node):
...
@@ -117,6 +122,7 @@ def local_abstractconv_gradinputs_gemm(node):
rval
=
CorrMM_gradInputs
(
border_mode
=
node
.
op
.
border_mode
,
rval
=
CorrMM_gradInputs
(
border_mode
=
node
.
op
.
border_mode
,
subsample
=
node
.
op
.
subsample
)(
kern
,
topgrad
,
subsample
=
node
.
op
.
subsample
)(
kern
,
topgrad
,
shape
)
shape
)
copy_stack_trace
(
node
.
outputs
[
0
],
rval
)
return
[
rval
]
return
[
rval
]
...
@@ -141,6 +147,8 @@ def local_conv2d_cpu(node):
...
@@ -141,6 +147,8 @@ def local_conv2d_cpu(node):
node
.
op
.
imshp
,
node
.
op
.
kshp
,
node
.
op
.
imshp
,
node
.
op
.
kshp
,
border_mode
=
node
.
op
.
border_mode
,
border_mode
=
node
.
op
.
border_mode
,
subsample
=
node
.
op
.
subsample
)
subsample
=
node
.
op
.
subsample
)
copy_stack_trace
(
node
.
outputs
[
0
],
rval
)
return
[
rval
]
return
[
rval
]
...
@@ -175,12 +183,14 @@ def local_conv2d_gradweight_cpu(node):
...
@@ -175,12 +183,14 @@ def local_conv2d_gradweight_cpu(node):
shape
[
0
],
shape
[
1
],
1
,
shape
[
0
],
shape
[
1
],
1
,
shuffled_img
.
shape
[
4
]),
shuffled_img
.
shape
[
4
]),
dCdH
=
shuffled_topgrad
)
dCdH
=
shuffled_topgrad
)
copy_stack_trace
(
node
.
outputs
[
0
],
rval
)
rval
=
theano
.
tensor
.
addbroadcast
(
rval
,
3
)
rval
=
theano
.
tensor
.
addbroadcast
(
rval
,
3
)
rval
=
rval
.
dimshuffle
(
0
,
4
,
1
,
2
)
rval
=
rval
.
dimshuffle
(
0
,
4
,
1
,
2
)
rval
=
rval
[:,
:,
::
-
1
,
::
-
1
]
rval
=
rval
[:,
:,
::
-
1
,
::
-
1
]
rval
=
theano
.
tensor
.
patternbroadcast
(
rval
,
rval
=
theano
.
tensor
.
patternbroadcast
(
rval
,
node
.
outputs
[
0
]
.
broadcastable
)
node
.
outputs
[
0
]
.
broadcastable
)
copy_stack_trace
(
node
.
outputs
[
0
],
rval
)
return
[
rval
]
return
[
rval
]
dx
,
dy
=
node
.
op
.
subsample
dx
,
dy
=
node
.
op
.
subsample
...
@@ -246,11 +256,15 @@ def local_conv2d_gradweight_cpu(node):
...
@@ -246,11 +256,15 @@ def local_conv2d_gradweight_cpu(node):
kshp_logical_top_aligned
=
kshp_logical_top_aligned
,
kshp_logical_top_aligned
=
kshp_logical_top_aligned
,
direction_hint
=
'bprop weights'
)
direction_hint
=
'bprop weights'
)
res
=
dw
(
img
,
filters
)
res
=
dw
(
img
,
filters
)
copy_stack_trace
(
node
.
outputs
[
0
],
res
)
if
node
.
op
.
border_mode
==
'valid'
:
if
node
.
op
.
border_mode
==
'valid'
:
res
=
res
.
dimshuffle
((
1
,
0
,
2
,
3
))
res
=
res
.
dimshuffle
((
1
,
0
,
2
,
3
))
res
=
res
[:,
:,
::
-
1
,
::
-
1
]
res
=
res
[:,
:,
::
-
1
,
::
-
1
]
res
=
theano
.
tensor
.
patternbroadcast
(
res
,
node
.
outputs
[
0
]
.
broadcastable
)
res
=
theano
.
tensor
.
patternbroadcast
(
res
,
node
.
outputs
[
0
]
.
broadcastable
)
copy_stack_trace
(
node
.
outputs
[
0
],
res
)
return
[
res
]
return
[
res
]
...
@@ -280,10 +294,13 @@ def local_conv2d_gradinputs_cpu(node):
...
@@ -280,10 +294,13 @@ def local_conv2d_gradinputs_cpu(node):
d
=
(
node
.
op
.
subsample
[
0
],
node
.
op
.
subsample
[
1
],
1
),
d
=
(
node
.
op
.
subsample
[
0
],
node
.
op
.
subsample
[
1
],
1
),
H
=
shuffled_topgrad
,
H
=
shuffled_topgrad
,
RShape
=
(
shape
[
0
],
shape
[
1
],
1
))
RShape
=
(
shape
[
0
],
shape
[
1
],
1
))
copy_stack_trace
(
node
.
outputs
[
0
],
rval
)
rval
=
theano
.
tensor
.
addbroadcast
(
rval
,
3
)
rval
=
theano
.
tensor
.
addbroadcast
(
rval
,
3
)
rval
=
rval
.
dimshuffle
(
0
,
4
,
1
,
2
)
rval
=
rval
.
dimshuffle
(
0
,
4
,
1
,
2
)
rval
=
theano
.
tensor
.
patternbroadcast
(
rval
,
rval
=
theano
.
tensor
.
patternbroadcast
(
rval
,
node
.
outputs
[
0
]
.
broadcastable
)
node
.
outputs
[
0
]
.
broadcastable
)
copy_stack_trace
(
node
.
outputs
[
0
],
rval
)
return
[
rval
]
return
[
rval
]
# Conv2d Implementation
# Conv2d Implementation
...
@@ -332,7 +349,9 @@ def local_conv2d_gradinputs_cpu(node):
...
@@ -332,7 +349,9 @@ def local_conv2d_gradinputs_cpu(node):
version
=-
1
,
version
=-
1
,
direction_hint
=
'bprop inputs'
)
direction_hint
=
'bprop inputs'
)
din
=
din
(
topgrad
,
filters
)
din
=
din
(
topgrad
,
filters
)
copy_stack_trace
(
node
.
outputs
[
0
],
din
)
din
=
theano
.
tensor
.
patternbroadcast
(
din
,
node
.
outputs
[
0
]
.
broadcastable
)
din
=
theano
.
tensor
.
patternbroadcast
(
din
,
node
.
outputs
[
0
]
.
broadcastable
)
copy_stack_trace
(
node
.
outputs
[
0
],
din
)
return
[
din
]
return
[
din
]
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论