Skip to content

Commit d4399f7

Browse files
committed
fix conv2d_transpose doc
1 parent 72e9dea commit d4399f7

File tree

1 file changed

+77
-80
lines changed
  • python/paddle/v2/fluid/layers

1 file changed

+77
-80
lines changed

python/paddle/v2/fluid/layers/nn.py

Lines changed: 77 additions & 80 deletions
Original file line numberDiff line numberDiff line change
@@ -607,58 +607,61 @@ def conv2d(input,
607607
<http://ufldl.stanford.edu/tutorial/supervised/FeatureExtractionUsingConvolution/>`_ .
608608
If bias attribution and activation type are provided, bias is added to the output of the convolution,
609609
and the corresponding activation function is applied to the final result.
610-
For each input :math:`X`, the equation is:
611610
611+
For each input :math:`X`, the equation is:
612612
613613
.. math::
614614
615615
Out = \sigma (W \\ast X + b)
616616
617617
In the above equation:
618618
619-
* :math:`X`: Input value, a tensor with NCHW format.
620-
* :math:`W`: Filter value, a tensor with MCHW format.
621-
* :math:`\\ast`: Convolution operation.
622-
* :math:`b`: Bias value, a 2-D tensor with shape [M, 1].
623-
* :math:`\\sigma`: Activation function.
624-
* :math:`Out`: Output value, the shape of :math:`Out` and :math:`X` may be different.
619+
* :math:`X`: Input value, a tensor with NCHW format.
620+
* :math:`W`: Filter value, a tensor with MCHW format.
621+
* :math:`\\ast`: Convolution operation.
622+
* :math:`b`: Bias value, a 2-D tensor with shape [M, 1].
623+
* :math:`\\sigma`: Activation function.
624+
* :math:`Out`: Output value, the shape of :math:`Out` and :math:`X` may be different.
625625
626626
Example:
627627
628-
Input:
629-
Input shape: $(N, C_{in}, H_{in}, W_{in})$
628+
- Input:
629+
630+
Input shape: $(N, C_{in}, H_{in}, W_{in})$
631+
632+
Filter shape: $(C_{out}, C_{in}, H_f, W_f)$
630633
631-
Filter shape: $(C_{out}, C_{in}, H_f, W_f)$
634+
- Output:
635+
Output shape: $(N, C_{out}, H_{out}, W_{out})$
632636
633-
Output:
634-
Output shape: $(N, C_{out}, H_{out}, W_{out})$
635637
Where
636-
.. math::
638+
639+
.. math::
637640
638641
H_{out}&= \\frac{(H_{in} + 2 * paddings[0] - (dilations[0] * (H_f - 1) + 1))}{strides[0]} + 1 \\\\
639642
W_{out}&= \\frac{(W_{in} + 2 * paddings[1] - (dilations[1] * (W_f - 1) + 1))}{strides[1]} + 1
640643
641644
Args:
642-
input(Variable): The input image with [N, C, H, W] format.
643-
num_filters(int): The number of filter. It is as same as the output
644-
image channel.
645-
filter_size(int|tuple|None): The filter size. If filter_size is a tuple,
646-
it must contain two integers, (filter_size_H, filter_size_W).
647-
Otherwise, the filter will be a square.
648-
stride(int|tuple): The stride size. If stride is a tuple, it must
649-
contain two integers, (stride_H, stride_W). Otherwise, the
650-
stride_H = stride_W = stride. Default: stride = 1.
651-
padding(int|tuple): The padding size. If padding is a tuple, it must
652-
contain two integers, (padding_H, padding_W). Otherwise, the
653-
padding_H = padding_W = padding. Default: padding = 0.
654-
groups(int): The groups number of the Conv2d Layer. According to grouped
655-
convolution in Alex Krizhevsky's Deep CNN paper: when group=2,
656-
the first half of the filters is only connected to the first half
657-
of the input channels, while the second half of the filters is only
658-
connected to the second half of the input channels. Default: groups=1
659-
param_attr(ParamAttr): The parameters to the Conv2d Layer. Default: None
660-
bias_attr(ParamAttr): Bias parameter for the Conv2d layer. Default: None
661-
act(str): Activation type. Default: None
645+
input(Variable): The input image with [N, C, H, W] format.
646+
num_filters(int): The number of filter. It is as same as the output
647+
image channel.
648+
filter_size(int|tuple|None): The filter size. If filter_size is a tuple,
649+
it must contain two integers, (filter_size_H, filter_size_W).
650+
Otherwise, the filter will be a square.
651+
stride(int|tuple): The stride size. If stride is a tuple, it must
652+
contain two integers, (stride_H, stride_W). Otherwise, the
653+
stride_H = stride_W = stride. Default: stride = 1.
654+
padding(int|tuple): The padding size. If padding is a tuple, it must
655+
contain two integers, (padding_H, padding_W). Otherwise, the
656+
padding_H = padding_W = padding. Default: padding = 0.
657+
groups(int): The groups number of the Conv2d Layer. According to grouped
658+
convolution in Alex Krizhevsky's Deep CNN paper: when group=2,
659+
the first half of the filters is only connected to the first half
660+
of the input channels, while the second half of the filters is only
661+
connected to the second half of the input channels. Default: groups=1
662+
param_attr(ParamAttr): The parameters to the Conv2d Layer. Default: None
663+
bias_attr(ParamAttr): Bias parameter for the Conv2d layer. Default: None
664+
act(str): Activation type. Default: None
662665
663666
Returns:
664667
Variable: The tensor variable storing the convolution and \
@@ -673,7 +676,6 @@ def conv2d(input,
673676
data = fluid.layers.data(name='data', shape=[3, 32, 32], dtype='float32')
674677
conv2d = fluid.layers.conv2d(input=data, num_filters=2, filter_size=3, act="relu")
675678
"""
676-
677679
if stride is None:
678680
stride = [1, 1]
679681
helper = LayerHelper('conv2d', **locals())
@@ -1005,84 +1007,79 @@ def conv2d_transpose(input,
10051007
"""
10061008
**Convlution2D transpose layer**
10071009
1008-
The convolution2D layer calculates the output based on the input, filter
1009-
and strides, paddings, dilations, groups parameters. Input(Input) and Output(Output)
1010-
are in NCHW format. Where N is batch size, C is the number of channels, H is the height
1011-
of the feature, and W is the width of the feature.
1010+
The convolution2D transpose layer calculates the output based on the input, filter
1011+
and dilations, strides, paddings, groups parameters. Input(Input) and output(Output)
1012+
are in NCHW format. Where N is batchsize, C is the number of channels, H is the height
1013+
of the feature, and W is the width of the feature. Parameters(dilations, strides, paddings)
1014+
are two elements. These two elements represent height and width, respectively.
10121015
The details of convolution transpose layer, please refer to the following explanation
1013-
and references therein
1014-
<http://datascience.stackexchange.com/questions/6107/what-are-deconvolutional-layers/>`_ .
1016+
and references `therein <http://www.matthewzeiler.com/wp-content/uploads/2017/07/cvpr2010.pdf>`_.
10151017
10161018
For each input :math:`X`, the equation is:
10171019
1018-
10191020
.. math::
10201021
10211022
Out = W \\ast X
10221023
1023-
In the above equation:
1024+
In the above equation:
10241025
1025-
* :math:`X`: Input value, a tensor with NCHW format.
1026-
* :math:`W`: Filter value, a tensor with MCHW format.
1027-
* :math: \\ast : Convolution transpose operation.
1028-
* :math:`Out`: Output value, the shape of :math:`Out` and :math:`X` may be different.
1026+
* :math:`X`: Input value, a tensor with NCHW format.
1027+
* :math:`W`: Filter value, a tensor with MCHW format.
1028+
* :math:`\\ast` : Convolution transpose operation.
1029+
* :math:`Out`: Output value, the shape of :math:`Out` and :math:`X` may be different.
10291030
10301031
Example:
10311032
10321033
- Input:
10331034
1034-
Input shape: $(N, C_{in}, H_{in}, W_{in})$
1035+
Input shape: $(N, C_{in}, H_{in}, W_{in})$
10351036
1036-
Filter shape: $(C_{in}, C_{out}, H_f, W_f)$
1037+
Filter shape: $(C_{in}, C_{out}, H_f, W_f)$
10371038
10381039
- Output:
10391040
1040-
Output shape: $(N, C_{out}, H_{out}, W_{out})$
1041+
Output shape: $(N, C_{out}, H_{out}, W_{out})$
10411042
10421043
Where
10431044
1044-
.. math::
1045+
.. math::
10451046
1046-
H_{out} = (H_{in} - 1) * strides[0] - 2 * paddings[0] + dilations[0] * (H_f - 1) + 1 \\\\
1047-
W_{out} = (W_{in} - 1) * strides[1] - 2 * paddings[1] + dilations[1] * (W_f - 1) + 1
1048-
1049-
All the input variables are passed in as local variables to the LayerHelper
1050-
constructor.
1047+
H_{out} &= (H_{in} - 1) * strides[0] - 2 * paddings[0] + dilations[0] * (H_f - 1) + 1 \\\\
1048+
W_{out} &= (W_{in} - 1) * strides[1] - 2 * paddings[1] + dilations[1] * (W_f - 1) + 1
10511049
10521050
Args:
1053-
input(Variable): The input image with [N, C, H, W] format.
1054-
num_filters(int): The number of filter. It is as same as the output
1055-
image channel.
1056-
output_size(int|tuple|None): The output image size. If output size is a
1057-
tuple, it must contain two integers, (image_H, image_W). This
1058-
parameter only works when filter_size is None.
1059-
filter_size(int|tuple|None): The filter size. If filter_size is a tuple,
1060-
it must contain two integers, (filter_size_H, filter_size_W).
1061-
Otherwise, the filter will be a square. None if use output size to
1062-
calculate filter_size
1063-
padding(int|tuple): The padding size. If padding is a tuple, it must
1064-
contain two integers, (padding_H, padding_W). Otherwise, the
1065-
padding_H = padding_W = padding.
1066-
stride(int|tuple): The stride size. If stride is a tuple, it must
1067-
contain two integers, (stride_H, stride_W). Otherwise, the
1068-
stride_H = stride_W = stride.
1069-
dilation(int|tuple): The dilation size. If dilation is a tuple, it must
1070-
contain two integers, (dilation_H, dilation_W). Otherwise, the
1071-
dilation_H = dilation_W = dilation.
1072-
param_attr: Parameter Attribute.
1051+
input(Variable): The input image with [N, C, H, W] format.
1052+
num_filters(int): The number of filter. It is as same as the output
1053+
image channel.
1054+
output_size(int|tuple|None): The output image size. If output size is a
1055+
tuple, it must contain two integers, (image_H, image_W). This
1056+
parameter only works when filter_size is None.
1057+
filter_size(int|tuple|None): The filter size. If filter_size is a tuple,
1058+
it must contain two integers, (filter_size_H, filter_size_W).
1059+
Otherwise, the filter will be a square. None if use output size to
1060+
calculate filter_size.
1061+
padding(int|tuple): The padding size. If padding is a tuple, it must
1062+
contain two integers, (padding_H, padding_W). Otherwise, the
1063+
padding_H = padding_W = padding. Default: padding = 0.
1064+
stride(int|tuple): The stride size. If stride is a tuple, it must
1065+
contain two integers, (stride_H, stride_W). Otherwise, the
1066+
stride_H = stride_W = stride. Default: stride = 1.
1067+
dilation(int|tuple): The dilation size. If dilation is a tuple, it must
1068+
contain two integers, (dilation_H, dilation_W). Otherwise, the
1069+
dilation_H = dilation_W = dilation. Default: dilation = 1.
1070+
param_attr(ParamAttr): The parameters to the Conv2d_transpose Layer. Default: None
10731071
10741072
Returns:
1075-
Variable: The tensor variable storing the convolution transpose result.
1073+
Variable: The tensor variable storing the convolution transpose result.
10761074
10771075
Raises:
1078-
ValueError: If the shapes of input, filter_size, stride, padding and groups mismatch.
1076+
ValueError: If the shapes of input, filter_size, stride, padding and groups mismatch.
10791077
10801078
Examples:
1081-
.. code-block:: python
1079+
.. code-block:: python
10821080
10831081
data = fluid.layers.data(name='data', shape=[3, 32, 32], dtype='float32')
1084-
conv2d = fluid.layers.conv2d_transpose(input=data, num_filters=2, filter_size=3)
1085-
1082+
conv2d_transpose = fluid.layers.conv2d_transpose(input=data, num_filters=2, filter_size=3)
10861083
"""
10871084
helper = LayerHelper("conv2d_transpose", **locals())
10881085
if not isinstance(input, Variable):

0 commit comments

Comments
 (0)