Python torch.nn.ConvTranspose1d() Examples
The following are 30
code examples of torch.nn.ConvTranspose1d().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
torch.nn
, or try the search function
.
Example #1
Source File: cls_fe_dct_bases.py From signaltrain with GNU General Public License v3.0 | 6 votes |
def __init__(self, ft_size=1024, w_size=2048, hop_size=1024): super(Synthesis, self).__init__() # Parameters self.batch_size = None self.time_domain_samples = None self.sz = ft_size self.wsz = w_size self.hop = hop_size self.half_N = int(self.sz / 2 + 1) # Synthesis 1D CNN self.conv_synthesis = nn.ConvTranspose1d(self.sz, 1, self.wsz, padding=0, stride=self.hop, bias=False) # Activation functions self.h_tanh = torch.nn.Hardtanh() self.tanh = torch.nn.Tanh() # Custom Initialization with DCT-TypeIV matrix self.initialize()
Example #2
Source File: modules.py From pase with MIT License | 6 votes |
def __init__(self, ninp, fmaps, kwidth, stride=4, norm_type=None, act=None, bias=True, name='GDeconv1DBlock'): super().__init__(name=name) if act is not None and act == 'glu': Wfmaps = 2 * fmaps else: Wfmaps = fmaps pad = max(0, (stride - kwidth)//-2) self.deconv = nn.ConvTranspose1d(ninp, Wfmaps, kwidth, stride=stride, padding=pad, bias=bias) self.norm = build_norm_layer(norm_type, self.deconv, Wfmaps) self.act = build_activation(act, fmaps) self.kwidth = kwidth self.stride = stride
Example #3
Source File: modules.py From pase with MIT License | 6 votes |
def __init__(self, ninp, fmaps, kwidth, stride=4, norm_type=None, act=None, name='GDeconv1DBlock'): super().__init__(name=name) pad = max(0, (stride - kwidth)//-2) self.deconv = nn.ConvTranspose1d(ninp, fmaps, kwidth, stride=stride, padding=pad) self.norm = build_norm_layer(norm_type, self.deconv, fmaps) if act is not None: self.act = getattr(nn, act)() else: self.act = nn.PReLU(fmaps, init=0) self.kwidth = kwidth self.stride = stride
Example #4
Source File: cls_fe_dft.py From signaltrain with GNU General Public License v3.0 | 6 votes |
def __init__(self, ft_size=1024, hop_size=384): super(Synthesis, self).__init__() # Parameters self.batch_size = None self.time_domain_samples = None self.sz = ft_size self.hop = hop_size self.half_N = int(self.sz / 2 + 1) # Synthesis 1D CNN self.conv_synthesis_real = nn.ConvTranspose1d(self.sz, 1, self.sz, padding=0, stride=self.hop, bias=False) self.conv_synthesis_imag = nn.ConvTranspose1d(self.sz, 1, self.sz, padding=0, stride=self.hop, bias=False) # Custom Initialization with Fourier matrix self.initialize()
Example #5
Source File: model.py From graph-generation with MIT License | 6 votes |
def __init__(self, input_size, output_size, stride, hops): super(CNN_decoder_share, self).__init__() self.input_size = input_size self.output_size = output_size self.hops = hops self.relu = nn.ReLU() self.deconv = nn.ConvTranspose1d(in_channels=int(self.input_size), out_channels=int(self.input_size), kernel_size=3, stride=stride) self.bn = nn.BatchNorm1d(int(self.input_size)) self.deconv_out = nn.ConvTranspose1d(in_channels=int(self.input_size), out_channels=int(self.output_size), kernel_size=3, stride=1, padding=1) for m in self.modules(): if isinstance(m, nn.ConvTranspose1d): # n = m.kernel_size[0] * m.kernel_size[1] * m.out_channels # m.weight.dataset.normal_(0, math.sqrt(2. / n)) m.weight.data = init.xavier_uniform(m.weight.data, gain=nn.init.calculate_gain('relu')) elif isinstance(m, nn.BatchNorm1d): m.weight.data.fill_(1) m.bias.data.zero_()
Example #6
Source File: waveunet_utils.py From Wave-U-Net-Pytorch with MIT License | 6 votes |
def __init__(self, n_inputs, n_outputs, kernel_size, stride, conv_type, transpose=False): super(ConvLayer, self).__init__() self.transpose = transpose self.stride = stride self.kernel_size = kernel_size self.conv_type = conv_type # How many channels should be normalised as one group if GroupNorm is activated # WARNING: Number of channels has to be divisible by this number! NORM_CHANNELS = 8 if self.transpose: self.filter = nn.ConvTranspose1d(n_inputs, n_outputs, self.kernel_size, stride, padding=kernel_size-1) else: self.filter = nn.Conv1d(n_inputs, n_outputs, self.kernel_size, stride) if conv_type == "gn": assert(n_outputs % NORM_CHANNELS == 0) self.norm = nn.GroupNorm(n_outputs // NORM_CHANNELS, n_outputs) elif conv_type == "bn": self.norm = nn.BatchNorm1d(n_outputs, momentum=0.01) # Add you own types of variations here!
Example #7
Source File: modules.py From segan_pytorch with MIT License | 6 votes |
def __init__(self, ninp, fmaps, kwidth, stride=4, bias=True, norm_type=None, act=None): super().__init__() pad = max(0, (stride - kwidth)//-2) self.deconv = nn.ConvTranspose1d(ninp, fmaps, kwidth, stride=stride, padding=pad) self.norm = build_norm_layer(norm_type, self.deconv, fmaps) if act is not None: self.act = getattr(nn, act)() else: self.act = nn.PReLU(fmaps, init=0) self.kwidth = kwidth self.stride = stride
Example #8
Source File: model.py From GraphRNN with MIT License | 6 votes |
def __init__(self, input_size, output_size, stride, hops): super(CNN_decoder_share, self).__init__() self.input_size = input_size self.output_size = output_size self.hops = hops self.relu = nn.ReLU() self.deconv = nn.ConvTranspose1d(in_channels=int(self.input_size), out_channels=int(self.input_size), kernel_size=3, stride=stride) self.bn = nn.BatchNorm1d(int(self.input_size)) self.deconv_out = nn.ConvTranspose1d(in_channels=int(self.input_size), out_channels=int(self.output_size), kernel_size=3, stride=1, padding=1) for m in self.modules(): if isinstance(m, nn.ConvTranspose1d): # n = m.kernel_size[0] * m.kernel_size[1] * m.out_channels # m.weight.dataset.normal_(0, math.sqrt(2. / n)) m.weight.data = init.xavier_uniform(m.weight.data, gain=nn.init.calculate_gain('relu')) elif isinstance(m, nn.BatchNorm1d): m.weight.data.fill_(1) m.bias.data.zero_()
Example #9
Source File: nn.py From samplernn-pytorch with MIT License | 6 votes |
def __init__(self, in_channels, out_channels, kernel_size, bias=True): super().__init__() self.conv_t = nn.ConvTranspose1d( in_channels=in_channels, out_channels=out_channels, kernel_size=kernel_size, stride=kernel_size, bias=False ) if bias: self.bias = nn.Parameter( torch.FloatTensor(out_channels, kernel_size) ) else: self.register_parameter('bias', None) self.reset_parameters()
Example #10
Source File: nnBuildUnits.py From medSynthesisV1 with MIT License | 6 votes |
def __init__(self, in_channels, out_channels, kernel_size, stride=1, padding=0, output_padding=0, groups=1, bias=True, dilation=1, nd=2): super(convTranspose23D_bn_Unit, self).__init__() assert nd==1 or nd==2 or nd==3, 'nd is not correctly specified!!!!, it should be {1,2,3}' if nd==2: self.conv = nn.ConvTranspose2d(in_channels, out_channels, kernel_size, stride=stride, padding=padding, output_padding=output_padding, groups=groups, bias=bias, dilation=dilation) self.bn = nn.BatchNorm2d(out_channels) elif nd==3: self.conv = nn.ConvTranspose3d(in_channels, out_channels, kernel_size, stride=stride, padding=padding, output_padding=output_padding, groups=groups, bias=bias, dilation=dilation) self.bn = nn.BatchNorm3d(out_channels) else: self.conv = nn.ConvTranspose1d(in_channels, out_channels, kernel_size, stride=stride, padding=padding, output_padding=output_padding, groups=groups, bias=bias, dilation=dilation) self.bn = nn.BatchNorm1d(out_channels) init.xavier_uniform(self.conv.weight, gain = np.sqrt(2.0)) init.constant(self.conv.bias, 0) # self.relu = nn.ReLU()
Example #11
Source File: nnBuildUnits.py From medSynthesisV1 with MIT License | 6 votes |
def __init__(self, in_channels, out_channels, kernel_size, stride=1, padding=0, output_padding=0, groups=1, bias=True, dilation=1, nd=2): super(convTranspose23D_bn_relu_Unit, self).__init__() assert nd==1 or nd==2 or nd==3, 'nd is not correctly specified!!!!, it should be {1,2,3}' if nd==2: self.conv = nn.ConvTranspose2d(in_channels, out_channels, kernel_size, stride=stride, padding=padding, output_padding=output_padding, groups=groups, bias=bias, dilation=dilation) self.bn = nn.BatchNorm2d(out_channels) elif nd==3: self.conv = nn.ConvTranspose3d(in_channels, out_channels, kernel_size, stride=stride, padding=padding, output_padding=output_padding, groups=groups, bias=bias, dilation=dilation) self.bn = nn.BatchNorm3d(out_channels) else: self.conv = nn.ConvTranspose1d(in_channels, out_channels, kernel_size, stride=stride, padding=padding, output_padding=output_padding, groups=groups, bias=bias, dilation=dilation) self.bn = nn.BatchNorm1d(out_channels) init.xavier_uniform(self.conv.weight, gain = np.sqrt(2.0)) init.constant(self.conv.bias, 0) self.relu = nn.ReLU()
Example #12
Source File: model.py From vae-audio with MIT License | 5 votes |
def spec_deconv1d(n_layer=3, n_channel=[64, 32, 16, 8], filter_size=[1, 3, 3], stride=[1, 2, 2]): """ Construction of deconv. layers. Input the arguments in normal conv. order. E.g., n_channel = [1, 32, 16, 8] gives deconv. layers of [8, 16, 32, 1]. :param n_layer: number of deconv. layers :param n_channel: in/output number of channels for each layer ( len(n_channel) = n_layer + 1 ) The first channel is the number of freqeuncy bands of input spectrograms :param filter_size: the filter size (x-axis) for each layer ( len(filter_size) = n_layer ) :param stride: filter stride size (x-axis) for each layer ( len(stride) = n_layer ) :return: an object (nn.Sequential) constructed of specified deconv. layers. TODO: [x] directly use nn.Conv1d for implementation [] allow different activations and batch normalization functions """ assert len(n_channel) == n_layer + 1, "This must fulfill: len(n_channel) = n_layer + 1" ast_msg = "The following must fulfill: len(filter_size) == len(stride) == n_layer" assert len(filter_size) == len(stride) == n_layer, ast_msg n_channel, filter_size, stride = n_channel[::-1], filter_size[::-1], stride[::-1] deconv_layers = [] for i in range(n_layer - 1): in_channel, out_channel = n_channel[i:i + 2] deconv_layers += [ nn.ConvTranspose1d(in_channel, out_channel, filter_size[i], stride[i]), nn.BatchNorm1d(out_channel), nn.Tanh() ] # Construct the output layer deconv_layers += [ nn.ConvTranspose1d(n_channel[-2], n_channel[-1], filter_size[-1], stride[-1]), nn.Tanh() # check the effect of with or without BatchNorm in this layer ] return nn.Sequential(*deconv_layers)
Example #13
Source File: model.py From demucs with MIT License | 5 votes |
def rescale_module(module, reference): for sub in module.modules(): if isinstance(sub, (nn.Conv1d, nn.ConvTranspose1d)): rescale_conv(sub, reference)
Example #14
Source File: model.py From vae-audio with MIT License | 5 votes |
def __init__(self, input_size=(128, 20), latent_dim=16, n_component=12, pow_exp=0, logvar_trainable=False, is_featExtract=False): super(Conv1dGMVAE, self).__init__(input_size, latent_dim, n_component, is_featExtract) self.n_channel = input_size[0] self.pow_exp, self.logvar_trainable = pow_exp, logvar_trainable self._build_logvar_lookup(pow_exp=pow_exp, logvar_trainable=logvar_trainable) self.encoder = nn.Sequential( nn.Conv1d(self.n_channel, 512, 3, 1), nn.BatchNorm1d(512), nn.ReLU(), nn.Conv1d(512, 512, 3, 1), nn.BatchNorm1d(512), nn.ReLU() ) self.flat_size, self.encoder_outputSize = self._infer_flat_size() self.encoder_fc = nn.Sequential( nn.Linear(self.flat_size, 512), nn.BatchNorm1d(512), nn.ReLU() ) self.lin_mu = nn.Linear(512, latent_dim) self.lin_logvar = nn.Linear(512, latent_dim) self.decoder_fc = nn.Sequential( nn.Linear(latent_dim, 512), nn.BatchNorm1d(512), nn.ReLU(), nn.Linear(512, self.flat_size), nn.BatchNorm1d(self.flat_size), nn.ReLU() ) self.decoder = nn.Sequential( nn.ConvTranspose1d(512, 512, 3, 1), nn.BatchNorm1d(512), nn.ReLU(), nn.ConvTranspose1d(512, self.n_channel, 3, 1), nn.Tanh() )
Example #15
Source File: nnBuildUnits.py From medSynthesisV1 with MIT License | 5 votes |
def __init__(self, in_channels, out_channels, kernel_size, stride=1, padding=0, output_padding=0, groups=1, bias=True, dilation=1, nd=2): super(convTranspose23DUnit, self).__init__() assert nd==1 or nd==2 or nd==3, 'nd is not correctly specified!!!!, it should be {1,2,3}' if nd==2: self.conv = nn.ConvTranspose2d(in_channels, out_channels, kernel_size, stride=stride, padding=padding, output_padding=output_padding, groups=groups, bias=bias, dilation=dilation) elif nd==3: self.conv = nn.ConvTranspose3d(in_channels, out_channels, kernel_size, stride=stride, padding=padding, output_padding=output_padding, groups=groups, bias=bias, dilation=dilation) else: self.conv = nn.ConvTranspose1d(in_channels, out_channels, kernel_size, stride=stride, padding=padding, output_padding=output_padding, groups=groups, bias=bias, dilation=dilation) init.xavier_uniform(self.conv.weight, gain = np.sqrt(2.0)) init.constant(self.conv.bias, 0)
Example #16
Source File: sagan_models.py From RL-GAN-Net with MIT License | 5 votes |
def __init__(self, batch_size=64, image_size=64, conv_dim=64): super(Discriminator, self).__init__() self.imsize = image_size layer1 = [] layer2 = [] layer3 = [] last = [] layer1.append(SpectralNorm(nn.Conv2d(1, conv_dim, 3,2, 2))) layer1.append(nn.LeakyReLU(0.1)) curr_dim = conv_dim layer2.append(SpectralNorm(nn.Conv2d(curr_dim, curr_dim * 2, 3, 2, 2))) # 4,2,1 layer2.append(nn.LeakyReLU(0.1)) curr_dim = curr_dim * 2 layer3.append(SpectralNorm(nn.Conv2d(curr_dim, curr_dim * 2, 3, 2, 2))) layer3.append(nn.LeakyReLU(0.1)) curr_dim = curr_dim * 2 if self.imsize == 64: layer4 = [] layer4.append(SpectralNorm(nn.Conv2d(curr_dim, curr_dim * 2, 4, 2, 1))) layer4.append(nn.LeakyReLU(0.1)) self.l4 = nn.Sequential(*layer4) curr_dim = curr_dim*2 self.l1 = nn.Sequential(*layer1) self.l2 = nn.Sequential(*layer2) self.l3 = nn.Sequential(*layer3) last.append(nn.Conv2d(curr_dim, 1, 4)) self.last = nn.Sequential(*last) self.attn1 = Self_Attn(256, 'relu') self.attn2 = Self_Attn(512, 'relu') self.input1d2d = nn.ConvTranspose1d(128,144,1)#SpectralNorm(nn.ConvTranspose1d(128,144,1))
Example #17
Source File: self_D_net.py From RL-GAN-Net with MIT License | 5 votes |
def __init__(self, image_size=64, conv_dim=64): super(Discriminator, self).__init__() self.imsize = image_size layer1 = [] layer2 = [] layer3 = [] last = [] layer1.append(SpectralNorm(nn.Conv2d(1, conv_dim, 3,2, 2))) layer1.append(nn.LeakyReLU(0.1)) curr_dim = conv_dim layer2.append(SpectralNorm(nn.Conv2d(curr_dim, curr_dim * 2, 3, 2, 2))) # 4,2,1 layer2.append(nn.LeakyReLU(0.1)) curr_dim = curr_dim * 2 layer3.append(SpectralNorm(nn.Conv2d(curr_dim, curr_dim * 2, 3, 2, 2))) layer3.append(nn.LeakyReLU(0.1)) curr_dim = curr_dim * 2 if self.imsize == 64: layer4 = [] layer4.append(SpectralNorm(nn.Conv2d(curr_dim, curr_dim * 2, 4, 2, 1))) layer4.append(nn.LeakyReLU(0.1)) self.l4 = nn.Sequential(*layer4) curr_dim = curr_dim*2 self.l1 = nn.Sequential(*layer1) self.l2 = nn.Sequential(*layer2) self.l3 = nn.Sequential(*layer3) last.append(nn.Conv2d(curr_dim, 1, 4)) self.last = nn.Sequential(*last) self.attn1 = Self_Attn(256, 'relu') self.attn2 = Self_Attn(512, 'relu') self.input1d2d = nn.ConvTranspose1d(128,144,1)
Example #18
Source File: generator.py From melgan with BSD 3-Clause "New" or "Revised" License | 5 votes |
def __init__(self, mel_channel): super(Generator, self).__init__() self.mel_channel = mel_channel self.generator = nn.Sequential( nn.ReflectionPad1d(3), nn.utils.weight_norm(nn.Conv1d(mel_channel, 512, kernel_size=7, stride=1)), nn.LeakyReLU(0.2), nn.utils.weight_norm(nn.ConvTranspose1d(512, 256, kernel_size=16, stride=8, padding=4)), ResStack(256), nn.LeakyReLU(0.2), nn.utils.weight_norm(nn.ConvTranspose1d(256, 128, kernel_size=16, stride=8, padding=4)), ResStack(128), nn.LeakyReLU(0.2), nn.utils.weight_norm(nn.ConvTranspose1d(128, 64, kernel_size=4, stride=2, padding=1)), ResStack(64), nn.LeakyReLU(0.2), nn.utils.weight_norm(nn.ConvTranspose1d(64, 32, kernel_size=4, stride=2, padding=1)), ResStack(32), nn.LeakyReLU(0.2), nn.ReflectionPad1d(3), nn.utils.weight_norm(nn.Conv1d(32, 1, kernel_size=7, stride=1)), nn.Tanh(), )
Example #19
Source File: det_base.py From frustum-convnet with MIT License | 5 votes |
def __init__(self, i_c=128, num_vec=3): super(ConvFeatNet, self).__init__() self.block1_conv1 = Conv1d(i_c + num_vec, 128, 3, 1, 1) self.block2_conv1 = Conv1d(128, 128, 3, 2, 1) self.block2_conv2 = Conv1d(128, 128, 3, 1, 1) self.block2_merge = Conv1d(128 + 128 + num_vec, 128, 1, 1) self.block3_conv1 = Conv1d(128, 256, 3, 2, 1) self.block3_conv2 = Conv1d(256, 256, 3, 1, 1) self.block3_merge = Conv1d(256 + 256 + num_vec, 256, 1, 1) self.block4_conv1 = Conv1d(256, 512, 3, 2, 1) self.block4_conv2 = Conv1d(512, 512, 3, 1, 1) self.block4_merge = Conv1d(512 + 512 + num_vec, 512, 1, 1) self.block2_deconv = DeConv1d(128, 256, 1, 1, 0) self.block3_deconv = DeConv1d(256, 256, 2, 2, 0) self.block4_deconv = DeConv1d(512, 256, 4, 4, 0) for m in self.modules(): if isinstance(m, (nn.Conv1d, nn.ConvTranspose1d)): # nn.init.xavier_uniform_(m.weight.data) nn.init.kaiming_normal_(m.weight.data, mode='fan_in') if m.bias is not None: m.bias.data.zero_() if isinstance(m, nn.BatchNorm1d): m.weight.data.fill_(1) m.bias.data.zero_()
Example #20
Source File: modules.py From melgan-neurips with MIT License | 5 votes |
def WNConvTranspose1d(*args, **kwargs): return weight_norm(nn.ConvTranspose1d(*args, **kwargs))
Example #21
Source File: model.py From asteroid with MIT License | 5 votes |
def __init__(self, freq_res, sample_res, n_sources): super().__init__() self.deconv = nn.ConvTranspose1d(n_sources * freq_res, n_sources, sample_res, padding=sample_res // 2, stride=sample_res // 2, groups=n_sources, output_padding=(sample_res // 2) - 1)
Example #22
Source File: pointnet.py From pointGAN with MIT License | 5 votes |
def __init__(self, num_points = 2500): super(PointGenC, self).__init__() self.conv1 = nn.ConvTranspose1d(100, 1024, 2,2,0) self.conv2 = nn.ConvTranspose1d(1024, 512, 5,5,0) self.conv3 = nn.ConvTranspose1d(512, 256, 5,5,0) self.conv4 = nn.ConvTranspose1d(256, 128, 2,2,0) self.conv5 = nn.ConvTranspose1d(128, 64, 5,5,0) self.conv6 = nn.ConvTranspose1d(64, 3, 5,5,0) self.bn1 = torch.nn.BatchNorm1d(1024) self.bn2 = torch.nn.BatchNorm1d(512) self.bn3 = torch.nn.BatchNorm1d(256) self.bn4 = torch.nn.BatchNorm1d(128) self.bn5 = torch.nn.BatchNorm1d(64) self.th = nn.Tanh()
Example #23
Source File: decoder.py From hybrid_rvae with MIT License | 5 votes |
def __init__(self, vocab_size, latent_variable_size, rnn_size, rnn_num_layers, embed_size): super(Decoder, self).__init__() self.vocab_size = vocab_size self.latent_variable_size = latent_variable_size self.rnn_size = rnn_size self.embed_size = embed_size self.rnn_num_layers = rnn_num_layers self.cnn = nn.Sequential( nn.ConvTranspose1d(self.latent_variable_size, 512, 4, 2, 0), nn.BatchNorm1d(512), nn.ELU(), nn.ConvTranspose1d(512, 512, 4, 2, 0, output_padding=1), nn.BatchNorm1d(512), nn.ELU(), nn.ConvTranspose1d(512, 256, 4, 2, 0), nn.BatchNorm1d(256), nn.ELU(), nn.ConvTranspose1d(256, 256, 4, 2, 0, output_padding=1), nn.BatchNorm1d(256), nn.ELU(), nn.ConvTranspose1d(256, 128, 4, 2, 0), nn.BatchNorm1d(128), nn.ELU(), nn.ConvTranspose1d(128, self.vocab_size, 4, 2, 0) ) self.rnn = nn.GRU(input_size=self.vocab_size + self.embed_size, hidden_size=self.rnn_size, num_layers=self.rnn_num_layers, batch_first=True) self.hidden_to_vocab = nn.Linear(self.rnn_size, self.vocab_size)
Example #24
Source File: model.py From graph-generation with MIT License | 5 votes |
def __init__(self, input_size, output_size, stride = 2): super(CNN_decoder, self).__init__() self.input_size = input_size self.output_size = output_size self.relu = nn.ReLU() self.deconv1_1 = nn.ConvTranspose1d(in_channels=int(self.input_size), out_channels=int(self.input_size/2), kernel_size=3, stride=stride) self.bn1_1 = nn.BatchNorm1d(int(self.input_size/2)) self.deconv1_2 = nn.ConvTranspose1d(in_channels=int(self.input_size/2), out_channels=int(self.input_size/2), kernel_size=3, stride=stride) self.bn1_2 = nn.BatchNorm1d(int(self.input_size/2)) self.deconv1_3 = nn.ConvTranspose1d(in_channels=int(self.input_size/2), out_channels=int(self.output_size), kernel_size=3, stride=1, padding=1) self.deconv2_1 = nn.ConvTranspose1d(in_channels=int(self.input_size/2), out_channels=int(self.input_size / 4), kernel_size=3, stride=stride) self.bn2_1 = nn.BatchNorm1d(int(self.input_size / 4)) self.deconv2_2 = nn.ConvTranspose1d(in_channels=int(self.input_size / 4), out_channels=int(self.input_size/4), kernel_size=3, stride=stride) self.bn2_2 = nn.BatchNorm1d(int(self.input_size / 4)) self.deconv2_3 = nn.ConvTranspose1d(in_channels=int(self.input_size / 4), out_channels=int(self.output_size), kernel_size=3, stride=1, padding=1) self.deconv3_1 = nn.ConvTranspose1d(in_channels=int(self.input_size / 4), out_channels=int(self.input_size / 8), kernel_size=3, stride=stride) self.bn3_1 = nn.BatchNorm1d(int(self.input_size / 8)) self.deconv3_2 = nn.ConvTranspose1d(in_channels=int(self.input_size / 8), out_channels=int(self.input_size / 8), kernel_size=3, stride=stride) self.bn3_2 = nn.BatchNorm1d(int(self.input_size / 8)) self.deconv3_3 = nn.ConvTranspose1d(in_channels=int(self.input_size / 8), out_channels=int(self.output_size), kernel_size=3, stride=1, padding=1) for m in self.modules(): if isinstance(m, nn.ConvTranspose1d): # n = m.kernel_size[0] * m.kernel_size[1] * m.out_channels # m.weight.dataset.normal_(0, math.sqrt(2. / n)) m.weight.data = init.xavier_uniform(m.weight.data, gain=nn.init.calculate_gain('relu')) elif isinstance(m, nn.BatchNorm1d): m.weight.data.fill_(1) m.bias.data.zero_()
Example #25
Source File: model.py From graph-generation with MIT License | 5 votes |
def __init__(self, input_size, output_size, stride=2): super(CNN_decoder_attention, self).__init__() self.input_size = input_size self.output_size = output_size self.relu = nn.ReLU() self.deconv = nn.ConvTranspose1d(in_channels=int(self.input_size), out_channels=int(self.input_size), kernel_size=3, stride=stride) self.bn = nn.BatchNorm1d(int(self.input_size)) self.deconv_out = nn.ConvTranspose1d(in_channels=int(self.input_size), out_channels=int(self.output_size), kernel_size=3, stride=1, padding=1) self.deconv_attention = nn.ConvTranspose1d(in_channels=int(self.input_size), out_channels=int(self.input_size), kernel_size=1, stride=1, padding=0) self.bn_attention = nn.BatchNorm1d(int(self.input_size)) self.relu_leaky = nn.LeakyReLU(0.2) for m in self.modules(): if isinstance(m, nn.ConvTranspose1d): # n = m.kernel_size[0] * m.kernel_size[1] * m.out_channels # m.weight.dataset.normal_(0, math.sqrt(2. / n)) m.weight.data = init.xavier_uniform(m.weight.data, gain=nn.init.calculate_gain('relu')) elif isinstance(m, nn.BatchNorm1d): m.weight.data.fill_(1) m.bias.data.zero_()
Example #26
Source File: factories.py From MONAI with Apache License 2.0 | 5 votes |
def convtrans_factory(dim): types = [nn.ConvTranspose1d, nn.ConvTranspose2d, nn.ConvTranspose3d] return types[dim - 1]
Example #27
Source File: model.py From segan-pytorch with GNU General Public License v3.0 | 5 votes |
def init_weights(self): """ Initialize weights for convolution layers using Xavier initialization. """ for m in self.modules(): if isinstance(m, nn.Conv1d) or isinstance(m, nn.ConvTranspose1d): nn.init.xavier_normal_(m.weight.data)
Example #28
Source File: overtone.py From WaveRNN with MIT License | 5 votes |
def __init__(self, in_channels, out_channels, warmup_steps, global_cond_channels): super().__init__() self.gru = nn.GRU(in_channels + global_cond_channels, out_channels, batch_first=True) self.tconv = nn.ConvTranspose1d(out_channels, out_channels, kernel_size=4, stride=4) self.warmup_steps = warmup_steps
Example #29
Source File: dense_sparse_dense.py From pytorch-planet-amazon with Apache License 2.0 | 5 votes |
def is_sparseable(m): return True if hasattr(m, 'weight') and isinstance(m, ( nn.Conv1d, nn.Conv2d, nn.Conv3d, nn.ConvTranspose1d, nn.ConvTranspose2d, nn.ConvTranspose3d, nn.Linear)) else False
Example #30
Source File: denseEDcirc.py From ar-pde-cnn with MIT License | 5 votes |
def last_decoding(in_features, out_channels, drop_rate=0., upsample='nearest'): """Last transition up layer, which outputs directly the predictions. """ last_up = nn.Sequential() last_up.add_module('norm1', nn.BatchNorm1d(in_features)) last_up.add_module('relu1', nn.ReLU(True)) last_up.add_module('conv1', nn.Conv1d(in_features, in_features // 2, kernel_size=1, stride=1, padding=0, bias=False)) if drop_rate > 0.: last_up.add_module('dropout1', nn.Dropout1d(p=drop_rate)) last_up.add_module('norm2', nn.BatchNorm1d(in_features // 2)) last_up.add_module('relu2', nn.ReLU(True)) # last_up.add_module('convT2', nn.ConvTranspose1d(in_features // 2, # out_channels, kernel_size=2*padding+stride, stride=stride, # padding=padding, output_padding=output_padding, bias=bias)) if upsample == 'nearest': last_up.add_module('upsample', UpsamplingNearest1d(scale_factor=2)) elif upsample == 'linear': last_up.add_module('upsample', UpsamplingLinear1d(scale_factor=2)) last_up.add_module('conv2', nn.Conv1d(in_features // 2, in_features // 4, kernel_size=3, stride=1, padding=1*2, bias=False, padding_mode='circular')) last_up.add_module('norm3', nn.BatchNorm1d(in_features // 4)) last_up.add_module('relu3', nn.ReLU(True)) last_up.add_module('conv3', nn.Conv1d(in_features // 4, out_channels, kernel_size=5, stride=1, padding=2*2, bias=False, padding_mode='circular')) return last_up