Python torch.nn.ReflectionPad1d() Examples
The following are 8
code examples of torch.nn.ReflectionPad1d().
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: networks.py From 2D-Motion-Retargeting with MIT License | 6 votes |
def __init__(self, channels, kernel_size=7): super(Decoder, self).__init__() model = [] pad = (kernel_size - 1) // 2 acti = nn.LeakyReLU(0.2) for i in range(len(channels) - 1): model.append(nn.Upsample(scale_factor=2, mode='nearest')) model.append(nn.ReflectionPad1d(pad)) model.append(nn.Conv1d(channels[i], channels[i + 1], kernel_size=kernel_size, stride=1)) if i == 0 or i == 1: model.append(nn.Dropout(p=0.2)) if not i == len(channels) - 2: model.append(acti) # whether to add tanh a last? #model.append(nn.Dropout(p=0.2)) self.model = nn.Sequential(*model)
Example #2
Source File: res_stack.py From melgan with BSD 3-Clause "New" or "Revised" License | 6 votes |
def __init__(self, channel): super(ResStack, self).__init__() self.blocks = nn.ModuleList([ nn.Sequential( nn.LeakyReLU(0.2), nn.ReflectionPad1d(3**i), nn.utils.weight_norm(nn.Conv1d(channel, channel, kernel_size=3, dilation=3**i)), nn.LeakyReLU(0.2), nn.utils.weight_norm(nn.Conv1d(channel, channel, kernel_size=1)), ) for i in range(3) ]) self.shortcuts = nn.ModuleList([ nn.utils.weight_norm(nn.Conv1d(channel, channel, kernel_size=1)) for i in range(3) ])
Example #3
Source File: networks.py From 2D-Motion-Retargeting with MIT License | 5 votes |
def __init__(self, channels, kernel_size=8, global_pool=None, convpool=None, compress=False): super(Encoder, self).__init__() model = [] acti = nn.LeakyReLU(0.2) nr_layer = len(channels) - 2 if compress else len(channels) - 1 for i in range(nr_layer): if convpool is None: pad = (kernel_size - 2) // 2 model.append(nn.ReflectionPad1d(pad)) model.append(nn.Conv1d(channels[i], channels[i+1], kernel_size=kernel_size, stride=2)) model.append(acti) else: pad = (kernel_size - 1) // 2 model.append(nn.ReflectionPad1d(pad)) model.append(nn.Conv1d(channels[i], channels[i+1], kernel_size=kernel_size, stride=1)) model.append(acti) model.append(convpool(kernel_size=2, stride=2)) self.global_pool = global_pool self.compress = compress self.model = nn.Sequential(*model) if self.compress: self.conv1x1 = nn.Conv1d(channels[-2], channels[-1], kernel_size=1)
Example #4
Source File: discriminator.py From melgan with BSD 3-Clause "New" or "Revised" License | 5 votes |
def __init__(self): super(Discriminator, self).__init__() self.discriminator = nn.ModuleList([ nn.Sequential( nn.ReflectionPad1d(7), nn.utils.weight_norm(nn.Conv1d(1, 16, kernel_size=15, stride=1)), nn.LeakyReLU(0.2, inplace=True), ), nn.Sequential( nn.utils.weight_norm(nn.Conv1d(16, 64, kernel_size=41, stride=4, padding=20, groups=4)), nn.LeakyReLU(0.2, inplace=True), ), nn.Sequential( nn.utils.weight_norm(nn.Conv1d(64, 256, kernel_size=41, stride=4, padding=20, groups=16)), nn.LeakyReLU(0.2, inplace=True), ), nn.Sequential( nn.utils.weight_norm(nn.Conv1d(256, 1024, kernel_size=41, stride=4, padding=20, groups=64)), nn.LeakyReLU(0.2, inplace=True), ), nn.Sequential( nn.utils.weight_norm(nn.Conv1d(1024, 1024, kernel_size=41, stride=4, padding=20, groups=256)), nn.LeakyReLU(0.2, inplace=True), ), nn.Sequential( nn.utils.weight_norm(nn.Conv1d(1024, 1024, kernel_size=5, stride=1, padding=2)), nn.LeakyReLU(0.2, inplace=True), ), nn.utils.weight_norm(nn.Conv1d(1024, 1, kernel_size=3, stride=1, padding=1)), ])
Example #5
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 #6
Source File: modules.py From melgan-neurips with MIT License | 5 votes |
def __init__(self, dim, dilation=1): super().__init__() self.block = nn.Sequential( nn.LeakyReLU(0.2), nn.ReflectionPad1d(dilation), WNConv1d(dim, dim, kernel_size=3, dilation=dilation), nn.LeakyReLU(0.2), WNConv1d(dim, dim, kernel_size=1), ) self.shortcut = WNConv1d(dim, dim, kernel_size=1)
Example #7
Source File: modules.py From melgan-neurips with MIT License | 5 votes |
def __init__(self, input_size, ngf, n_residual_layers): super().__init__() ratios = [8, 8, 2, 2] self.hop_length = np.prod(ratios) mult = int(2 ** len(ratios)) model = [ nn.ReflectionPad1d(3), WNConv1d(input_size, mult * ngf, kernel_size=7, padding=0), ] # Upsample to raw audio scale for i, r in enumerate(ratios): model += [ nn.LeakyReLU(0.2), WNConvTranspose1d( mult * ngf, mult * ngf // 2, kernel_size=r * 2, stride=r, padding=r // 2 + r % 2, output_padding=r % 2, ), ] for j in range(n_residual_layers): model += [ResnetBlock(mult * ngf // 2, dilation=3 ** j)] mult //= 2 model += [ nn.LeakyReLU(0.2), nn.ReflectionPad1d(3), WNConv1d(ngf, 1, kernel_size=7, padding=0), nn.Tanh(), ] self.model = nn.Sequential(*model) self.apply(weights_init)
Example #8
Source File: modules.py From melgan-neurips with MIT License | 5 votes |
def __init__(self, ndf, n_layers, downsampling_factor): super().__init__() model = nn.ModuleDict() model["layer_0"] = nn.Sequential( nn.ReflectionPad1d(7), WNConv1d(1, ndf, kernel_size=15), nn.LeakyReLU(0.2, True), ) nf = ndf stride = downsampling_factor for n in range(1, n_layers + 1): nf_prev = nf nf = min(nf * stride, 1024) model["layer_%d" % n] = nn.Sequential( WNConv1d( nf_prev, nf, kernel_size=stride * 10 + 1, stride=stride, padding=stride * 5, groups=nf_prev // 4, ), nn.LeakyReLU(0.2, True), ) nf = min(nf * 2, 1024) model["layer_%d" % (n_layers + 1)] = nn.Sequential( WNConv1d(nf_prev, nf, kernel_size=5, stride=1, padding=2), nn.LeakyReLU(0.2, True), ) model["layer_%d" % (n_layers + 2)] = WNConv1d( nf, 1, kernel_size=3, stride=1, padding=1 ) self.model = model