Skip to content

Commit

Permalink
refine conv2d_transpose layer doc
Browse files Browse the repository at this point in the history
  • Loading branch information
chengduoZH committed Dec 23, 2017
1 parent bb58a47 commit ba82f2c
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 15 deletions.
10 changes: 5 additions & 5 deletions paddle/operators/conv_transpose_op.cc
Original file line number Diff line number Diff line change
Expand Up @@ -117,8 +117,8 @@ The input(X) size and output(Out) size may be different.
Output shape: $(N, C_{out}, H_{out}, W_{out})$
Where
$$
H_{out} = (H_{in} - 1) * strides[0] - 2 * paddings[0] + H_f \\
W_{out} = (W_{in} - 1) * strides[1] - 2 * paddings[1] + W_f
H_{out} = (H_{in} - 1) * strides[0] - 2 * paddings[0] + dilations[0] * (H_f - 1) + 1 \\
W_{out} = (W_{in} - 1) * strides[1] - 2 * paddings[1] + dilations[1] * (W_f - 1) + 1
$$
)DOC");
}
Expand Down Expand Up @@ -187,9 +187,9 @@ The input(X) size and output(Out) size may be different.
Output shape: $(N, C_{out}, D_{out}, H_{out}, W_{out})$
Where
$$
D_{out} = (D_{in} - 1) * strides[0] - 2 * paddings[0] + D_f \\
H_{out} = (H_{in} - 1) * strides[1] - 2 * paddings[1] + H_f \\
W_{out} = (W_{in} - 1) * strides[2] - 2 * paddings[2] + W_f
D_{out} = (D_{in} - 1) * strides[0] - 2 * paddings[0] + dilations[0] * (D_f - 1) + 1 \\
H_{out} = (H_{in} - 1) * strides[1] - 2 * paddings[1] + dilations[1] * (H_f - 1) + 1 \\
W_{out} = (W_{in} - 1) * strides[2] - 2 * paddings[2] + dilations[2] * (W_f - 1) + 1
$$
)DOC");
}
Expand Down
9 changes: 4 additions & 5 deletions paddle/operators/conv_transpose_op.h
Original file line number Diff line number Diff line change
Expand Up @@ -133,9 +133,9 @@ class GemmConvTransposeKernel : public framework::OpKernel<T> {
if (data_dim == 2U) {
// col2im: col_matrix -> dy
// from (c * k_h * k_w, h * w) to (c, o_h, o_w)
col2im(dev_ctx, col, std::vector<int>{dilations[0], dilations[1]},
strides, std::vector<int>{paddings[0], paddings[1], paddings[0],
paddings[1]},
col2im(dev_ctx, col, dilations, strides,
std::vector<int>{paddings[0], paddings[1], paddings[0],
paddings[1]},
&output_batch);
} else if (data_dim == 3U) {
// col2vol: col_matrix -> dy
Expand Down Expand Up @@ -239,8 +239,7 @@ class GemmConvTransposeGradKernel : public framework::OpKernel<T> {
if (data_dim == 2U) {
// im2col: dy -> col matrix
// from (c, o_h, o_w) to (c * k_h * k_w, h * w)
im2col(dev_ctx, output_grad_batch,
std::vector<int>{dilations[0], dilations[1]}, strides,
im2col(dev_ctx, output_grad_batch, dilations, strides,
std::vector<int>{paddings[0], paddings[1], paddings[0],
paddings[1]},
&col);
Expand Down
60 changes: 55 additions & 5 deletions python/paddle/v2/fluid/layers/nn.py
Original file line number Diff line number Diff line change
Expand Up @@ -851,9 +851,51 @@ def conv2d_transpose(input,
dilation=None,
param_attr=None):
"""
The transpose of conv2d layer.
**Convlution2D transpose layer**
This layer is also known as deconvolution layer.
The convolution2D layer calculates the output based on the input, filter
and strides, paddings, dilations, groups parameters. Input(Input) and Output(Output)
are in NCHW format. Where N is batch size, C is the number of channels, H is the height
of the feature, and W is the width of the feature.
The details of convolution transpose layer, please refer to the following explanation
and references therein
<http://datascience.stackexchange.com/questions/6107/what-are-deconvolutional-layers/>`_ .
For each input :math:`X`, the equation is:
.. math::
Out = W \\ast X
In the above equation:
* :math:`X`: Input value, a tensor with NCHW format.
* :math:`W`: Filter value, a tensor with MCHW format.
* :math: \\ast : Convolution transpose operation.
* :math:`Out`: Output value, the shape of :math:`Out` and :math:`X` may be different.
Example:
- Input:
Input shape: $(N, C_{in}, H_{in}, W_{in})$
Filter shape: $(C_{in}, C_{out}, H_f, W_f)$
- Output:
Output shape: $(N, C_{out}, H_{out}, W_{out})$
Where
.. math::
H_{out} = (H_{in} - 1) * strides[0] - 2 * paddings[0] + dilations[0] * (H_f - 1) + 1 \\\\
W_{out} = (W_{in} - 1) * strides[1] - 2 * paddings[1] + dilations[1] * (W_f - 1) + 1
All the input variables are passed in as local variables to the LayerHelper
constructor.
Args:
input(Variable): The input image with [N, C, H, W] format.
Expand All @@ -876,11 +918,19 @@ def conv2d_transpose(input,
contain two integers, (dilation_H, dilation_W). Otherwise, the
dilation_H = dilation_W = dilation.
param_attr: Parameter Attribute.
main_program(Program): the main program
startup_program(Program): the startup program
Returns:
Variable: Output image.
Variable: The tensor variable storing the convolution transpose result.
Raises:
ValueError: If the shapes of input, filter_size, stride, padding and groups mismatch.
Examples:
.. code-block:: python
data = fluid.layers.data(name='data', shape=[3, 32, 32], dtype='float32')
conv2d = fluid.layers.conv2d_transpose(input=data, num_filters=2, filter_size=3)
"""
helper = LayerHelper("conv2d_transpose", **locals())
if not isinstance(input, Variable):
Expand Down

0 comments on commit ba82f2c

Please sign in to comment.