Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
289c3bd4
提交
289c3bd4
authored
8月 15, 2016
作者:
Gijs van Tulder
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Introduce AbstractConv3D and related changes.
Add abstract convolution classes, reuse this for 2D and 3D.
上级
d3fb7189
全部展开
隐藏空白字符变更
内嵌
并排
正在显示
5 个修改的文件
包含
120 行增加
和
5 行删除
+120
-5
opt.py
theano/sandbox/cuda/opt.py
+3
-3
__init__.py
theano/tensor/nnet/__init__.py
+1
-0
abstract_conv.py
theano/tensor/nnet/abstract_conv.py
+0
-0
opt.py
theano/tensor/nnet/opt.py
+116
-2
test_abstract_conv.py
theano/tensor/nnet/tests/test_abstract_conv.py
+0
-0
没有找到文件。
theano/sandbox/cuda/opt.py
浏览文件 @
289c3bd4
...
@@ -87,7 +87,7 @@ from theano.tensor import slinalg
...
@@ -87,7 +87,7 @@ from theano.tensor import slinalg
from
theano.tensor.nnet.Conv3D
import
Conv3D
from
theano.tensor.nnet.Conv3D
import
Conv3D
from
theano.tests.breakpoint
import
PdbBreakpoint
from
theano.tests.breakpoint
import
PdbBreakpoint
from
theano.tensor.nnet.abstract_conv
import
(
BaseAbstractConv
2d
,
from
theano.tensor.nnet.abstract_conv
import
(
BaseAbstractConv
,
AbstractConv2d
,
AbstractConv2d
,
AbstractConv2d_gradWeights
,
AbstractConv2d_gradWeights
,
AbstractConv2d_gradInputs
)
AbstractConv2d_gradInputs
)
...
@@ -2736,7 +2736,7 @@ def local_conv2d_gpu_conv(node):
...
@@ -2736,7 +2736,7 @@ def local_conv2d_gpu_conv(node):
if
isinstance
(
node
.
op
,
GpuFromHost
):
if
isinstance
(
node
.
op
,
GpuFromHost
):
host_input
=
node
.
inputs
[
0
]
host_input
=
node
.
inputs
[
0
]
if
host_input
.
owner
and
isinstance
(
host_input
.
owner
.
op
,
if
host_input
.
owner
and
isinstance
(
host_input
.
owner
.
op
,
BaseAbstractConv
2d
):
BaseAbstractConv
):
conv
=
host_input
.
owner
.
op
conv
=
host_input
.
owner
.
op
inps
=
list
(
host_input
.
owner
.
inputs
)
inps
=
list
(
host_input
.
owner
.
inputs
)
...
@@ -2749,7 +2749,7 @@ def local_conv2d_gpu_conv(node):
...
@@ -2749,7 +2749,7 @@ def local_conv2d_gpu_conv(node):
out
.
tag
.
values_eq_approx
=
values_eq_approx_high_tol
out
.
tag
.
values_eq_approx
=
values_eq_approx_high_tol
return
[
out
]
return
[
out
]
if
isinstance
(
node
.
op
,
BaseAbstractConv
2d
):
if
isinstance
(
node
.
op
,
BaseAbstractConv
):
# conv(host_from_gpu) -> host_from_gpu(gpu_conv)
# conv(host_from_gpu) -> host_from_gpu(gpu_conv)
inp1
=
node
.
inputs
[
0
]
inp1
=
node
.
inputs
[
0
]
inp2
=
node
.
inputs
[
1
]
inp2
=
node
.
inputs
[
1
]
...
...
theano/tensor/nnet/__init__.py
浏览文件 @
289c3bd4
...
@@ -32,6 +32,7 @@ from .bn import batch_normalization
...
@@ -32,6 +32,7 @@ from .bn import batch_normalization
import
warnings
import
warnings
from
.abstract_conv
import
conv2d
as
abstract_conv2d
from
.abstract_conv
import
conv2d
as
abstract_conv2d
from
.abstract_conv
import
conv3d
as
abstract_conv3d
def
conv2d
(
input
,
filters
,
input_shape
=
None
,
filter_shape
=
None
,
def
conv2d
(
input
,
filters
,
input_shape
=
None
,
filter_shape
=
None
,
...
...
theano/tensor/nnet/abstract_conv.py
浏览文件 @
289c3bd4
差异被折叠。
点击展开。
theano/tensor/nnet/opt.py
浏览文件 @
289c3bd4
...
@@ -18,6 +18,9 @@ from theano.tensor.nnet.blocksparse import (
...
@@ -18,6 +18,9 @@ from theano.tensor.nnet.blocksparse import (
from
theano.tensor.nnet.abstract_conv
import
(
AbstractConv2d
,
from
theano.tensor.nnet.abstract_conv
import
(
AbstractConv2d
,
AbstractConv2d_gradWeights
,
AbstractConv2d_gradWeights
,
AbstractConv2d_gradInputs
)
AbstractConv2d_gradInputs
)
from
theano.tensor.nnet.abstract_conv
import
(
AbstractConv3d
,
AbstractConv3d_gradWeights
,
AbstractConv3d_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
register_specialize_device
from
theano.tensor
import
TensorType
from
theano.tensor
import
TensorType
...
@@ -25,6 +28,7 @@ from theano.tensor import opt
...
@@ -25,6 +28,7 @@ from theano.tensor import opt
# Cpu implementation
# Cpu implementation
from
theano.tensor.nnet.conv
import
conv2d
,
ConvOp
from
theano.tensor.nnet.conv
import
conv2d
,
ConvOp
from
theano.tensor.nnet.Conv3D
import
conv3D
from
theano.tensor.nnet.ConvGrad3D
import
convGrad3D
from
theano.tensor.nnet.ConvGrad3D
import
convGrad3D
from
theano.tensor.nnet.ConvTransp3D
import
convTransp3D
from
theano.tensor.nnet.ConvTransp3D
import
convTransp3D
...
@@ -159,6 +163,37 @@ def local_conv2d_cpu(node):
...
@@ -159,6 +163,37 @@ def local_conv2d_cpu(node):
return
[
rval
]
return
[
rval
]
@local_optimizer
([
AbstractConv3d
])
def
local_conv3d_cpu
(
node
):
if
not
isinstance
(
node
.
op
,
AbstractConv3d
):
return
None
img
,
kern
=
node
.
inputs
if
((
not
isinstance
(
img
.
type
,
TensorType
)
or
not
isinstance
(
kern
.
type
,
TensorType
))):
return
None
if
node
.
op
.
border_mode
not
in
[
'valid'
,
(
0
,
0
,
0
)]:
return
None
if
node
.
op
.
filter_dilation
!=
(
1
,
1
,
1
):
return
None
bias
=
theano
.
tensor
.
zeros_like
(
kern
[:,
0
,
0
,
0
,
0
])
# need to flip the kernel if necessary (conv3D does not flip)
if
node
.
op
.
filter_flip
:
kern
=
kern
[:,
:,
::
-
1
,
::
-
1
,
::
-
1
]
# conv3D expects shape (batch, row, column, time, channel)
img
=
img
.
dimshuffle
(
0
,
2
,
3
,
4
,
1
)
kern
=
kern
.
dimshuffle
(
0
,
2
,
3
,
4
,
1
)
rval
=
conv3D
(
img
,
kern
,
bias
,
node
.
op
.
subsample
)
copy_stack_trace
(
node
.
outputs
[
0
],
rval
)
rval
=
rval
.
dimshuffle
(
0
,
4
,
1
,
2
,
3
)
return
[
rval
]
@local_optimizer
([
AbstractConv2d_gradWeights
])
@local_optimizer
([
AbstractConv2d_gradWeights
])
def
local_conv2d_gradweight_cpu
(
node
):
def
local_conv2d_gradweight_cpu
(
node
):
if
not
isinstance
(
node
.
op
,
AbstractConv2d_gradWeights
):
if
not
isinstance
(
node
.
op
,
AbstractConv2d_gradWeights
):
...
@@ -277,6 +312,39 @@ def local_conv2d_gradweight_cpu(node):
...
@@ -277,6 +312,39 @@ def local_conv2d_gradweight_cpu(node):
return
[
res
]
return
[
res
]
@local_optimizer
([
AbstractConv3d_gradWeights
])
def
local_conv3d_gradweight_cpu
(
node
):
if
not
isinstance
(
node
.
op
,
AbstractConv3d_gradWeights
):
return
None
img
,
topgrad
,
shape
=
node
.
inputs
if
((
not
isinstance
(
img
.
type
,
TensorType
)
or
not
isinstance
(
topgrad
.
type
,
TensorType
))):
return
None
if
node
.
op
.
border_mode
not
in
[
'valid'
,
(
0
,
0
,
0
)]:
return
None
if
node
.
op
.
filter_dilation
!=
(
1
,
1
,
1
):
return
None
# conv3D expects shape (batch, row, column, time, channel)
img
=
img
.
dimshuffle
(
0
,
2
,
3
,
4
,
1
)
topgrad
=
topgrad
.
dimshuffle
(
0
,
2
,
3
,
4
,
1
)
W_shape
=
(
topgrad
.
shape
[
4
],
shape
[
0
],
shape
[
1
],
shape
[
2
],
img
.
shape
[
4
])
rval
=
convGrad3D
(
img
,
node
.
op
.
subsample
,
W_shape
,
topgrad
)
copy_stack_trace
(
node
.
outputs
[
0
],
rval
)
rval
=
rval
.
dimshuffle
(
0
,
4
,
1
,
2
,
3
)
# need to flip the kernel if necessary (conv3D does not flip)
if
node
.
op
.
filter_flip
:
rval
=
rval
[:,
:,
::
-
1
,
::
-
1
,
::
-
1
]
rval
=
theano
.
tensor
.
patternbroadcast
(
rval
,
node
.
outputs
[
0
]
.
broadcastable
)
return
[
rval
]
@local_optimizer
([
AbstractConv2d_gradInputs
])
@local_optimizer
([
AbstractConv2d_gradInputs
])
def
local_conv2d_gradinputs_cpu
(
node
):
def
local_conv2d_gradinputs_cpu
(
node
):
if
not
isinstance
(
node
.
op
,
AbstractConv2d_gradInputs
):
if
not
isinstance
(
node
.
op
,
AbstractConv2d_gradInputs
):
...
@@ -366,6 +434,38 @@ def local_conv2d_gradinputs_cpu(node):
...
@@ -366,6 +434,38 @@ def local_conv2d_gradinputs_cpu(node):
return
[
din
]
return
[
din
]
@local_optimizer
([
AbstractConv3d_gradInputs
])
def
local_conv3d_gradinputs_cpu
(
node
):
if
not
isinstance
(
node
.
op
,
AbstractConv3d_gradInputs
):
return
None
kern
,
topgrad
,
shape
=
node
.
inputs
if
((
not
isinstance
(
kern
.
type
,
TensorType
)
or
not
isinstance
(
topgrad
.
type
,
TensorType
))):
return
None
if
node
.
op
.
border_mode
not
in
[
'valid'
,
(
0
,
0
,
0
)]:
return
None
if
node
.
op
.
filter_dilation
!=
(
1
,
1
,
1
):
return
None
# need to flip the kernel if necessary (conv3D does not flip)
if
node
.
op
.
filter_flip
:
kern
=
kern
[:,
:,
::
-
1
,
::
-
1
,
::
-
1
]
# conv3D expects shape (batch, row, column, time, channel)
kern
=
kern
.
dimshuffle
(
0
,
2
,
3
,
4
,
1
)
topgrad
=
topgrad
.
dimshuffle
(
0
,
2
,
3
,
4
,
1
)
bias
=
theano
.
tensor
.
zeros_like
(
kern
[
0
,
0
,
0
,
0
,
:])
rval
=
convTransp3D
(
kern
,
bias
,
node
.
op
.
subsample
,
topgrad
,
shape
)
copy_stack_trace
(
node
.
outputs
[
0
],
rval
)
rval
=
rval
.
dimshuffle
(
0
,
4
,
1
,
2
,
3
)
rval
=
theano
.
tensor
.
patternbroadcast
(
rval
,
node
.
outputs
[
0
]
.
broadcastable
)
return
[
rval
]
# Register Cpu Optmization
# Register Cpu Optmization
conv_groupopt
=
theano
.
gof
.
optdb
.
LocalGroupDB
()
conv_groupopt
=
theano
.
gof
.
optdb
.
LocalGroupDB
()
conv_groupopt
.
__name__
=
"conv_opts"
conv_groupopt
.
__name__
=
"conv_opts"
...
@@ -390,16 +490,30 @@ conv_groupopt.register('local_conv2d_gradweight_cpu',
...
@@ -390,16 +490,30 @@ conv_groupopt.register('local_conv2d_gradweight_cpu',
conv_groupopt
.
register
(
'local_conv2d_gradinputs_cpu'
,
conv_groupopt
.
register
(
'local_conv2d_gradinputs_cpu'
,
local_conv2d_gradinputs_cpu
,
40
,
local_conv2d_gradinputs_cpu
,
40
,
'fast_compile'
,
'fast_run'
)
'fast_compile'
,
'fast_run'
)
conv_groupopt
.
register
(
'local_conv3d_cpu'
,
local_conv3d_cpu
,
40
,
'fast_compile'
,
'fast_run'
)
conv_groupopt
.
register
(
'local_conv3d_gradweight_cpu'
,
local_conv3d_gradweight_cpu
,
40
,
'fast_compile'
,
'fast_run'
)
conv_groupopt
.
register
(
'local_conv3d_gradinputs_cpu'
,
local_conv3d_gradinputs_cpu
,
40
,
'fast_compile'
,
'fast_run'
)
# Verify that no AbstractConv are present in the graph
# Verify that no AbstractConv are present in the graph
@local_optimizer
([
AbstractConv2d
,
@local_optimizer
([
AbstractConv2d
,
AbstractConv2d_gradWeights
,
AbstractConv2d_gradWeights
,
AbstractConv2d_gradInputs
])
AbstractConv2d_gradInputs
,
AbstractConv3d
,
AbstractConv3d_gradWeights
,
AbstractConv3d_gradInputs
])
def
local_abstractconv_check
(
node
):
def
local_abstractconv_check
(
node
):
if
isinstance
(
node
.
op
,
(
AbstractConv2d
,
if
isinstance
(
node
.
op
,
(
AbstractConv2d
,
AbstractConv2d_gradWeights
,
AbstractConv2d_gradWeights
,
AbstractConv2d_gradInputs
)):
AbstractConv2d_gradInputs
,
AbstractConv3d
,
AbstractConv3d_gradWeights
,
AbstractConv3d_gradInputs
)):
raise
AssertionError
(
raise
AssertionError
(
'
%
s Theano optimization failed: there is no implementation '
'
%
s Theano optimization failed: there is no implementation '
'available supporting the requested options. Did you exclude '
'available supporting the requested options. Did you exclude '
...
...
theano/tensor/nnet/tests/test_abstract_conv.py
浏览文件 @
289c3bd4
差异被折叠。
点击展开。
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论