def __init__(self, in_channels, out_channels, kernel_size, stride, padding): super(ResidualLayer, self).__init__() self.conv1d_layer = nn.Sequential( nn.Conv1d( in_channels=in_channels, out_channels=out_channels, kernel_size=kernel_size, stride=1, padding=padding, ), nn.InstanceNorm1d(num_features=out_channels, affine=True), ) self.conv_layer_gates = nn.Sequential( nn.Conv1d( in_channels=in_channels, out_channels=out_channels, kernel_size=kernel_size, stride=1, padding=padding, ), nn.InstanceNorm1d(num_features=out_channels, affine=True), ) self.conv1d_out_layer = nn.Sequential( nn.Conv1d( in_channels=out_channels, out_channels=in_channels, kernel_size=kernel_size, stride=1, padding=padding, ), nn.InstanceNorm1d(num_features=in_channels, affine=True), )
def __init__( self, c_in, c_cond, c_h, c_out, kernel_size, n_conv_blocks, upsample, act, sn, dropout_rate, ): super(Decoder, self).__init__() self.n_conv_blocks = n_conv_blocks self.upsample = upsample self.act = get_act(act) f = lambda x: x self.in_conv_layer = f(nn.Conv1d(c_in, c_h, kernel_size=1)) self.first_conv_layers = nn.ModuleList([ f(nn.Conv1d(c_h, c_h, kernel_size=kernel_size)) for _ in range(n_conv_blocks) ]) self.second_conv_layers = nn.ModuleList([ f(nn.Conv1d(c_h, c_h * up, kernel_size=kernel_size)) for _, up in zip(range(n_conv_blocks), self.upsample) ]) self.norm_layer = nn.InstanceNorm1d(c_h, affine=False) self.conv_affine_layers = nn.ModuleList( [f(nn.Linear(c_cond, c_h * 2)) for _ in range(n_conv_blocks * 2)]) self.out_conv_layer = f(nn.Conv1d(c_h, c_out, kernel_size=1)) self.dropout_layer = nn.Dropout(p=dropout_rate)
def downsample(self, in_channels, out_channels, kernel_size, stride, padding): self.ConvLayer = nn.Sequential( nn.Conv1d( in_channels=in_channels, out_channels=out_channels, kernel_size=kernel_size, stride=stride, padding=padding, ), nn.InstanceNorm1d(num_features=out_channels, affine=True), GLU(), ) return self.ConvLayer
def __init__( self, c_in, c_h, c_out, kernel_size, bank_size, bank_scale, c_bank, n_conv_blocks, subsample, act, dropout_rate, ): super(ContentEncoder, self).__init__() self.n_conv_blocks = n_conv_blocks self.subsample = subsample self.act = get_act(act) self.conv_bank = nn.ModuleList([ nn.Conv1d(c_in, c_bank, kernel_size=k) for k in range(bank_scale, bank_size + 1, bank_scale) ]) in_channels = c_bank * (bank_size // bank_scale) + c_in self.in_conv_layer = nn.Conv1d(in_channels, c_h, kernel_size=1) self.first_conv_layers = nn.ModuleList([ nn.Conv1d(c_h, c_h, kernel_size=kernel_size) for _ in range(n_conv_blocks) ]) self.second_conv_layers = nn.ModuleList([ nn.Conv1d(c_h, c_h, kernel_size=kernel_size, stride=sub) for sub, _ in zip(subsample, range(n_conv_blocks)) ]) self.norm_layer = nn.InstanceNorm1d(c_h, affine=False) self.mean_layer = nn.Conv1d(c_h, c_out, kernel_size=1) self.std_layer = nn.Conv1d(c_h, c_out, kernel_size=1) self.dropout_layer = nn.Dropout(p=dropout_rate)
def __init__(self): super(Generator, self).__init__() # 2D Conv Layer self.conv1 = nn.Conv2d( in_channels=1, out_channels=128, kernel_size=(5, 15), stride=(1, 1), padding=(2, 7), ) self.conv1_gates = nn.Conv2d( in_channels=1, out_channels=128, kernel_size=(5, 15), stride=1, padding=(2, 7), ) # 2D Downsample Layer self.downSample1 = downSample_Generator(in_channels=128, out_channels=256, kernel_size=5, stride=2, padding=2) self.downSample2 = downSample_Generator(in_channels=256, out_channels=256, kernel_size=5, stride=2, padding=2) # 2D -> 1D Conv self.conv2dto1dLayer = nn.Sequential( nn.Conv1d(in_channels=2304, out_channels=256, kernel_size=1, stride=1, padding=0), nn.InstanceNorm1d(num_features=256, affine=True), ) # Residual Blocks self.residualLayer1 = ResidualLayer(in_channels=256, out_channels=512, kernel_size=3, stride=1, padding=1) self.residualLayer2 = ResidualLayer(in_channels=256, out_channels=512, kernel_size=3, stride=1, padding=1) self.residualLayer3 = ResidualLayer(in_channels=256, out_channels=512, kernel_size=3, stride=1, padding=1) self.residualLayer4 = ResidualLayer(in_channels=256, out_channels=512, kernel_size=3, stride=1, padding=1) self.residualLayer5 = ResidualLayer(in_channels=256, out_channels=512, kernel_size=3, stride=1, padding=1) self.residualLayer6 = ResidualLayer(in_channels=256, out_channels=512, kernel_size=3, stride=1, padding=1) # 1D -> 2D Conv self.conv1dto2dLayer = nn.Sequential( nn.Conv1d(in_channels=256, out_channels=2304, kernel_size=1, stride=1, padding=0), nn.InstanceNorm1d(num_features=2304, affine=True), ) # UpSample Layer self.upSample1 = self.upSample(in_channels=256, out_channels=1024, kernel_size=5, stride=1, padding=2) self.upSample2 = self.upSample(in_channels=256, out_channels=512, kernel_size=5, stride=1, padding=2) self.lastConvLayer = nn.Conv2d( in_channels=128, out_channels=1, kernel_size=(5, 15), stride=(1, 1), padding=(2, 7), )
def __init__(self, input_shape=(80, 64), residual_in_channels=256): super(Generator, self).__init__() Cx, Tx = input_shape self.flattened_channels = (Cx // 4) * residual_in_channels # 2D Conv Layer self.conv1 = nn.Conv2d( in_channels=2, out_channels=residual_in_channels // 2, kernel_size=(5, 15), stride=(1, 1), padding=(2, 7), ) self.conv1_gates = nn.Conv2d( in_channels=2, out_channels=residual_in_channels // 2, kernel_size=(5, 15), stride=1, padding=(2, 7), ) # 2D Downsampling Layers self.downSample1 = DownSampleGenerator( in_channels=residual_in_channels // 2, out_channels=residual_in_channels, kernel_size=5, stride=2, padding=2, ) self.downSample2 = DownSampleGenerator( in_channels=residual_in_channels, out_channels=residual_in_channels, kernel_size=5, stride=2, padding=2, ) # 2D -> 1D Conv self.conv2dto1dLayer = nn.Conv1d( in_channels=self.flattened_channels, out_channels=residual_in_channels, kernel_size=1, stride=1, padding=0, ) self.conv2dto1dLayer_tfan = nn.InstanceNorm1d( num_features=residual_in_channels, affine=True ) # Residual Blocks self.residualLayer1 = ResidualLayer( in_channels=residual_in_channels, out_channels=residual_in_channels * 2, kernel_size=3, stride=1, padding=1, ) self.residualLayer2 = ResidualLayer( in_channels=residual_in_channels, out_channels=residual_in_channels * 2, kernel_size=3, stride=1, padding=1, ) self.residualLayer3 = ResidualLayer( in_channels=residual_in_channels, out_channels=residual_in_channels * 2, kernel_size=3, stride=1, padding=1, ) self.residualLayer4 = ResidualLayer( in_channels=residual_in_channels, out_channels=residual_in_channels * 2, kernel_size=3, stride=1, padding=1, ) self.residualLayer5 = ResidualLayer( in_channels=residual_in_channels, out_channels=residual_in_channels * 2, kernel_size=3, stride=1, padding=1, ) self.residualLayer6 = ResidualLayer( in_channels=residual_in_channels, out_channels=residual_in_channels * 2, kernel_size=3, stride=1, padding=1, ) # 1D -> 2D Conv self.conv1dto2dLayer = nn.Conv1d( in_channels=residual_in_channels, out_channels=self.flattened_channels, kernel_size=1, stride=1, padding=0, ) self.conv1dto2dLayer_tfan = nn.InstanceNorm1d( num_features=self.flattened_channels, affine=True ) # UpSampling Layers self.upSample1 = self.upsample( in_channels=residual_in_channels, out_channels=residual_in_channels * 4, kernel_size=5, stride=1, padding=2, ) self.glu = GLU() self.upSample2 = self.upsample( in_channels=residual_in_channels, out_channels=residual_in_channels * 2, kernel_size=5, stride=1, padding=2, ) # 2D Conv Layer self.lastConvLayer = nn.Conv2d( in_channels=residual_in_channels // 2, out_channels=1, kernel_size=(5, 15), stride=(1, 1), padding=(2, 7), )