Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
251f616f
提交
251f616f
authored
8月 10, 2017
作者:
Frederic Bastien
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Update conv doc.
上级
d844e6c1
显示空白字符变更
内嵌
并排
正在显示
2 个修改的文件
包含
46 行增加
和
92 行删除
+46
-92
conv.txt
doc/library/tensor/nnet/conv.txt
+45
-91
opt.py
theano/gpuarray/opt.py
+1
-1
没有找到文件。
doc/library/tensor/nnet/conv.txt
浏览文件 @
251f616f
...
@@ -22,78 +22,62 @@
...
@@ -22,78 +22,62 @@
.. moduleauthor:: LISA
.. moduleauthor:: LISA
.. note::
The recomanded user interface are:
- :func:`theano.tensor.nnet.conv2d` for 2d convolution
- :func:`theano.tensor.nnet.conv3d` for 3d convolution
As of December 2015, a new conv2d interface has been introduced.
With those new interface, Theano will automatically use the fastest
:func:`nnet.conv2d <theano.tensor.nnet.conv2d>` defines an
implementation in many cases. On the CPU, the implementation is a GEMM
abstract theano graph convolution operation
based one. On the GPU, there is a GEMM based and :ref:`cuDNN
(:func:`nnet.abstract_conv.AbstractConv2d <theano.tensor.nnet.abstract_conv.AbstractConv2d>`)
<libdoc_gpuarray_dnn>` version.
that will be replaced by an actual convolution implementation during
the optimization phase.
As of October 2016 (version 0.9.0dev3), there is also a conv3d interface that provides
By default on the GPU, if cuDNN is available, it will be used,
a similar operation for 3D convolution. :func:`nnet.conv3d <theano.tensor.nnet.conv3d>`
otherwise we will fall back to using gemm based version (slower than
defines the abstract theano graph convolution operation
cuDNN in most cases and uses more memory). To get an error if cuDNN
:func:`nnet.abstract_conv.AbstractConv3d <theano.tensor.nnet.abstract_conv.AbstractConv3d>
`.
can not be used, you can supply the Theano flag ``dnn.enable=True`
`.
Since the abstract Op does not have any implementation, it will prevent
Either cuDNN and the gemm version can be disabled using the Theano flags
computations in the un-optimized graph, and cause problems with DebugMode
,
``optimizer_excluding=conv_dnn`` and ``optimizer_excluding=conv_gemm``
,
test values, and when compiling with optimizer=None
.
respectively. If both are disabled, it will raise an error
.
By default, if :ref:`cuDNN <libdoc_gpuarray_dnn>`
is available, we will use it, otherwise we will fall back to using the
gemm version (slower than cuDNN in most cases and uses more memory).
Either cuDNN and the gemm version can be disabled using the Theano flags
For the cuDNN version, there is different algorythm with different
``optimizer_excluding=conv_dnn`` and ``optimizer_excluding=conv_gemm``,
memory/speed trade-off. Manual selection of the right one is very
respectively. In this case, we will fall back to using the legacy
difficult as it depend of the shapes and hardware. So it can change
convolution code, which is slower, but does not require extra memory.
for each layer. An auto-tuning mode exist and can be activated by
To verify that cuDNN is used, you can supply the Theano flag
those flag: ``dnn.conv.algo_fwd=time_once``,
``optimizer_including=cudnn``. This will raise an error if cuDNN is
``dnn.conv.algo_bwd_data=time_once`` and
unavailable
.
``dnn.conv.algo_bwd_filter=time_once``
.
It is not advised to ever disable cuDNN, as this is usually the fastest
This auto-tuning have the inconvenience that the first call is much
option. Disabling the gemm version is only useful if cuDNN is unavailable
slower as it try and time each implementation it have. So if you
and you run out of GPU memory.
benchmark, it is important that you remove the first call from your
timing.
There are two other implementations of 2D convolution: An FFT-based
convolution integrated into Theano, and an implementation by Alex Krizhevsky
available via Pylearn2. See the documentation below on how to use them.
Old conv2d interface is still accessible through :func:`nnet.conv.conv2d <theano.tensor.nnet.conv.conv2d>`.
.. note::
Theano had older user interface like
theano.tensor.nnet.conv.conv2d. Do not user them anymore. They
will give you slower code and won't allow easy switch between CPU
and GPU computation. They also support less type of convolution.
TODO: Give examples on how to use these things! They are pretty complicated.
Implementation Details
======================
This section give more implementation detail. Most of the time you do
not need to read it. Theano will select it for you.
- Implemented operators for neural network 2D / image convolution:
- Implemented operators for neural network 2D / image convolution:
- :func:`nnet.conv.conv2d <theano.tensor.nnet.conv.conv2d>`.
- :func:`nnet.conv.conv2d <theano.tensor.nnet.conv.conv2d>`.
CPU convolution implementation, previously used as the
old 2d convolution. DO NOT USE ANYMORE.
convolution interface. This is the standard operator for
convolutional neural networks working with batches of
multi-channel 2D images, available. It computes a convolution,
i.e., it flips the kernel.
Most of the more efficient GPU implementations listed below can be
inserted automatically as a replacement for nnet.conv.conv2d via graph
optimizations. Some of these graph optimizations are enabled by default,
others can be enabled via Theano flags.
You can also use a meta-optimizer to automatically choose the
fastest implementation for each specific convolution in your
graph using the old interface. For each instance, it will
compile and benchmark each applicable implementation of the ones
listed below and choose the fastest one.
As performance is dependent on input and filter shapes, this
only works for operations introduced via nnet.conv.conv2d with
fully specified shape information. Enable it via the Theano
flag ``optimizer_including=conv_meta``, and optionally set it to
verbose mode via the flag `metaopt.verbose=1`.
- :func:`GpuCorrMM <theano.gpuarray.blas.GpuCorrMM>`
- :func:`GpuCorrMM <theano.gpuarray.blas.GpuCorrMM>`
This is a GPU-only 2d correlation implementation taken from
This is a GPU-only 2d correlation implementation taken from
`caffe's CUDA implementation <https://github.com/BVLC/caffe/blob/master/src/caffe/layers/conv_layer.cu>`_
`caffe's CUDA implementation <https://github.com/BVLC/caffe/blob/master/src/caffe/layers/conv_layer.cu>`_. It does not flip the kernel.
and also used by Torch. It does not flip the kernel.
For each element in a batch, it first creates a
For each element in a batch, it first creates a
`Toeplitz <http://en.wikipedia.org/wiki/Toeplitz_matrix>`_ matrix in a CUDA kernel.
`Toeplitz <http://en.wikipedia.org/wiki/Toeplitz_matrix>`_ matrix in a CUDA kernel.
...
@@ -102,65 +86,35 @@ TODO: Give examples on how to use these things! They are pretty complicated.
...
@@ -102,65 +86,35 @@ TODO: Give examples on how to use these things! They are pretty complicated.
It needs extra memory for the Toeplitz matrix, which is a 2D matrix of shape
It needs extra memory for the Toeplitz matrix, which is a 2D matrix of shape
``(no of channels * filter width * filter height, output width * output height)``.
``(no of channels * filter width * filter height, output width * output height)``.
As it provides a gradient, you can use it as a replacement for nnet.conv2d.
But usually, you will just use nnet.conv2d and allow Theano's graph
optimizer to automatically replace it by the GEMM version if cuDNN is not
available. To explicitly disable the graph optimizer, set
``THEANO_FLAGS=optimizer_excluding=conv_gemm`` in your environment.
If using it, please see the warning about a bug in CUDA 5.0 to 6.0 below.
- :func:`CorrMM <theano.tensor.nnet.corr.CorrMM>`
- :func:`CorrMM <theano.tensor.nnet.corr.CorrMM>`
This is a CPU-only 2d correlation implementation taken from
This is a CPU-only 2d correlation implementation taken from
`caffe's cpp implementation <https://github.com/BVLC/caffe/blob/master/src/caffe/layers/conv_layer.cpp>`_
`caffe's cpp implementation <https://github.com/BVLC/caffe/blob/master/src/caffe/layers/conv_layer.cpp>`_.
and also used by Torch. It does not flip the kernel. As it provides a gradient,
It does not flip the kernel.
you can use it as a replacement for nnet.conv2d. For convolutions done on
CPU, nnet.conv2d will be replaced by CorrMM. To explicitly disable it, set
``THEANO_FLAGS=optimizer_excluding=conv_gemm`` in your environment.
- :func:`dnn_conv <theano.gpuarray.dnn.dnn_conv>` GPU-only
- :func:`dnn_conv <theano.gpuarray.dnn.dnn_conv>` GPU-only
convolution using NVIDIA's cuDNN library. This requires that you have
convolution using NVIDIA's cuDNN library.
cuDNN 4.0 or newer installed and available, which in turn requires CUDA 7.0
and a GPU with compute capability 3.0 or more.
If cuDNN is available, by default, Theano will replace all nnet.conv2d
operations with dnn_conv. To explicitly disable it, set
``THEANO_FLAGS=optimizer_excluding=conv_dnn`` in your environment.
As dnn_conv has a gradient defined, you can also use it manually.
- Implemented operators for neural network 3D / video convolution:
- Implemented operators for neural network 3D / video convolution:
- :func:`GpuCorr3dMM <theano.gpuarray.blas.GpuCorr3dMM>`
- :func:`GpuCorr3dMM <theano.gpuarray.blas.GpuCorr3dMM>`
This is a GPU-only 3d correlation relying on a Toeplitz matrix
This is a GPU-only 3d correlation relying on a Toeplitz matrix
and gemm implementation (see :func:`GpuCorrMM <theano.sandbox.cuda.blas.GpuCorrMM>`)
and gemm implementation (see :func:`GpuCorrMM <theano.sandbox.cuda.blas.GpuCorrMM>`)
It needs extra memory for the Toeplitz matrix, which is a 2D matrix of shape
It needs extra memory for the Toeplitz matrix, which is a 2D matrix of shape
``(no of channels * filter width * filter height * filter depth, output width * output height * output depth)``.
``(no of channels * filter width * filter height * filter depth, output width * output height * output depth)``.
As it provides a gradient, you can use it as a replacement for nnet.conv3d.
Alternatively, you can use nnet.conv3d and allow Theano's graph optimizer
to replace it by the GEMM version by setting
``THEANO_FLAGS=optimizer_including=conv3d_gemm:convgrad3d_gemm:convtransp3d_gemm`` in your environment.
This is not enabled by default because it uses some extra memory, but the
overhead is small compared to conv3d_fft, there are no restrictions on
input or kernel shapes and strides are supported. If using it,
please see the warning about a bug in CUDA 5.0 to 6.0
in :func:`GpuCorrMM <theano.sandbox.cuda.blas.GpuCorrMM>`.
- :func:`Corr3dMM <theano.tensor.nnet.corr3d.Corr3dMM>`
- :func:`Corr3dMM <theano.tensor.nnet.corr3d.Corr3dMM>`
This is a CPU-only 3d correlation implementation based on
This is a CPU-only 3d correlation implementation based on
the 2d version (:func:`CorrMM <theano.tensor.nnet.corr.CorrMM>`).
the 2d version (:func:`CorrMM <theano.tensor.nnet.corr.CorrMM>`).
It does not flip the kernel. As it provides a gradient, you can use it as a
It does not flip the kernel. As it provides a gradient, you can use it as a
replacement for nnet.conv3d. For convolutions done on CPU,
replacement for nnet.conv3d. For convolutions done on CPU,
nnet.conv3d will be replaced by Corr3dMM. To explicitly disable it, set
nnet.conv3d will be replaced by Corr3dMM.
``THEANO_FLAGS=optimizer_excluding=conv_gemm`` in your environment.
- :func:`dnn_conv <theano.gpuarray.dnn.dnn_conv>` GPU-only
- :func:`dnn_conv <theano.gpuarray.dnn.dnn_conv>` GPU-only
convolution using NVIDIA's cuDNN library. This requires that you have
convolution using NVIDIA's cuDNN library.
cuDNN 4.0 or newer installed and available, which in turn requires CUDA 7.0
and a GPU with compute capability 3.0 or more.
If cuDNN is available, by default, Theano will replace all nnet.conv3d
If cuDNN is available, by default, Theano will replace all nnet.conv3d
operations with dnn_conv. To explicitly disable it, set
operations with dnn_conv.
``THEANO_FLAGS=optimizer_excluding=conv_dnn`` in your environment.
As dnn_conv3d has a gradient defined, you can also use it manually.
- :func:`conv3d2d <theano.tensor.nnet.conv3d2d.conv3d>`
- :func:`conv3d2d <theano.tensor.nnet.conv3d2d.conv3d>`
Another conv3d implementation that uses the conv2d with data reshaping.
Another conv3d implementation that uses the conv2d with data reshaping.
It is faster in some cases than conv3d. It flips the kernel.
It is faster in some c
orner c
ases than conv3d. It flips the kernel.
.. autofunction:: theano.tensor.nnet.conv2d
.. autofunction:: theano.tensor.nnet.conv2d
.. autofunction:: theano.tensor.nnet.conv2d_transpose
.. autofunction:: theano.tensor.nnet.conv2d_transpose
...
...
theano/gpuarray/opt.py
浏览文件 @
251f616f
...
@@ -2134,7 +2134,7 @@ def local_gpua_abstractconv(op, context_name, inputs, outputs):
...
@@ -2134,7 +2134,7 @@ def local_gpua_abstractconv(op, context_name, inputs, outputs):
AbstractConv2d_gradInputs
,
AbstractConv2d_gradInputs
,
AbstractConv3d
,
AbstractConv3d
,
AbstractConv3d_gradWeights
,
AbstractConv3d_gradWeights
,
AbstractConv3d_gradInputs
],
'fast_compile'
,
'conv_dnn'
,
'cudnn'
)
AbstractConv3d_gradInputs
],
'fast_compile'
)
def
local_gpua_lift_abstractconv_graph
(
op
,
context_name
,
inputs
,
outputs
):
def
local_gpua_lift_abstractconv_graph
(
op
,
context_name
,
inputs
,
outputs
):
inps
=
list
(
inputs
)
inps
=
list
(
inputs
)
inps
[
0
]
=
as_gpuarray_variable
(
inputs
[
0
],
inps
[
0
]
=
as_gpuarray_variable
(
inputs
[
0
],
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论