Exemplo n.º 1
0
    def __init__(
        self,
        inp_filters: int,
        out_filters: int,
        group_scale: int = 8,
        se_channels: int = 128,
        kernel_size: int = 1,
        dilation: int = 1,
        init_mode: str = 'xavier_uniform',
    ):
        super().__init__()
        self.out_filters = out_filters
        padding_val = get_same_padding(kernel_size=kernel_size,
                                       dilation=dilation,
                                       stride=1)

        group_conv = nn.Conv1d(
            out_filters,
            out_filters,
            kernel_size=kernel_size,
            dilation=dilation,
            padding=padding_val,
            groups=group_scale,
        )
        self.group_tdnn_block = nn.Sequential(
            TDNNModule(inp_filters, out_filters, kernel_size=1, dilation=1),
            group_conv,
            nn.ReLU(),
            nn.BatchNorm1d(out_filters),
            TDNNModule(out_filters, out_filters, kernel_size=1, dilation=1),
        )

        self.se_layer = MaskedSEModule(out_filters, se_channels, out_filters)

        self.apply(lambda x: init_weights(x, mode=init_mode))
Exemplo n.º 2
0
    def __init__(
        self,
        inp_filters: int,
        out_filters: int,
        kernel_size: int = 1,
        dilation: int = 1,
        stride: int = 1,
        padding: int = None,
    ):
        super().__init__()
        if padding is None:
            padding = get_same_padding(kernel_size,
                                       stride=stride,
                                       dilation=dilation)

        self.conv_layer = nn.Conv1d(
            in_channels=inp_filters,
            out_channels=out_filters,
            kernel_size=kernel_size,
            dilation=dilation,
            padding=padding,
        )

        self.activation = nn.ReLU()
        self.bn = nn.BatchNorm1d(out_filters)
Exemplo n.º 3
0
    def test_padding_size_conv1d(self):
        input_channels = 1
        output_channels = 1
        kernel_sizes = [3, 7, 11]
        dilation_sizes = [2, 3, 4]
        stride = 1
        inp = torch.rand(2, 1, 40)

        for kernel_size in kernel_sizes:
            for dilation_size in dilation_sizes:
                padding = jasper.get_same_padding(kernel_size, stride, dilation_size)

                conv = torch.nn.Conv1d(
                    input_channels, output_channels, kernel_size=kernel_size, dilation=dilation_size, padding=padding
                )

                out = conv(inp)
                assert out.shape == inp.shape