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.txt 4.6 kB

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