Skip to content

BSConv

BSConv1d

Bases: Module

BSConv1d implements the BSConv concept which is based on the paper BSConv: Binarized Separated Convolutional Neural Networks.

BSConv is an amalgamation of depthwise separable convolution and pointwise convolution. Depthwise separable convolution utilizes far fewer parameters by separating the spatial (depthwise) and channel-wise (pointwise) operations. Meanwhile, pointwise convolution helps in transforming the channel characteristics without considering the channel's context.

Parameters:

Name Type Description Default
channels_in int

Number of input channels

required
channels_out int

Number of output channels produced by the convolution

required
kernel_size int

Size of the kernel used in depthwise convolution

required
padding int

Zeropadding added around the input tensor along the height and width directions

required

Attributes:

Name Type Description
pointwise PointwiseConv1d

Pointwise convolution module

depthwise DepthWiseConv1d

Depthwise separable convolution module

Source code in models/tts/delightful_tts/conv_blocks/bsconv.py
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
class BSConv1d(Module):
    r"""`BSConv1d` implements the `BSConv` concept which is based on the paper [BSConv:
    Binarized Separated Convolutional Neural Networks](https://arxiv.org/pdf/2003.13549.pdf).

    `BSConv` is an amalgamation of depthwise separable convolution and pointwise convolution.
    Depthwise separable convolution utilizes far fewer parameters by separating the spatial
    (depthwise) and channel-wise (pointwise) operations. Meanwhile, pointwise convolution
    helps in transforming the channel characteristics without considering the channel's context.

    Args:
        channels_in (int): Number of input channels
        channels_out (int): Number of output channels produced by the convolution
        kernel_size (int): Size of the kernel used in depthwise convolution
        padding (int): Zeropadding added around the input tensor along the height and width directions

    Attributes:
        pointwise (PointwiseConv1d): Pointwise convolution module
        depthwise (DepthWiseConv1d): Depthwise separable convolution module
    """

    def __init__(
        self,
        channels_in: int,
        channels_out: int,
        kernel_size: int,
        padding: int,
    ):
        super().__init__()

        # Instantiate Pointwise Convolution Module:
        # First operation in BSConv: the number of input channels is transformed to the number
        # of output channels without taking into account the channel context.
        self.pointwise = PointwiseConv1d(channels_in, channels_out)

        # Instantiate Depthwise Convolution Module:
        # Second operation in BSConv: A spatial convolution is performed independently over each output
        # channel from the pointwise convolution.
        self.depthwise = DepthWiseConv1d(
            channels_out,
            channels_out,
            kernel_size=kernel_size,
            padding=padding,
        )

    def forward(self, x: torch.Tensor) -> torch.Tensor:
        # Propagate input tensor through pointwise convolution.
        x1 = self.pointwise(x)

        # Propagate the result of the previous pointwise convolution through the depthwise convolution.
        # Return final output of the sequence of pointwise and depthwise convolutions
        return self.depthwise(x1)