Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
5ae986b1
提交
5ae986b1
authored
8月 27, 2017
作者:
Vikram
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Documentation suggestions implemented
上级
444f7d56
隐藏空白字符变更
内嵌
并排
正在显示
5 个修改的文件
包含
82 行增加
和
74 行删除
+82
-74
dnn.py
theano/gpuarray/dnn.py
+5
-0
__init__.py
theano/tensor/nnet/__init__.py
+6
-12
abstract_conv.py
theano/tensor/nnet/abstract_conv.py
+67
-58
corr.py
theano/tensor/nnet/corr.py
+1
-1
test_abstract_conv.py
theano/tensor/nnet/tests/test_abstract_conv.py
+3
-3
没有找到文件。
theano/gpuarray/dnn.py
浏览文件 @
5ae986b1
...
@@ -3039,6 +3039,7 @@ def local_abstractconv_cudnn_graph(op, context_name, inputs, outputs):
...
@@ -3039,6 +3039,7 @@ def local_abstractconv_cudnn_graph(op, context_name, inputs, outputs):
return
None
return
None
if
isinstance
(
op
.
border_mode
,
tuple
)
and
any
(
isinstance
(
p
,
tuple
)
for
p
in
op
.
border_mode
):
if
isinstance
(
op
.
border_mode
,
tuple
)
and
any
(
isinstance
(
p
,
tuple
)
for
p
in
op
.
border_mode
):
# Asymmetric padding not yet supported
return
None
return
None
inp1
=
inputs
[
0
]
inp1
=
inputs
[
0
]
...
@@ -3138,6 +3139,7 @@ def local_abstractconv_cudnn(node):
...
@@ -3138,6 +3139,7 @@ def local_abstractconv_cudnn(node):
if
node
.
op
.
unshared
:
if
node
.
op
.
unshared
:
return
None
return
None
if
isinstance
(
node
.
op
.
border_mode
,
tuple
)
and
any
(
isinstance
(
p
,
tuple
)
for
p
in
node
.
op
.
border_mode
):
if
isinstance
(
node
.
op
.
border_mode
,
tuple
)
and
any
(
isinstance
(
p
,
tuple
)
for
p
in
node
.
op
.
border_mode
):
# Asymmetric padding not yet supported
return
None
return
None
if
isinstance
(
node
.
op
,
AbstractConv2d
):
if
isinstance
(
node
.
op
,
AbstractConv2d
):
return
local_abstractconv_cudnn_graph
(
node
.
op
,
ctx
,
node
.
inputs
,
node
.
outputs
)
return
local_abstractconv_cudnn_graph
(
node
.
op
,
ctx
,
node
.
inputs
,
node
.
outputs
)
...
@@ -3156,6 +3158,7 @@ def local_abstractconv_cudnn_alt(node):
...
@@ -3156,6 +3158,7 @@ def local_abstractconv_cudnn_alt(node):
if
node
.
op
.
unshared
:
if
node
.
op
.
unshared
:
return
None
return
None
if
isinstance
(
node
.
op
.
border_mode
,
tuple
)
and
any
(
isinstance
(
p
,
tuple
)
for
p
in
node
.
op
.
border_mode
):
if
isinstance
(
node
.
op
.
border_mode
,
tuple
)
and
any
(
isinstance
(
p
,
tuple
)
for
p
in
node
.
op
.
border_mode
):
# Asymmetric padding not yet supported
return
None
return
None
inp1
=
node
.
inputs
[
0
]
inp1
=
node
.
inputs
[
0
]
inp2
=
node
.
inputs
[
1
]
inp2
=
node
.
inputs
[
1
]
...
@@ -3366,6 +3369,7 @@ def local_abstractconv_gw_cudnn(node):
...
@@ -3366,6 +3369,7 @@ def local_abstractconv_gw_cudnn(node):
if
node
.
op
.
unshared
:
if
node
.
op
.
unshared
:
return
None
return
None
if
isinstance
(
node
.
op
.
border_mode
,
tuple
)
and
any
(
isinstance
(
p
,
tuple
)
for
p
in
node
.
op
.
border_mode
):
if
isinstance
(
node
.
op
.
border_mode
,
tuple
)
and
any
(
isinstance
(
p
,
tuple
)
for
p
in
node
.
op
.
border_mode
):
# Asymmetric padding not yet supported
return
None
return
None
if
isinstance
(
node
.
op
,
AbstractConv2d_gradWeights
):
if
isinstance
(
node
.
op
,
AbstractConv2d_gradWeights
):
return
local_abstractconv_cudnn_graph
(
node
.
op
,
ctx
,
node
.
inputs
,
node
.
outputs
)
return
local_abstractconv_cudnn_graph
(
node
.
op
,
ctx
,
node
.
inputs
,
node
.
outputs
)
...
@@ -3381,6 +3385,7 @@ def local_abstractconv_gi_cudnn(node):
...
@@ -3381,6 +3385,7 @@ def local_abstractconv_gi_cudnn(node):
if
node
.
op
.
unshared
:
if
node
.
op
.
unshared
:
return
None
return
None
if
isinstance
(
node
.
op
.
border_mode
,
tuple
)
and
any
(
isinstance
(
p
,
tuple
)
for
p
in
node
.
op
.
border_mode
):
if
isinstance
(
node
.
op
.
border_mode
,
tuple
)
and
any
(
isinstance
(
p
,
tuple
)
for
p
in
node
.
op
.
border_mode
):
# Asymmetric padding not yet supported
return
None
return
None
if
isinstance
(
node
.
op
,
AbstractConv2d_gradInputs
):
if
isinstance
(
node
.
op
,
AbstractConv2d_gradInputs
):
return
local_abstractconv_cudnn_graph
(
node
.
op
,
ctx
,
node
.
inputs
,
node
.
outputs
)
return
local_abstractconv_cudnn_graph
(
node
.
op
,
ctx
,
node
.
inputs
,
node
.
outputs
)
...
...
theano/tensor/nnet/__init__.py
浏览文件 @
5ae986b1
...
@@ -72,18 +72,17 @@ def conv2d(input, filters, input_shape=None, filter_shape=None,
...
@@ -72,18 +72,17 @@ def conv2d(input, filters, input_shape=None, filter_shape=None,
You can give ``None`` for any element of the list to specify that this
You can give ``None`` for any element of the list to specify that this
element is not known at compile time.
element is not known at compile time.
border_mode: str, int or tuple of ``convdim`` elements where each element
border_mode: str, int or a tuple of two ints or pairs of ints
is an integer or a tuple of length 2.
Either of the following:
Either of the following:
``'valid'``: apply filter wherever it completely overlaps with the
``'valid'``: apply filter wherever it completely overlaps with the
input. Generates output of shape: input shape - filter shape + 1
input. Generates output of shape: input shape - filter shape + 1
``'full'``: apply filter wherever it partly overlaps with the input.
``'full'``: apply filter wherever it partly overlaps with the input.
Generates output of shape: input shape + filter shape - 1
Generates output of shape: input shape + filter shape - 1
``'half'``: pad input with a symmetric border of ``filter
size
// 2``
``'half'``: pad input with a symmetric border of ``filter
rows
// 2``
in each convolution dimension, then perform a valid convolution.
rows and ``filter columns // 2`` columns, then perform a valid
For filters with an odd filter size, this leads to the output
convolution. For filters with an odd number of rows and columns, this
shape being equal to the input shape.
leads to the output
shape being equal to the input shape.
``int``: pad input with a symmetric border of zeros of the given
``int``: pad input with a symmetric border of zeros of the given
width, then perform a valid convolution.
width, then perform a valid convolution.
``(int1, int2)``: (for 2D) pad input with a symmetric border of ``int1``,
``(int1, int2)``: (for 2D) pad input with a symmetric border of ``int1``,
...
@@ -91,11 +90,6 @@ def conv2d(input, filters, input_shape=None, filter_shape=None,
...
@@ -91,11 +90,6 @@ def conv2d(input, filters, input_shape=None, filter_shape=None,
``(int1, (int2, int3))`` or ``((int1, int2), int3)``: (for 2D)
``(int1, (int2, int3))`` or ``((int1, int2), int3)``: (for 2D)
pad input with one symmetric border of `int1`` or ``int3``, and
pad input with one symmetric border of `int1`` or ``int3``, and
one asymmetric border of ``(int2, int3)`` or ``(int1, int2)``.
one asymmetric border of ``(int2, int3)`` or ``(int1, int2)``.
``((int1, int2), (int3, int4))``: (for 2D) pad input with an asymmetric
border of ``(int1, int2)`` along one dimension and ``(int3, int4)``
along the second dimension.
``(int1, int2, int3)``: (for 3D) pad input with a symmetric border of
``int1``, ``int2`` and ``int3``, then perform a valid convolution.
subsample: tuple of len 2
subsample: tuple of len 2
Factor by which to subsample the output.
Factor by which to subsample the output.
...
@@ -208,7 +202,7 @@ def conv2d_transpose(input, filters, output_shape, filter_shape=None,
...
@@ -208,7 +202,7 @@ def conv2d_transpose(input, filters, output_shape, filter_shape=None,
You can give ``None`` for any element of the list to specify that this
You can give ``None`` for any element of the list to specify that this
element is not known at compile time.
element is not known at compile time.
border_mode: str, int or tuple of two
elements
border_mode: str, int or tuple of two
int
Refers to the ``border_mode`` argument of the corresponding forward
Refers to the ``border_mode`` argument of the corresponding forward
(non-transposed) convolution. See the argument description in
(non-transposed) convolution. See the argument description in
``conv2d``. What was ``padding`` for the forward convolution means
``conv2d``. What was ``padding`` for the forward convolution means
...
...
theano/tensor/nnet/abstract_conv.py
浏览文件 @
5ae986b1
...
@@ -52,11 +52,11 @@ def get_conv_output_shape(image_shape, kernel_shape,
...
@@ -52,11 +52,11 @@ def get_conv_output_shape(image_shape, kernel_shape,
number of output channels, height and width of the output, number of
number of output channels, height and width of the output, number of
input channels, height and width of the kernel.
input channels, height and width of the kernel.
None where undefined.
None where undefined.
border_mode: string, int (symbolic or numeric) or tuple of int (symbolic
border_mode: string, int (symbolic or numeric) or tuple of int (symbolic
or numeric)
. If it is a string, it must be 'valid', 'half' or 'full'.
or numeric)
or pairs of ints. If it is a string, it must be 'valid',
If it is a tuple, its two (or three) elements respectively correspond
'half' or 'full'. If it is a tuple, its two (or three) elements respectively
to the padding (possibly left and right) on height and width
correspond to the padding on height and width (and possibly depth)
(and possibly depth) axis
.
axis. For asymmetric padding, provide a pair of ints for each dimension
.
subsample: tuple of int (symbolic or numeric). Its two or three elements
subsample: tuple of int (symbolic or numeric). Its two or three elements
espectively correspond to the subsampling on height and width (and
espectively correspond to the subsampling on height and width (and
possibly depth) axis.
possibly depth) axis.
...
@@ -104,10 +104,11 @@ def get_conv_shape_1axis(image_shape, kernel_shape, border_mode,
...
@@ -104,10 +104,11 @@ def get_conv_shape_1axis(image_shape, kernel_shape, border_mode,
given axis. None if undefined.
given axis. None if undefined.
kernel_shape: int or None. Corresponds to the kernel shape on a given
kernel_shape: int or None. Corresponds to the kernel shape on a given
axis. None if undefined.
axis. None if undefined.
border_mode: string, int or tuple. If it is a string, it must be
border_mode: string, int or tuple
of 2 ints
. If it is a string, it must be
'valid', 'half' or 'full'. If it is an integer, it must correspond to
'valid', 'half' or 'full'. If it is an integer, it must correspond to
the padding on the considered axis. If it is a tuple, its two elements
the padding on the considered axis. If it is a tuple, its two elements
must correspond to the padding (left and right) on the desired axis.
must correspond to the asymmetric padding (e.g., left and right) on
the considered axis.
subsample: int. It must correspond to the subsampling on the
subsample: int. It must correspond to the subsampling on the
considered axis.
considered axis.
dilation: int. It must correspond to the dilation on the
dilation: int. It must correspond to the dilation on the
...
@@ -173,11 +174,11 @@ def get_conv_gradweights_shape(image_shape, top_shape,
...
@@ -173,11 +174,11 @@ def get_conv_gradweights_shape(image_shape, top_shape,
image shape. Its four (or five) element must correspond respectively
image shape. Its four (or five) element must correspond respectively
to: batch size, number of output channels, height and width (and
to: batch size, number of output channels, height and width (and
possibly depth) of the image. None where undefined.
possibly depth) of the image. None where undefined.
border_mode: string, int (symbolic or numeric) or tuple of int (symbolic
border_mode: string, int (symbolic or numeric) or tuple of int (symbolic
or numeric)
. If it is a string, it must be 'valid', 'half' or 'full'.
or numeric)
or pairs of ints. If it is a string, it must be 'valid',
If it is a tuple, its two (or three) elements respectively correspond
'half' or 'full'. If it is a tuple, its two (or three) elements respectively
to the padding (possibly left and right) on height and width
correspond to the padding on height and width (and possibly depth)
(and possibly depth) axis
.
axis. For asymmetric padding, provide a pair of ints for each dimension
.
subsample: tuple of int (symbolic or numeric). Its two or three elements
subsample: tuple of int (symbolic or numeric). Its two or three elements
respectively correspond to the subsampling on height and width (and
respectively correspond to the subsampling on height and width (and
possibly depth) axis.
possibly depth) axis.
...
@@ -234,10 +235,11 @@ def get_conv_gradweights_shape_1axis(image_shape, top_shape, border_mode,
...
@@ -234,10 +235,11 @@ def get_conv_gradweights_shape_1axis(image_shape, top_shape, border_mode,
given axis. None if undefined.
given axis. None if undefined.
top_shape: int or None. Corresponds to the top shape on a given axis.
top_shape: int or None. Corresponds to the top shape on a given axis.
None if undefined.
None if undefined.
border_mode: string, int or tuple. If it is a string, it must be
border_mode: string, int or tuple
of 2 ints
. If it is a string, it must be
'valid', 'half' or 'full'. If it is an integer, it must correspond to
'valid', 'half' or 'full'. If it is an integer, it must correspond to
the padding on the considered axis. If it is a tuple, its two elements
the padding on the considered axis. If it is a tuple, its two elements
must correspond to the padding (left and right) on the desired axis.
must correspond to the asymmetric padding (e.g., left and right) on
the considered axis.
subsample: int. It must correspond to the subsampling on the
subsample: int. It must correspond to the subsampling on the
considered axis.
considered axis.
dilation: int. It must correspond to the dilation on the
dilation: int. It must correspond to the dilation on the
...
@@ -296,11 +298,11 @@ def get_conv_gradinputs_shape(kernel_shape, top_shape,
...
@@ -296,11 +298,11 @@ def get_conv_gradinputs_shape(kernel_shape, top_shape,
image shape. Its four (or five) element must correspond respectively
image shape. Its four (or five) element must correspond respectively
to: batch size, number of output channels, height and width (and
to: batch size, number of output channels, height and width (and
possibly depth) of the image. None where undefined.
possibly depth) of the image. None where undefined.
border_mode: string, int (symbolic or numeric) or tuple of int (symbolic
border_mode: string, int (symbolic or numeric) or tuple of int (symbolic
or numeric)
. If it is a string, it must be 'valid', 'half' or 'full'.
or numeric)
or pairs of ints. If it is a string, it must be 'valid',
If it is a tuple, its two (or three) elements respectively correspond
'half' or 'full'. If it is a tuple, its two (or three) elements respectively
to the padding (possibly left and right) on height and width
correspond to the padding on height and width (and possibly depth)
(and possibly depth) axis
.
axis. For asymmetric padding, provide a pair of ints for each dimension
.
subsample: tuple of int (symbolic or numeric). Its two or three elements
subsample: tuple of int (symbolic or numeric). Its two or three elements
respectively correspond to the subsampling on height and width (and
respectively correspond to the subsampling on height and width (and
possibly depth) axis.
possibly depth) axis.
...
@@ -354,10 +356,11 @@ def get_conv_gradinputs_shape_1axis(kernel_shape, top_shape, border_mode,
...
@@ -354,10 +356,11 @@ def get_conv_gradinputs_shape_1axis(kernel_shape, top_shape, border_mode,
axis. None if undefined.
axis. None if undefined.
top_shape: int or None. Corresponds to the top shape on a given axis.
top_shape: int or None. Corresponds to the top shape on a given axis.
None if undefined.
None if undefined.
border_mode: string, int or tuple. If it is a string, it must be
border_mode: string, int or tuple
of 2 ints
. If it is a string, it must be
'valid', 'half' or 'full'. If it is an integer, it must correspond to
'valid', 'half' or 'full'. If it is an integer, it must correspond to
the padding on the considered axis. If it is a tuple, its two elements
the padding on the considered axis. If it is a tuple, its two elements
must correspond to the padding (left and right) on the desired axis.
must correspond to the asymmetric padding (e.g., left and right) on
the considered axis.
subsample: int. It must correspond to the subsampling on the
subsample: int. It must correspond to the subsampling on the
considered axis.
considered axis.
dilation: int. It must correspond to the dilation on the
dilation: int. It must correspond to the dilation on the
...
@@ -423,11 +426,11 @@ def check_conv_gradinputs_shape(image_shape, kernel_shape, output_shape,
...
@@ -423,11 +426,11 @@ def check_conv_gradinputs_shape(image_shape, kernel_shape, output_shape,
output shape. Its four (or five) elements must correspond respectively
output shape. Its four (or five) elements must correspond respectively
to: batch size, number of output channels, height and width
to: batch size, number of output channels, height and width
(and possibly depth) of the output. None where undefined.
(and possibly depth) of the output. None where undefined.
border_mode: string, int (symbolic or numeric) or tuple where each element
border_mode: string, int (symbolic or numeric) or tuple of int (symbolic
is either an int or a tuple of length 2 (symbolic or numeric).
or numeric) or pairs of ints. If it is a string, it must be 'valid',
If it is a string, it must be 'valid', 'half' or 'full'.
'half' or 'full'. If it is a tuple, its two (or three) elements respectively
If it is a tuple, its two (or three) elements respectively correspond
correspond to the padding on height and width (and possibly depth)
to the padding on height and width (and possibly depth) axis
.
axis. For asymmetric padding, provide a pair of ints for each dimension
.
subsample: tuple of int (symbolic or numeric). Its two or three elements
subsample: tuple of int (symbolic or numeric). Its two or three elements
respectively correspond to the subsampling on height and width (and
respectively correspond to the subsampling on height and width (and
possibly depth) axis.
possibly depth) axis.
...
@@ -553,8 +556,9 @@ def assert_shape(x, expected_shape, msg='Unexpected shape.'):
...
@@ -553,8 +556,9 @@ def assert_shape(x, expected_shape, msg='Unexpected shape.'):
return
x
return
x
def
mode_to_pad
(
mode
,
convdim
,
kshp
):
def
border_mode_to_pad
(
mode
,
convdim
,
kshp
):
""" Computes a tuple for padding given the border_mode parameter
"""
Computes a tuple for padding given the border_mode parameter
Parameters
Parameters
----------
----------
...
@@ -708,10 +712,10 @@ def separable_conv2d(input,
...
@@ -708,10 +712,10 @@ def separable_conv2d(input,
width, then perform a valid convolution.
width, then perform a valid convolution.
``(int1, int2)``: pad input with a symmetric border of ``int1`` rows
``(int1, int2)``: pad input with a symmetric border of ``int1`` rows
and ``int2`` columns, then perform a valid convolution.
and ``int2`` columns, then perform a valid convolution.
``(int1, (int2, int3))`` or ``((int1, int2), int3)``:
(for 2D)
``(int1, (int2, int3))`` or ``((int1, int2), int3)``:
pad input with one symmetric border of `int1`` or ``int3``, and
pad input with one symmetric border of `int1`` or ``int3``, and
one asymmetric border of ``(int2, int3)`` or ``(int1, int2)``.
one asymmetric border of ``(int2, int3)`` or ``(int1, int2)``.
``((int1, int2), (int3, int4))``:
(for 2D)
pad input with an asymmetric
``((int1, int2), (int3, int4))``: pad input with an asymmetric
border of ``(int1, int2)`` along one dimension and ``(int3, int4)``
border of ``(int1, int2)`` along one dimension and ``(int3, int4)``
along the second dimension.
along the second dimension.
...
@@ -1041,8 +1045,7 @@ def conv2d_grad_wrt_inputs(output_grad,
...
@@ -1041,8 +1045,7 @@ def conv2d_grad_wrt_inputs(output_grad,
Optional, possibly used to choose an optimal implementation.
Optional, possibly used to choose an optimal implementation.
You can give ``None`` for any element of the list to specify that
You can give ``None`` for any element of the list to specify that
this element is not known at compile time.
this element is not known at compile time.
border_mode: str, int or tuple of 2 elements where each element
border_mode: str, int or a tuple of two ints or pairs of ints
is an integer or a tuple of length 2.
Either of the following:
Either of the following:
``'valid'``
``'valid'``
...
@@ -1073,8 +1076,8 @@ def conv2d_grad_wrt_inputs(output_grad,
...
@@ -1073,8 +1076,8 @@ def conv2d_grad_wrt_inputs(output_grad,
pad input with one symmetric border of `int1`` or ``int3``, and
pad input with one symmetric border of `int1`` or ``int3``, and
one asymmetric border of ``(int2, int3)`` or ``(int1, int2)``.
one asymmetric border of ``(int2, int3)`` or ``(int1, int2)``.
``((int1, int2), (int3, int4))``
: (for 2D) pad input with an asymmetric
``((int1, int2), (int3, int4))``
border of ``(int1, int2)`` along one dimension and ``(int3, int4)``
pad input with an asymmetric
border of ``(int1, int2)`` along one dimension and ``(int3, int4)``
along the second dimension.
along the second dimension.
subsample : tuple of len 2
subsample : tuple of len 2
...
@@ -1336,8 +1339,7 @@ def conv2d_grad_wrt_weights(input,
...
@@ -1336,8 +1339,7 @@ def conv2d_grad_wrt_weights(input,
Optional, possibly used to choose an optimal implementation.
Optional, possibly used to choose an optimal implementation.
You can give ``None`` for any element of the list to specify
You can give ``None`` for any element of the list to specify
that this element is not known at compile time.
that this element is not known at compile time.
border_mode: str, int or tuple of 2 elements where each element
border_mode: str, int or a tuple of two ints or pairs of ints
is an integer or a tuple of length 2.
Either of the following:
Either of the following:
``'valid'``
``'valid'``
...
@@ -1368,9 +1370,9 @@ def conv2d_grad_wrt_weights(input,
...
@@ -1368,9 +1370,9 @@ def conv2d_grad_wrt_weights(input,
pad input with one symmetric border of `int1`` or ``int3``, and
pad input with one symmetric border of `int1`` or ``int3``, and
one asymmetric border of ``(int2, int3)`` or ``(int1, int2)``.
one asymmetric border of ``(int2, int3)`` or ``(int1, int2)``.
``((int1, int2), (int3, int4))``
: (for 2D) pad input with an asymmetric
``((int1, int2), (int3, int4))``
border of ``(int1, int2)`` along one dimension and ``(int3, int4)``
pad input with an asymmetric border of ``(int1, int2)`` along
along the second dimension.
one dimension and ``(int3, int4)``
along the second dimension.
subsample : tuple of len 2
subsample : tuple of len 2
The subsampling used in the forward pass of the convolutional
The subsampling used in the forward pass of the convolutional
operation. Also called strides elsewhere.
operation. Also called strides elsewhere.
...
@@ -1584,16 +1586,17 @@ def conv3d_grad_wrt_weights(input,
...
@@ -1584,16 +1586,17 @@ def conv3d_grad_wrt_weights(input,
return
gradWeight_op
(
input
,
output_grad
,
filter_shape
[
-
3
:])
return
gradWeight_op
(
input
,
output_grad
,
filter_shape
[
-
3
:])
def
causal_conv
(
input
,
def
causal_conv1d
(
input
,
filters
,
filters
,
filter_shape
,
filter_shape
,
input_shape
=
None
,
input_shape
=
None
,
subsample
=
1
,
subsample
=
1
,
filter_flip
=
True
,
filter_flip
=
True
,
filter_dilation
=
1
,
filter_dilation
=
1
,
num_groups
=
1
,
num_groups
=
1
,
unshared
=
False
):
unshared
=
False
):
"""Computes (dilated) causal convolution
"""
Computes (dilated) causal convolution
The output at time t depends only on the inputs till t-1. Used for
The output at time t depends only on the inputs till t-1. Used for
modelling temporal data.
modelling temporal data.
...
@@ -1629,7 +1632,7 @@ def causal_conv(input,
...
@@ -1629,7 +1632,7 @@ def causal_conv(input,
num_groups : int
num_groups : int
Divides the image, kernel and output tensors into num_groups
Divides the image, kernel and output tensors into num_groups
separate groups. Each which carry out convolutions separately
separate groups. Each which carry out convolutions separately
unshared: bool
unshared
: bool
If true, then unshared or 'locally connected' convolution will be
If true, then unshared or 'locally connected' convolution will be
performed. A different filter will be used for each region of the
performed. A different filter will be used for each region of the
input.
input.
...
@@ -1640,6 +1643,11 @@ def causal_conv(input,
...
@@ -1640,6 +1643,11 @@ def causal_conv(input,
Set of feature vectors generated by convolutional layer. Tensor is
Set of feature vectors generated by convolutional layer. Tensor is
of shape (batch_size, output_channels, output_length)
of shape (batch_size, output_channels, output_length)
Notes
-----
:note: Currently, this is implemented with the 2D convolution ops.
"""
"""
input
=
as_tensor_variable
(
input
)
input
=
as_tensor_variable
(
input
)
...
@@ -1885,8 +1893,7 @@ class BaseAbstractConv(Op):
...
@@ -1885,8 +1893,7 @@ class BaseAbstractConv(Op):
element is not known at compile time.
element is not known at compile time.
kshp is defined w.r.t the forward conv.
kshp is defined w.r.t the forward conv.
border_mode: str, int or tuple of ``convdim`` elements where each element
border_mode: str, int or a tuple of two ints or pairs of ints
is an integer or a tuple of length 2.
Either of the following:
Either of the following:
``'valid'``: apply filter wherever it completely overlaps with the
``'valid'``: apply filter wherever it completely overlaps with the
...
@@ -1965,12 +1972,15 @@ class BaseAbstractConv(Op):
...
@@ -1965,12 +1972,15 @@ class BaseAbstractConv(Op):
'invalid border_mode {}, which must be a '
'invalid border_mode {}, which must be a '
'tuple of length {}'
.
format
(
border_mode
,
convdim
))
'tuple of length {}'
.
format
(
border_mode
,
convdim
))
for
mode
in
border_mode
:
for
mode
in
border_mode
:
if
isinstance
(
mode
,
tuple
)
and
convdim
!=
2
:
raise
NotImplementedError
(
'Asymmetric padding not implemented for {}D'
.
format
(
convdim
))
if
not
((
isinstance
(
mode
,
integer_types
)
and
mode
>=
0
)
or
if
not
((
isinstance
(
mode
,
integer_types
)
and
mode
>=
0
)
or
(
isinstance
(
mode
,
tuple
)
and
len
(
mode
)
==
2
and
min
(
mode
)
>=
0
and
(
isinstance
(
mode
,
tuple
)
and
len
(
mode
)
==
2
and
min
(
mode
)
>=
0
and
all
(
isinstance
(
m
,
integer_types
)
for
m
in
mode
))):
all
(
isinstance
(
m
,
integer_types
)
for
m
in
mode
))):
raise
ValueError
(
raise
ValueError
(
'invalid border mode {}. The tuple can only contain integers '
'invalid border mode {}. The tuple can only contain integers '
' or
tuples of integers of length 2
'
.
format
(
border_mode
))
' or
pairs of integers
'
.
format
(
border_mode
))
elif
border_mode
not
in
(
'valid'
,
'full'
,
'half'
):
elif
border_mode
not
in
(
'valid'
,
'full'
,
'half'
):
raise
ValueError
(
raise
ValueError
(
'invalid border_mode {}, which must be either '
'invalid border_mode {}, which must be either '
...
@@ -2238,7 +2248,7 @@ class AbstractConv(BaseAbstractConv):
...
@@ -2238,7 +2248,7 @@ class AbstractConv(BaseAbstractConv):
%
self
.
convdim
)
%
self
.
convdim
)
o
,
=
out_
o
,
=
out_
mode
=
self
.
border_mode
mode
=
self
.
border_mode
pad
=
mode_to_pad
(
mode
,
self
.
convdim
,
dil_kernshp
)
pad
=
border_
mode_to_pad
(
mode
,
self
.
convdim
,
dil_kernshp
)
if
any
(
p
!=
(
0
,
0
)
for
p
in
pad
):
if
any
(
p
!=
(
0
,
0
)
for
p
in
pad
):
mode
=
"valid"
mode
=
"valid"
...
@@ -2503,7 +2513,7 @@ class AbstractConv_gradWeights(BaseAbstractConv):
...
@@ -2503,7 +2513,7 @@ class AbstractConv_gradWeights(BaseAbstractConv):
dil_shape
=
tuple
((
shape
[
i
]
-
1
)
*
self
.
filter_dilation
[
i
]
+
1
dil_shape
=
tuple
((
shape
[
i
]
-
1
)
*
self
.
filter_dilation
[
i
]
+
1
for
i
in
range
(
self
.
convdim
))
for
i
in
range
(
self
.
convdim
))
pad
=
mode_to_pad
(
self
.
border_mode
,
self
.
convdim
,
dil_shape
)
pad
=
border_
mode_to_pad
(
self
.
border_mode
,
self
.
convdim
,
dil_shape
)
if
any
(
p
!=
(
0
,
0
)
for
p
in
pad
):
if
any
(
p
!=
(
0
,
0
)
for
p
in
pad
):
new_img
=
np
.
zeros
((
img
.
shape
[
0
],
img
.
shape
[
1
])
+
new_img
=
np
.
zeros
((
img
.
shape
[
0
],
img
.
shape
[
1
])
+
...
@@ -2805,8 +2815,7 @@ class AbstractConv_gradInputs(BaseAbstractConv):
...
@@ -2805,8 +2815,7 @@ class AbstractConv_gradInputs(BaseAbstractConv):
dil_kernshp
=
tuple
((
kern
.
shape
[
-
self
.
convdim
+
i
]
-
1
)
*
self
.
filter_dilation
[
i
]
+
1
dil_kernshp
=
tuple
((
kern
.
shape
[
-
self
.
convdim
+
i
]
-
1
)
*
self
.
filter_dilation
[
i
]
+
1
for
i
in
range
(
self
.
convdim
))
for
i
in
range
(
self
.
convdim
))
mode
=
self
.
border_mode
pad
=
border_mode_to_pad
(
self
.
border_mode
,
self
.
convdim
,
dil_kernshp
)
pad
=
mode_to_pad
(
mode
,
self
.
convdim
,
dil_kernshp
)
imshp
=
self
.
imshp
[:]
if
self
.
imshp
is
not
None
else
[
None
]
*
(
2
+
self
.
convdim
)
imshp
=
self
.
imshp
[:]
if
self
.
imshp
is
not
None
else
[
None
]
*
(
2
+
self
.
convdim
)
fallback_imshp
=
([
topgrad
.
shape
[
0
],
kern
.
shape
[
-
self
.
convdim
-
1
]]
+
fallback_imshp
=
([
topgrad
.
shape
[
0
],
kern
.
shape
[
-
self
.
convdim
-
1
]]
+
...
@@ -2815,7 +2824,7 @@ class AbstractConv_gradInputs(BaseAbstractConv):
...
@@ -2815,7 +2824,7 @@ class AbstractConv_gradInputs(BaseAbstractConv):
for
i
in
range
(
2
+
self
.
convdim
)]
for
i
in
range
(
2
+
self
.
convdim
)]
expected_topgrad_shape
=
get_conv_output_shape
(
expected_topgrad_shape
=
get_conv_output_shape
(
imshp
,
kern
.
shape
,
imshp
,
kern
.
shape
,
mode
,
self
.
subsample
,
self
.
filter_dilation
)
self
.
border_
mode
,
self
.
subsample
,
self
.
filter_dilation
)
if
not
tuple
(
expected_topgrad_shape
)
==
tuple
(
topgrad
.
shape
):
if
not
tuple
(
expected_topgrad_shape
)
==
tuple
(
topgrad
.
shape
):
raise
ValueError
(
raise
ValueError
(
'invalid input_shape for gradInputs: the given input_shape '
'invalid input_shape for gradInputs: the given input_shape '
...
...
theano/tensor/nnet/corr.py
浏览文件 @
5ae986b1
...
@@ -89,7 +89,7 @@ class BaseCorrMM(gof.OpenMPOp):
...
@@ -89,7 +89,7 @@ class BaseCorrMM(gof.OpenMPOp):
raise
ValueError
(
raise
ValueError
(
'invalid border_mode {}, which must be either '
'invalid border_mode {}, which must be either '
'"valid", "full", "half", an integer or a tuple '
'"valid", "full", "half", an integer or a tuple '
'of
length 2
'
.
format
(
border_mode
))
'of
two integers or a pair of integers
'
.
format
(
border_mode
))
self
.
border_mode
=
border_mode
self
.
border_mode
=
border_mode
if
len
(
subsample
)
!=
2
:
if
len
(
subsample
)
!=
2
:
raise
ValueError
(
"subsample must have two elements"
)
raise
ValueError
(
"subsample must have two elements"
)
...
...
theano/tensor/nnet/tests/test_abstract_conv.py
浏览文件 @
5ae986b1
...
@@ -24,7 +24,7 @@ from theano.tensor.nnet.abstract_conv import bilinear_kernel_1D
...
@@ -24,7 +24,7 @@ from theano.tensor.nnet.abstract_conv import bilinear_kernel_1D
from
theano.tensor.nnet.abstract_conv
import
bilinear_kernel_2D
from
theano.tensor.nnet.abstract_conv
import
bilinear_kernel_2D
from
theano.tensor.nnet.abstract_conv
import
bilinear_upsampling
from
theano.tensor.nnet.abstract_conv
import
bilinear_upsampling
from
theano.tensor.nnet.abstract_conv
import
separable_conv2d
,
separable_conv3d
from
theano.tensor.nnet.abstract_conv
import
separable_conv2d
,
separable_conv3d
from
theano.tensor.nnet.abstract_conv
import
causal_conv
from
theano.tensor.nnet.abstract_conv
import
causal_conv
1d
from
theano.tensor.nnet.corr
import
(
CorrMM
,
CorrMM_gradWeights
,
from
theano.tensor.nnet.corr
import
(
CorrMM
,
CorrMM_gradWeights
,
CorrMM_gradInputs
)
CorrMM_gradInputs
)
from
theano.tensor.nnet.corr3d
import
(
Corr3dMM
,
Corr3dMM_gradWeights
,
from
theano.tensor.nnet.corr3d
import
(
Corr3dMM
,
Corr3dMM_gradWeights
,
...
@@ -2037,7 +2037,7 @@ class TestCausalConv(unittest.TestCase):
...
@@ -2037,7 +2037,7 @@ class TestCausalConv(unittest.TestCase):
img_sym
=
theano
.
tensor
.
tensor3
(
'img'
)
img_sym
=
theano
.
tensor
.
tensor3
(
'img'
)
kern_sym
=
theano
.
tensor
.
tensor3
(
'kern'
)
kern_sym
=
theano
.
tensor
.
tensor3
(
'kern'
)
sym_out
=
causal_conv
(
img_sym
,
kern_sym
,
self
.
kern
.
shape
,
filter_dilation
=
self
.
dilation
)
sym_out
=
causal_conv
1d
(
img_sym
,
kern_sym
,
self
.
kern
.
shape
,
filter_dilation
=
self
.
dilation
)
causal_func
=
theano
.
function
([
img_sym
,
kern_sym
],
sym_out
,
mode
=
self
.
mode
)
causal_func
=
theano
.
function
([
img_sym
,
kern_sym
],
sym_out
,
mode
=
self
.
mode
)
...
@@ -2046,6 +2046,6 @@ class TestCausalConv(unittest.TestCase):
...
@@ -2046,6 +2046,6 @@ class TestCausalConv(unittest.TestCase):
utt
.
assert_allclose
(
output
,
self
.
precomp_top
)
utt
.
assert_allclose
(
output
,
self
.
precomp_top
)
def
causal_conv_fn
(
inputs_val
,
filters_val
):
def
causal_conv_fn
(
inputs_val
,
filters_val
):
return
causal_conv
(
inputs_val
,
filters_val
,
self
.
kern
.
shape
,
filter_dilation
=
1
)
return
causal_conv
1d
(
inputs_val
,
filters_val
,
self
.
kern
.
shape
,
filter_dilation
=
1
)
utt
.
verify_grad
(
causal_conv_fn
,
[
self
.
img
,
self
.
kern
],
mode
=
self
.
mode
,
eps
=
1
)
utt
.
verify_grad
(
causal_conv_fn
,
[
self
.
img
,
self
.
kern
],
mode
=
self
.
mode
,
eps
=
1
)
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论