⚗️ | Experimenting with larger model architecture.
This commit is contained in:
@ -2,29 +2,39 @@ import torch
|
||||
import torch.nn as nn
|
||||
import torch.nn.utils as utils
|
||||
|
||||
def discriminator_block(in_channels, out_channels, kernel_size=3, stride=1, dilation=1):
|
||||
padding = (kernel_size // 2) * dilation
|
||||
return nn.Sequential(
|
||||
utils.spectral_norm(nn.Conv1d(in_channels, out_channels, kernel_size=kernel_size, stride=stride, dilation=dilation, padding=padding)),
|
||||
nn.BatchNorm1d(out_channels),
|
||||
nn.LeakyReLU(0.2, inplace=True) # Changed activation to LeakyReLU
|
||||
)
|
||||
|
||||
class SISUDiscriminator(nn.Module):
|
||||
def __init__(self):
|
||||
super(SISUDiscriminator, self).__init__()
|
||||
layers = 8
|
||||
layers = 32 # Increased base layer count
|
||||
self.model = nn.Sequential(
|
||||
utils.spectral_norm(nn.Conv1d(1, layers, kernel_size=7, stride=2, padding=3)),
|
||||
nn.BatchNorm1d(layers),
|
||||
nn.PReLU(),
|
||||
nn.Conv1d(layers, layers * 2, kernel_size=7, padding=3),
|
||||
nn.BatchNorm1d(layers * 2),
|
||||
nn.PReLU(),
|
||||
nn.Conv1d(layers * 2, layers * 4, kernel_size=5, padding=2),
|
||||
nn.BatchNorm1d(layers * 4),
|
||||
nn.PReLU(),
|
||||
nn.Conv1d(layers * 4, layers * 8, kernel_size=3, padding=1),
|
||||
nn.BatchNorm1d(layers * 8),
|
||||
nn.PReLU(),
|
||||
nn.Conv1d(layers * 8, 1, kernel_size=3, padding=1),
|
||||
# Initial Convolution
|
||||
discriminator_block(1, layers, kernel_size=7, stride=2, dilation=1), # Downsample
|
||||
|
||||
# Core Discriminator Blocks with varied kernels and dilations
|
||||
discriminator_block(layers, layers * 2, kernel_size=5, stride=2, dilation=1), # Downsample
|
||||
discriminator_block(layers * 2, layers * 2, kernel_size=3, dilation=2),
|
||||
discriminator_block(layers * 2, layers * 4, kernel_size=5, dilation=4),
|
||||
discriminator_block(layers * 4, layers * 4, kernel_size=3, dilation=8),
|
||||
discriminator_block(layers * 4, layers * 8, kernel_size=5, dilation=16),
|
||||
discriminator_block(layers * 8, layers * 8, kernel_size=3, dilation=8),
|
||||
discriminator_block(layers * 8, layers * 4, kernel_size=5, dilation=4),
|
||||
discriminator_block(layers * 4, layers * 2, kernel_size=3, dilation=2),
|
||||
discriminator_block(layers * 2, layers, kernel_size=5, dilation=1),
|
||||
# Final Convolution
|
||||
discriminator_block(layers, 1, kernel_size=3, stride=1),
|
||||
)
|
||||
self.global_avg_pool = nn.AdaptiveAvgPool1d(1)
|
||||
|
||||
def forward(self, x):
|
||||
x = x + 0.01 * torch.randn_like(x)
|
||||
# Gaussian noise is not necessary here for discriminator as it is already implicit in the training process
|
||||
x = self.model(x)
|
||||
x = self.global_avg_pool(x)
|
||||
x = x.view(-1, 1)
|
||||
|
Reference in New Issue
Block a user