speechbrain.nnet.complex_networks.c_CNN 模块

实现复值卷积神经网络的库。

作者
  • Titouan Parcollet 2020

摘要

CConv1d

此函数实现复值一维卷积。

CConv2d

此函数实现复值一维卷积。

参考

class speechbrain.nnet.complex_networks.c_CNN.CConv1d(out_channels, kernel_size, input_shape, stride=1, dilation=1, padding='same', groups=1, bias=True, padding_mode='reflect', init_criterion='glorot', weight_init='complex')[source]

基类:Module

此函数实现复值一维卷积。

参数:
  • out_channels (int) – 输出通道数。请注意,这些是复值神经元。如果指定 256 个通道,则输出维度将是 512。

  • kernel_size (int) – 卷积核大小。

  • input_shape (tuple) – 输入张量的预期形状。

  • stride (int, optional) – 卷积滤波器的步长因子(默认为 1)。

  • dilation (int, optional) – 卷积滤波器的扩张因子(默认为 1)。

  • padding (str, optional) – (same, valid, causal)。如果为“valid”,则不执行填充。如果为“same”且步长为 1,则输出形状与输入形状相同。“causal”导致因果(扩张)卷积。(默认为“same”)

  • groups (int, optional) – 此选项指定卷积组。更多信息请参见 torch.nn 文档(默认为 1)。

  • bias (bool, optional) – 如果为 True,则采用加性偏置 b(默认为 True)。

  • padding_mode (str, optional) – 此标志指定填充类型。更多信息请参见 torch.nn 文档(默认为“reflect”)。

  • init_criterion (str, optional) – (glorot, he)。此参数控制权重的初始化准则。它与 weights_init 结合用于构建复值权重的初始化方法(默认为“glorot”)。

  • weight_init (str, optional) – (complex, unitary)。此参数定义复值权重的初始化过程。“complex”将根据 init_criterion 和复数极坐标形式生成随机复值权重。“unitary”将权重归一化到单位圆上。(默认为“complex”)更多详情请参阅:“Deep Complex Networks”,Trabelsi C. et al.

示例

>>> inp_tensor = torch.rand([10, 16, 30])
>>> cnn_1d = CConv1d(
...     input_shape=inp_tensor.shape, out_channels=12, kernel_size=5
... )
>>> out_tensor = cnn_1d(inp_tensor)
>>> out_tensor.shape
torch.Size([10, 16, 24])
forward(x)[source]

返回卷积的输出。

参数:

x (torch.Tensor) – (batch, time, channel)。要进行卷积的输入。预期为 3d 或 4d 张量。

返回:

wx – 卷积输出。

返回类型:

torch.Tensor

class speechbrain.nnet.complex_networks.c_CNN.CConv2d(out_channels, kernel_size, input_shape, stride=1, dilation=1, padding='same', groups=1, bias=True, padding_mode='reflect', init_criterion='glorot', weight_init='complex')[source]

基类:Module

此函数实现复值一维卷积。

参数:
  • out_channels (int) – 输出通道数。请注意,这些是复值神经元。如果指定 256 个通道,则输出维度将是 512。

  • kernel_size (int) – 卷积核大小。

  • input_shape (tuple) – 输入的预期形状。

  • stride (int, optional) – 卷积滤波器的步长因子(默认为 1)。

  • dilation (int, optional) – 卷积滤波器的扩张因子(默认为 1)。

  • padding (str, optional) – (same, valid, causal)。如果为“valid”,则不执行填充。如果为“same”且步长为 1,则输出形状与输入形状相同。“causal”导致因果(扩张)卷积。(默认为“same”)

  • groups (int, optional) – 此选项指定卷积组(默认为 1)。更多信息请参见 torch.nn 文档。

  • bias (bool, optional) – 如果为 True,则采用加性偏置 b(默认为 True)。

  • padding_mode (str, optional) – 此标志指定填充类型(默认为“reflect”)。更多信息请参见 torch.nn 文档。

  • init_criterion (str , optional) – (glorot, he)。此参数控制权重的初始化准则(默认为“glorot”)。它与 weights_init 结合用于构建复值权重的初始化方法。

  • weight_init (str, optional) – (complex, unitary)。此参数定义复值权重的初始化过程(默认为 complex)。“complex”将根据 init_criterion 和复数极坐标形式生成随机复值权重。“unitary”将权重归一化到单位圆上。更多详情请参阅:“Deep Complex Networks”,Trabelsi C. et al.

示例

>>> inp_tensor = torch.rand([10, 16, 30, 30])
>>> cnn_2d = CConv2d(
...     input_shape=inp_tensor.shape, out_channels=12, kernel_size=5
... )
>>> out_tensor = cnn_2d(inp_tensor)
>>> out_tensor.shape
torch.Size([10, 16, 30, 24])
forward(x, init_params=False)[source]

返回卷积的输出。

参数:
  • x (torch.Tensor) – (batch, time, feature, channels)。要进行卷积的输入。预期为 3d 或 4d 张量。

  • init_params (bool) – 是否在此次传递中初始化参数。

返回:

x – 卷积的输出。

返回类型:

torch.Tensor