Conv3d

class Conv3d(in_channels, out_channels, kernel_size, stride=1, padding=0, dilation=1, groups=1, bias=True, conv_mode='cross_correlation')[源代码]

对输入 tensor 进行三维卷积

例如,给一个大小为 \((N, C_{\text{in}}, T, H, W)\) 的输出:

\[\text{out}(N_i, C_{\text{out}_j}) = \text{bias}(C_{\text{out}_j}) + \sum_{k = 0}^{C_{\text{in}} - 1} \text{weight}(C_{\text{out}_j}, k) \star \text{input}(N_i, k)\]

在此式子中 \(\star\) 是有效的 3D 互相关(cross-correlation) 运算符, \(N\) 是 batch 大小, \(C\) 表示 channels 数量。

groups == in_channelsout_channels == K * in_channels ,其中 K 是正整数,该操作也被称为深度方向卷积(depthwise convolution)。

In other words, for an input of size \((N, C_{\text{in}}, T_{\text{in}}, H_{\text{in}}, W_{\text{in}})\), a depthwise convolution with a depthwise multiplier K, can be constructed by arguments \((in\_channels=C_{\text{in}}, out\_channels=C_{\text{in}} \times K, ..., groups=C_{\text{in}})\).

参数
  • in_channels (int) – 输入数据中的通道数。

  • out_channels (int) – 输出数据中的通道数。

  • kernel_size (Union[int, Tuple[int, int, int]]) – 空间维度上的权重大小。如果kernel_size 是一个 int, 实际的kernel大小为 (kernel_size, kernel_size, kernel_size)

  • stride (Union[int, Tuple[int, int, int]]) – stride of the 3D convolution operation. Default: 1.

  • padding (Union[int, Tuple[int, int, int]]) – size of the paddings added to the input on both sides of its spatial dimensions. Only zero-padding is supported. Default: 0.

  • dilation (Union[int, Tuple[int, int, int]]) – dilation of the 3D convolution operation. Default: 1.

  • groups (int) – number of groups into which the input and output channels are divided, so as to perform a grouped convolution. When groups is not 1, in_channels and out_channels must be divisible by groups, and the shape of weight should be (groups, out_channel // groups, in_channels // groups, depth, height, width). Default: 1.

  • bias (bool) – whether to add a bias onto the result of convolution. Default: True.

  • conv_mode (str) – supports cross_correlation. Default: cross_correlation.

Shape:

input: \((N, C_{\text{in}}, T_{\text{in}}, H_{\text{in}}, W_{\text{in}})\). output: \((N, C_{\text{out}}, T_{\text{out}}, H_{\text{out}}, W_{\text{out}})\).

注解

  • weight 的shape通常是 (out_channels, in_channels, depth, height, width) , 如果 groups 不为1, shape 将是 (groups, out_channels // groups, in_channels // groups, depth, height, width)

  • bias 的shape通常是 (1, out_channels, *1)

返回

module. The instance of the Conv3d module.

返回类型

Return type

实际案例

>>> import numpy as np
>>> m = M.Conv3d(in_channels=3, out_channels=1, kernel_size=3)
>>> inp = mge.tensor(np.arange(0, 384).astype("float32").reshape(2, 3, 4, 4, 4))
>>> oup = m(inp)
>>> oup.numpy().shape
(2, 1, 2, 2, 2)