You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

mindspore.nn.Conv1d.rst 4.7 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. mindspore.nn.Conv1d
  2. ======================
  3. .. py:class:: mindspore.nn.Conv1d(in_channels, out_channels, kernel_size, stride=1, pad_mode='same', padding=0, dilation=1, group=1, has_bias=False, weight_init='normal', bias_init='zeros')
  4. 一维卷积层。
  5. 在输入Tensor上应用一维卷积,该Tensor的shape通常为 :math:`(N, C_{in}, W_{in})` ,其中 :math:`N` 是batch size, :math:`C_{in}` 是通道数。
  6. 对于每个batch中的Tensor,其shape为 :math:`(C_{in}, W_{in})` ,公式定义为:
  7. .. math::
  8. out_j = \sum_{i=0}^{C_{in} - 1} ccor(W_{ij}, X_i) + b_j,
  9. 其中, :math:`ccor` 为互关联算子, :math:`C_{in}` 为输入通道数, :math:`j` 的范围从 :math:`0` 到 :math:`C_{out} - 1` , :math:`W_{ij}` 对应第 :math:`j` 个过滤器的第 :math:`i` 个通道, :math:`out_{j}` 对应输出的第 :math:`j` 个通道。
  10. :math:`W_{ij}`是kernel的切片,它的shape为 :math:`(\text{ks_w})` ,其中 :math:`\text{ks_w}` 是卷积核的宽度。
  11. 完整kernel的shape为 :math:`(C_{out}, C_{in} // \text{group}, \text{ks_w})` ,其中group是在通道维度上分割输入 `x` 的组数。
  12. 如果'pad_mode'设置为"valid",则输出宽度将为 :math:`\left \lfloor{1 + \frac{W_{in} + 2 \times \text{padding} - \text{ks_w} - (\text{ks_w} - 1) \times (\text{dilation} - 1) }{\text{stride}}} \right \rfloor` 。
  13. 论文 `Gradient Based Learning Applied to Document Recognition <http://vision.stanford.edu/cs598_spring07/papers/Lecun98.pdf>`_ 首次提出卷积层。
  14. **参数:**
  15. - **in_channels** (int) - 输入通道数 :math:`C_{in}` 。
  16. - **out_channels** (int) - 输出通道数 :math:`C_{out}` 。
  17. - **kernel_size** (int) - 指定一维卷积核的宽度。
  18. - **stride** (int) - 步长大小,表示移到宽度。默认值:1。
  19. - **pad_mode** (str) - 指定填充模式。可选值为"same"、"valid"、"pad"。默认值:"same"。
  20. - same:采用补全方式。输出的宽度与输入 `x` 一致。填充总数将在水平上进行计算。并尽可能均匀分布到左侧和右侧。否则,最后一次将从底部和右侧进行额外的填充。若设置该模式,`padding` 必须为0。
  21. - valid:采用的丢弃方式。在不填充的前提下返回可能大的宽度的输出。多余的像素会被丢弃。如果设置此模式,则 `padding` 必须为0。
  22. - pad:输入 `x` 两侧的隐式填充。 `padding` 的数量将填充到输入Tensor边框上。 `padding` 必须大于或等于0。
  23. - **padding** (int) - 输入 `x` 两侧的隐式填充。默认值:0。
  24. - **dilation** (int) - 指定用于扩张卷积的扩张速率。如果设置为 :math:`k > 1` ,则每个采样位置都跳过 :math:`k - 1` 个像素。其值必须大于或等于1,并以输入 `x` 的宽度为界。默认值:1。
  25. - **group** (int) - 将过滤器拆分为组, `in_ channels` 和 `out_channels` 必须可被组数整除。默认值:1。
  26. - **has_bias** (bool) - 指定图层是否使用偏置矢量。默认值:False。
  27. - **weight_init** (Union[Tensor, str, Initializer, numbers.Number]) - 卷积核的初始化方法。它可以是Tensor,str,初始化实例或numbers.Number。当使用str时,可选“TruncatedNormal”,“Normal”,“Uniform”,“HeUniform”和“XavierUniform”分布以及常量“One”和“Zero”分布的值,可接受别名“ xavier_uniform”,“ he_uniform”,“ ones”和“ zeros”。上述字符串大小写均可。更多细节请参考Initializer的值。默认值:“normal”。
  28. - **bias_init** (Union[Tensor, str, Initializer, numbers.Number]) - 偏置向量的初始化方法。可以使用的初始化方法和字符串与“weight_init”相同。更多细节请参考Initializer的值。默认值:“zeros”。
  29. **输入:**
  30. - **x** (Tensor) - shape为 :math:`(N, C_{in}, W_{in})` 的Tensor。
  31. **输出:**
  32. Tensor,shape为:math:`(N, C_{out}, W_{out})`。
  33. **异常:**
  34. - **TypeError** - `in_channels` 、 `out_channels` 、 `kernel_size` 、 `stride` 、 `padding` 或 `dilation` 不是int。
  35. - **ValueError** - `in_channels` 、 `out_channels` 、 `kernel_size` 、 `stride` 或 `dilation` 小于1。
  36. - **ValueError** - `padding` 小于0。
  37. - **ValueError** - `pad_mode` 不是'same','valid',或'pad'。
  38. **支持平台:**
  39. ``Ascend`` ``GPU`` ``CPU``
  40. **样例:**
  41. >>> net = nn.Conv1d(120, 240, 4, has_bias=False, weight_init='normal')
  42. >>> x = Tensor(np.ones([1, 120, 640]), mindspore.float32)
  43. >>> output = net(x).shape
  44. >>> print(output)
  45. (1, 240, 640)