def __init__(self, num_fields, channels=[3], kernel_heights=[3], activation='Tanh'):
    super(CCPM_ConvLayer, self).__init__()
    if (not isinstance(kernel_heights, list)):
        kernel_heights = ([kernel_heights] * len(channels))
    elif (len(kernel_heights) != len(channels)):
        raise ValueError('channels={} and kernel_heights={} should have the same length.'.format(channels, kernel_heights))
    module_list = []
    self.channels = ([1] + channels)
    layers = len(kernel_heights)
    for i in range(1, len(self.channels)):
        in_channels = self.channels[(i - 1)]
        out_channels = self.channels[i]
        kernel_height = kernel_heights[(i - 1)]
        module_list.append(nn.ZeroPad2d((0, 0, (kernel_height - 1), (kernel_height - 1))))
        module_list.append(nn.Conv2d(in_channels, out_channels, kernel_size=(kernel_height, 1)))
        if (i < layers):
            k = max(3, int(((1 - pow((float(i) / layers), (layers - i))) * num_fields)))
        else:
            k = 3
        module_list.append(KMaxPooling(k, dim=2))
        module_list.append(get_activation(activation))
    self.conv_layer = nn.Sequential(*module_list)
def __init__(self, num_fields, channels=[3], kernel_heights=[3], activation='Tanh'):
    super(CCPM_ConvLayer, self).__init__()
    if (not isinstance(kernel_heights, list)):
        kernel_heights = ([kernel_heights] * len(channels))
    elif (len(kernel_heights) != len(channels)):
        raise ValueError('channels={} and kernel_heights={} should have the same length.'.format(channels, kernel_heights))
    module_list = []
    self.channels = ([1] + channels)
    layers = len(kernel_heights)
    for i in range(1, len(self.channels)):
        in_channels = self.channels[(i - 1)]
        out_channels = self.channels[i]
        kernel_height = kernel_heights[(i - 1)]
        module_list.append(nn.ZeroPad2d((0, 0, (kernel_height - 1), (kernel_height - 1))))
        module_list.append(nn.Conv2d(in_channels, out_channels, kernel_size=(kernel_height, 1)))
        if (i < layers):
            k = max(3, int(((1 - pow((float(i) / layers), (layers - i))) * num_fields)))
        else:
            k = 3
        module_list.append(KMaxPooling(k, dim=2))
        module_list.append(get_activation(activation))
    self.conv_layer = nn.Sequential(*module_list)