From b24c7b433ae9db990dbd52eb0f1b357568fb484c Mon Sep 17 00:00:00 2001 From: Jean-Marc Valin Date: Tue, 12 Sep 2023 22:58:34 -0400 Subject: [PATCH] Remove --has-gain and --passthrough-size args Couldn't be used anymore --- dnn/torch/fargan/fargan.py | 23 +++++++---------------- dnn/torch/fargan/train_fargan.py | 4 +--- 2 files changed, 8 insertions(+), 19 deletions(-) diff --git a/dnn/torch/fargan/fargan.py b/dnn/torch/fargan/fargan.py index b532f268a..91497ccd2 100644 --- a/dnn/torch/fargan/fargan.py +++ b/dnn/torch/fargan/fargan.py @@ -154,17 +154,13 @@ def forward(self, features, period): return tmp class FARGANSub(nn.Module): - def __init__(self, subframe_size=40, nb_subframes=4, cond_size=256, passthrough_size=0, has_gain=False): + def __init__(self, subframe_size=40, nb_subframes=4, cond_size=256): super(FARGANSub, self).__init__() self.subframe_size = subframe_size self.nb_subframes = nb_subframes self.cond_size = cond_size - self.has_gain = has_gain - self.passthrough_size = passthrough_size - #print("has_gain:", self.has_gain) - #print("passthrough_size:", self.passthrough_size) #self.sig_dense1 = nn.Linear(4*self.subframe_size+self.passthrough_size+self.cond_size, self.cond_size, bias=False) self.fwc0 = FWConv(4*self.subframe_size+80, self.cond_size) self.sig_dense2 = nn.Linear(self.cond_size, self.cond_size, bias=False) @@ -179,9 +175,8 @@ def __init__(self, subframe_size=40, nb_subframes=4, cond_size=256, passthrough_ self.gru3_glu = GLU(self.cond_size) self.ptaps_dense = nn.Linear(4*self.cond_size, 5) - self.sig_dense_out = nn.Linear(4*self.cond_size, self.subframe_size+self.passthrough_size, bias=False) - if self.has_gain: - self.gain_dense_out = nn.Linear(4*self.cond_size, 1) + self.sig_dense_out = nn.Linear(4*self.cond_size, self.subframe_size, bias=False) + self.gain_dense_out = nn.Linear(4*self.cond_size, 1) self.apply(init_weights) @@ -223,10 +218,9 @@ def forward(self, cond, prev, exc_mem, phase, period, states, gain=None): #fpitch = taps[:,0:1]*pred[:,:-4] + taps[:,1:2]*pred[:,1:-3] + taps[:,2:3]*pred[:,2:-2] + taps[:,3:4]*pred[:,3:-1] + taps[:,4:]*pred[:,4:] fpitch = pred[:,2:-2] - if self.has_gain: - pitch_gain = torch.exp(self.gain_dense_out(gru3_out)) - dump_signal(pitch_gain, 'pgain.f32') - sig_out = (sig_out + pitch_gain*fpitch) * gain + pitch_gain = torch.exp(self.gain_dense_out(gru3_out)) + dump_signal(pitch_gain, 'pgain.f32') + sig_out = (sig_out + pitch_gain*fpitch) * gain exc_mem = torch.cat([exc_mem[:,self.subframe_size:], sig_out], 1) dump_signal(sig_out, 'sig_out.f32') return sig_out, exc_mem, (gru1_state, gru2_state, gru3_state, fwc0_state) @@ -240,11 +234,9 @@ def __init__(self, subframe_size=40, nb_subframes=4, feature_dim=20, cond_size=2 self.frame_size = self.subframe_size*self.nb_subframes self.feature_dim = feature_dim self.cond_size = cond_size - self.has_gain = has_gain - self.passthrough_size = passthrough_size self.cond_net = FARGANCond(feature_dim=feature_dim, cond_size=cond_size) - self.sig_net = FARGANSub(subframe_size=subframe_size, nb_subframes=nb_subframes, cond_size=cond_size, has_gain=has_gain, passthrough_size=passthrough_size) + self.sig_net = FARGANSub(subframe_size=subframe_size, nb_subframes=nb_subframes, cond_size=cond_size) def forward(self, features, period, nb_frames, pre=None, states=None): device = features.device @@ -266,7 +258,6 @@ def forward(self, features, period, nb_frames, pre=None, states=None): sig = torch.zeros((batch_size, 0), device=device) cond = self.cond_net(features, period) - passthrough = torch.zeros(batch_size, self.passthrough_size, device=device) if pre is not None: prev[:,:] = pre[:, self.frame_size-self.subframe_size : self.frame_size] exc_mem[:,-self.frame_size:] = pre[:, :self.frame_size] diff --git a/dnn/torch/fargan/train_fargan.py b/dnn/torch/fargan/train_fargan.py index 3904253e0..20cf2d2ba 100644 --- a/dnn/torch/fargan/train_fargan.py +++ b/dnn/torch/fargan/train_fargan.py @@ -24,8 +24,6 @@ model_group = parser.add_argument_group(title="model parameters") model_group.add_argument('--cond-size', type=int, help="first conditioning size, default: 256", default=256) -model_group.add_argument('--has-gain', action='store_true', help="use gain-shape network") -model_group.add_argument('--passthrough-size', type=int, help="state passing through in addition to audio, default: 0", default=0) model_group.add_argument('--gamma', type=float, help="Use A(z/gamma), default: 0.9", default=0.9) training_group = parser.add_argument_group(title="training parameters") @@ -74,7 +72,7 @@ device = torch.device("cuda") if torch.cuda.is_available() else torch.device("cpu") checkpoint['model_args'] = () -checkpoint['model_kwargs'] = {'cond_size': cond_size, 'has_gain': args.has_gain, 'passthrough_size': args.passthrough_size, 'gamma': args.gamma} +checkpoint['model_kwargs'] = {'cond_size': cond_size, 'gamma': args.gamma} print(checkpoint['model_kwargs']) model = fargan.FARGAN(*checkpoint['model_args'], **checkpoint['model_kwargs'])