Skip to content

Commit

Permalink
Remove --has-gain and --passthrough-size args
Browse files Browse the repository at this point in the history
Couldn't be used anymore
  • Loading branch information
jmvalin committed Sep 13, 2023
1 parent 2f8b36d commit b24c7b4
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 19 deletions.
23 changes: 7 additions & 16 deletions dnn/torch/fargan/fargan.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
Expand Down Expand Up @@ -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)
Expand All @@ -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
Expand All @@ -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]
Expand Down
4 changes: 1 addition & 3 deletions dnn/torch/fargan/train_fargan.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down Expand Up @@ -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'])

Expand Down

0 comments on commit b24c7b4

Please sign in to comment.