correct conv ops api equations

This commit is contained in:
lilinjie 2022-08-08 21:44:26 +08:00
parent a028a42c88
commit 7c472435e4
4 changed files with 27 additions and 27 deletions

View File

@ -45,28 +45,28 @@ mindspore.nn.Conv2d
.. math:: .. math::
\begin{array}{ll} \\ \begin{array}{ll} \\
H_{out} \left \lfloor{\frac{H_{in}}{\text{stride[0]}} + 1} \right \rfloor \\ H_{out} \left \lceil{\frac{H_{in}}{\text{stride[0]}}} \right \rceil \\
W_{out} \left \lfloor{\frac{W_{in}}{\text{stride[1]}} + 1} \right \rfloor \\ W_{out} \left \lceil{\frac{W_{in}}{\text{stride[1]}}} \right \rceil \\
\end{array} \end{array}
pad_mode为"valid"时: pad_mode为"valid"时:
.. math:: .. math::
\begin{array}{ll} \\ \begin{array}{ll} \\
H_{out} \left \lfloor{\frac{H_{in} - \text{dilation[0]} \times (\text{kernel_size[0]} - 1) } H_{out} \left \lceil{\frac{H_{in} - \text{dilation[0]} \times (\text{kernel_size[0]} - 1) }
{\text{stride[0]}} + 1} \right \rfloor \\ {\text{stride[0]}}} \right \rceil \\
W_{out} \left \lfloor{\frac{W_{in} - \text{dilation[1]} \times (\text{kernel_size[1]} - 1) } W_{out} \left \lceil{\frac{W_{in} - \text{dilation[1]} \times (\text{kernel_size[1]} - 1) }
{\text{stride[1]}} + 1} \right \rfloor \\ {\text{stride[1]}}} \right \rceil \\
\end{array} \end{array}
pad_mode为"pad"时: pad_mode为"pad"时:
.. math:: .. math::
\begin{array}{ll} \\ \begin{array}{ll} \\
H_{out} \left \lfloor{\frac{H_{in} + padding[0] + padding[1] - (\text{dilation[0]} - 1) \times H_{out} \left \lfloor{\frac{H_{in} + padding[0] + padding[1] - (\text{kernel_size[0]} - 1) \times
\text{kernel_size[0]} - 1 }{\text{stride[0]}} + 1} \right \rfloor \\ \text{dilation[0]} - 1 }{\text{stride[0]}} + 1} \right \rfloor \\
W_{out} \left \lfloor{\frac{W_{in} + padding[2] + padding[3] - (\text{dilation[1]} - 1) \times W_{out} \left \lfloor{\frac{W_{in} + padding[2] + padding[3] - (\text{kernel_size[1]} - 1) \times
\text{kernel_size[1]} - 1 }{\text{stride[1]}} + 1} \right \rfloor \\ \text{dilation[1]} - 1 }{\text{stride[1]}} + 1} \right \rfloor \\
\end{array} \end{array}
异常: 异常:

View File

@ -12,7 +12,7 @@ mindspore.ops.Conv2D
其中, :math:`ccor``cross-correlation <https://en.wikipedia.org/wiki/Cross-correlation>`_ :math:`C_{in}` 为输入通道数, :math:`j` 的范围从 :math:`0`:math:`C_{out} - 1` :math:`W_{ij}` 对应第 :math:`j` 个过滤器的第 :math:`i` 个通道, :math:`out_{j}` 对应输出的第 :math:`j` 个通道。 :math:`W_{ij}` 为卷积核的切片其shape为 :math:`(\text{kernel_size[0]},\text{kernel_size[1]})` ,其中 :math:`\text{kernel_size[0]}`:math:`\text{kernel_size[1]}` 是卷积核的高度和宽度。完整卷积核的shape为 :math:`(C_{out}, C_{in} / \text{group}, \text{kernel_size[0]}, \text{kernel_size[1]})` ,其中 `group` 是在通道上分割输入 `x` 的组数。 其中, :math:`ccor``cross-correlation <https://en.wikipedia.org/wiki/Cross-correlation>`_ :math:`C_{in}` 为输入通道数, :math:`j` 的范围从 :math:`0`:math:`C_{out} - 1` :math:`W_{ij}` 对应第 :math:`j` 个过滤器的第 :math:`i` 个通道, :math:`out_{j}` 对应输出的第 :math:`j` 个通道。 :math:`W_{ij}` 为卷积核的切片其shape为 :math:`(\text{kernel_size[0]},\text{kernel_size[1]})` ,其中 :math:`\text{kernel_size[0]}`:math:`\text{kernel_size[1]}` 是卷积核的高度和宽度。完整卷积核的shape为 :math:`(C_{out}, C_{in} / \text{group}, \text{kernel_size[0]}, \text{kernel_size[1]})` ,其中 `group` 是在通道上分割输入 `x` 的组数。
如果 `pad_mode` 设置为"valid",则输出高度和宽度将分别为 :math:`\left \lfloor{1 + \frac{H_{in} + \text{padding[0]} + \text{padding[1]} - \text{kernel_size[0]} - (\text{kernel_size[0]} - 1) \times (\text{dilation[0]} - 1) }{\text{stride[0]}}} \right \rfloor`:math:`\left \lfloor{1 + \frac{W_{in} + \text{padding[2]} + \text{padding[3]} - \text{kernel_size[1]} - (\text{kernel_size[1]} - 1) \times (\text{dilation[1]} - 1) }{\text{stride[1]}}} \right \rfloor` 如果 `pad_mode` 设置为"pad",则输出高度和宽度将分别为 :math:`\left \lfloor{1 + \frac{H_{in} + \text{padding[0]} + \text{padding[1]} - \text{kernel_size[0]} - (\text{kernel_size[0]} - 1) \times (\text{dilation[0]} - 1) }{\text{stride[0]}}} \right \rfloor`:math:`\left \lfloor{1 + \frac{W_{in} + \text{padding[2]} + \text{padding[3]} - \text{kernel_size[1]} - (\text{kernel_size[1]} - 1) \times (\text{dilation[1]} - 1) }{\text{stride[1]}}} \right \rfloor`
其中, :math:`dialtion` 为卷积核元素之间的间距, :math:`stride` 为移动步长, :math:`padding` 为添加到输入两侧的零填充。 其中, :math:`dialtion` 为卷积核元素之间的间距, :math:`stride` 为移动步长, :math:`padding` 为添加到输入两侧的零填充。
请参考论文 `Gradient Based Learning Applied to Document Recognition <http://vision.stanford.edu/cs598_spring07/papers/Lecun98.pdf>`_ 。更详细的介绍参见http://cs231n.github.io/convolutional-networks/。 请参考论文 `Gradient Based Learning Applied to Document Recognition <http://vision.stanford.edu/cs598_spring07/papers/Lecun98.pdf>`_ 。更详细的介绍参见http://cs231n.github.io/convolutional-networks/。

View File

@ -195,28 +195,28 @@ class Conv2d(_Conv):
.. math:: .. math::
\begin{array}{ll} \\ \begin{array}{ll} \\
H_{out} \left \lfloor{\frac{H_{in}}{\text{stride[0]}} + 1} \right \rfloor \\ H_{out} \left \lceil{\frac{H_{in}}{\text{stride[0]}}} \right \rceil \\
W_{out} \left \lfloor{\frac{W_{in}}{\text{stride[1]}} + 1} \right \rfloor \\ W_{out} \left \lceil{\frac{W_{in}}{\text{stride[1]}}} \right \rceil \\
\end{array} \end{array}
pad_mode is 'valid': pad_mode is 'valid':
.. math:: .. math::
\begin{array}{ll} \\ \begin{array}{ll} \\
H_{out} \left \lfloor{\frac{H_{in} - \text{dilation[0]} \times (\text{kernel_size[0]} - 1) } H_{out} \left \lceil{\frac{H_{in} - \text{dilation[0]} \times (\text{kernel_size[0]} - 1) }
{\text{stride[0]}} + 1} \right \rfloor \\ {\text{stride[0]}}} \right \rceil \\
W_{out} \left \lfloor{\frac{W_{in} - \text{dilation[1]} \times (\text{kernel_size[1]} - 1) } W_{out} \left \lceil{\frac{W_{in} - \text{dilation[1]} \times (\text{kernel_size[1]} - 1) }
{\text{stride[1]}} + 1} \right \rfloor \\ {\text{stride[1]}}} \right \rceil \\
\end{array} \end{array}
pad_mode is 'pad': pad_mode is 'pad':
.. math:: .. math::
\begin{array}{ll} \\ \begin{array}{ll} \\
H_{out} \left \lfloor{\frac{H_{in} + padding[0] + padding[1] - (\text{dilation[0]} - 1) \times H_{out} \left \lfloor{\frac{H_{in} + padding[0] + padding[1] - (\text{kernel_size[0]} - 1) \times
\text{kernel_size[0]} - 1 }{\text{stride[0]}} + 1} \right \rfloor \\ \text{dilation[0]} - 1 }{\text{stride[0]}} + 1} \right \rfloor \\
W_{out} \left \lfloor{\frac{W_{in} + padding[2] + padding[3] - (\text{dilation[1]} - 1) \times W_{out} \left \lfloor{\frac{W_{in} + padding[2] + padding[3] - (\text{kernel_size[1]} - 1) \times
\text{kernel_size[1]} - 1 }{\text{stride[1]}} + 1} \right \rfloor \\ \text{dilation[1]} - 1 }{\text{stride[1]}} + 1} \right \rfloor \\
\end{array} \end{array}
Raises: Raises:
@ -1223,19 +1223,19 @@ class Conv1dTranspose(_Conv):
pad_mode is 'same': pad_mode is 'same':
.. math:: .. math::
L_{out} \left \lfloor{\frac{L_{in}}{\text{stride}} + 1} \right \rfloor L_{out} \left \lceil{\frac{L_{in}}{\text{stride}}} \right \rceil
pad_mode is 'valid': pad_mode is 'valid':
.. math:: .. math::
L_{out} \left \lfloor{\frac{L_{in} - \text{dilation} \times (\text{kernel_size} - 1) } L_{out} \left \lceil{\frac{L_{in} - \text{dilation} \times (\text{kernel_size} - 1) }
{\text{stride}} + 1} \right \rfloor {\text{stride}}} \right \rceil
pad_mode is 'pad': pad_mode is 'pad':
.. math:: .. math::
L_{out} \left \lfloor{\frac{L_{in} + 2 \times padding - (\text{dilation} - 1) \times L_{out} \left \lfloor{\frac{L_{in} + 2 \times padding - (\text{kernel_size} - 1) \times
\text{kernel_size} - 1 }{\text{stride}} + 1} \right \rfloor \text{dilation} - 1 }{\text{stride}} + 1} \right \rfloor
Raises: Raises:
TypeError: If `in_channels`, `out_channels`, `kernel_size`, `stride`, `padding` or `dilation` is not an int. TypeError: If `in_channels`, `out_channels`, `kernel_size`, `stride`, `padding` or `dilation` is not an int.

View File

@ -1280,7 +1280,7 @@ class Conv2D(Primitive):
:math:`(C_{out}, C_{in} / \text{group}, \text{kernel_size[0]}, \text{kernel_size[1]})`, :math:`(C_{out}, C_{in} / \text{group}, \text{kernel_size[0]}, \text{kernel_size[1]})`,
where group is the group number to split the input in the channel dimension. where group is the group number to split the input in the channel dimension.
If the 'pad_mode' is set to be "valid", the output height and width will be If the 'pad_mode' is set to be "pad", the output height and width will be
:math:`\left \lfloor{1 + \frac{H_{in} + \text{padding[0]} + \text{padding[1]} - \text{kernel_size[0]} - :math:`\left \lfloor{1 + \frac{H_{in} + \text{padding[0]} + \text{padding[1]} - \text{kernel_size[0]} -
(\text{kernel_size[0]} - 1) \times (\text{dilation[0]} - 1) }{\text{stride[0]}}} \right \rfloor` and (\text{kernel_size[0]} - 1) \times (\text{dilation[0]} - 1) }{\text{stride[0]}}} \right \rfloor` and
:math:`\left \lfloor{1 + \frac{W_{in} + \text{padding[2]} + \text{padding[3]} - \text{kernel_size[1]} - :math:`\left \lfloor{1 + \frac{W_{in} + \text{padding[2]} + \text{padding[3]} - \text{kernel_size[1]} -