Skip to content

CodeAnt AI: Made Changes to the file #184

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions analytics/tests/tests/trainer/test_trainer.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,12 @@ class TestTrainer:
def test_trainer_base(self):
config = TRAINER_DEFAULTS.values()

params = dict(
params = {
checkpoint_name="test",
checkpoint_path="test_checkpoint",
cudnn_enabled=True,
log_dir="this/is/a/test",
)
}
config.update(params)
hparams = HParams(**config)
trainer = TTSTrainer(hparams)
Expand Down Expand Up @@ -50,4 +50,4 @@ def test_gradient_step(self, lj_trainer):

assert math.isclose(
lj_trainer.loss[2], train_loss_4_datapoints_2_iteration, abs_tol=5e-4
)
)
16 changes: 8 additions & 8 deletions uberduck_ml_dev/data/collate.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ def __call__(self, batch):
output = Batch()

if return_audio:
max_target_len = max([x["audio"].size(0) for x in batch])
max_target_len = max(x['audio'].size(0) for x in batch)
audio_padded = torch.FloatTensor(len(batch), max_target_len)
audio_padded.zero_()
audio_lengths = torch.LongTensor(len(batch))
Expand All @@ -66,7 +66,7 @@ def __call__(self, batch):

if return_mels:
n_mel_channels = batch[0]["mel"].size(0)
max_target_len = max([x["mel"].size(1) for x in batch])
max_target_len = max(x['mel'].size(1) for x in batch)
mel_padded = torch.FloatTensor(len(batch), n_mel_channels, max_target_len)
mel_padded.zero_()
mel_lengths = torch.LongTensor(len(batch))
Expand All @@ -90,7 +90,7 @@ def __call__(self, batch):
output["speaker_ids"] = speaker_ids

if return_f0s:
max_target_len = max([x["f0"].size(0) for x in batch])
max_target_len = max(x['f0'].size(0) for x in batch)
f0_padded = torch.FloatTensor(len(batch), 1, max_target_len)
f0_padded.zero_()
for i, sample in enumerate(batch):
Expand Down Expand Up @@ -142,7 +142,7 @@ def __call__(self, batch):

# Right zero-pad mel-spec
num_mel_channels = batch[0]["mel"].size(0)
max_target_len = max([x["mel"].size(1) for x in batch])
max_target_len = max(x['mel'].size(1) for x in batch)

# include mel padded, gate padded and speaker ids
mel_padded = torch.FloatTensor(len(batch), num_mel_channels, max_target_len)
Expand Down Expand Up @@ -272,16 +272,16 @@ def __call__(self, batch):
torch.LongTensor([x[0].size(1) for x in batch]), dim=0, descending=True
)

max_spec_len = max([x[0].size(1) for x in batch])
max_wave_len = max([x[1].size(1) for x in batch])
max_spec_len = max(x[0].size(1) for x in batch)
max_wave_len = max(x[1].size(1) for x in batch)
spec_lengths = torch.LongTensor(len(batch))
wave_lengths = torch.LongTensor(len(batch))
spec_padded = torch.FloatTensor(len(batch), batch[0][0].size(0), max_spec_len)
wave_padded = torch.FloatTensor(len(batch), 1, max_wave_len)
spec_padded.zero_()
wave_padded.zero_()

max_phone_len = max([x[2].size(0) for x in batch])
max_phone_len = max(x[2].size(0) for x in batch)
phone_lengths = torch.LongTensor(len(batch))
phone_padded = torch.FloatTensor(
len(batch), max_phone_len, batch[0][2].shape[1]
Expand Down Expand Up @@ -325,4 +325,4 @@ def __call__(self, batch):
wave_padded,
wave_lengths,
sid, # nee "dv"
)
)
66 changes: 26 additions & 40 deletions uberduck_ml_dev/data/data.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,29 +16,18 @@
from librosa import pyin
import parselmouth

from ..models.common import MelSTFT
from ..models.common import FILTER_LENGTH, HOP_LENGTH, MelSTFT, N_MEL_CHANNELS, SAMPLING_RATE, TacotronSTFT, WIN_LENGTH
from ..utils.utils import (
load_filepaths_and_text,
intersperse,
)
from .utils import (
oversample,
_orig_to_dense_speaker_id,
beta_binomial_prior_distribution,
)
from .utils import _orig_to_dense_speaker_id, beta_binomial_prior_distribution, oversample, spectrogram_torch
from ..text.utils import text_to_sequence
from ..text.text_processing import TextProcessing
from ..models.common import (
FILTER_LENGTH,
HOP_LENGTH,
WIN_LENGTH,
SAMPLING_RATE,
N_MEL_CHANNELS,
TacotronSTFT,
)

from ..text.symbols import NVIDIA_TACO2_SYMBOLS
from ..trainer.rvc.utils import load_wav_to_torch
from .utils import spectrogram_torch



from ..models.tacotron2 import MAX_WAV_VALUE
Expand Down Expand Up @@ -185,7 +174,7 @@ def __init__(
# NOTE (Sam): this is the RADTTS version - more recent than mellotron from the same author.
# NOTE (Sam): in contrast to get_gst, the computation here is kept in this file rather than a functional argument.
def _get_f0(self, audiopath, audio):
filename = "_".join(audiopath.split("/")).split(".wav")[0]
filename = '_'.join(audiopath.split('/')).split('.wav', maxsplit=1)[0]
f0_path = os.path.join(self.f0_cache_path, filename)
f0_path += "_f0_sr{}_fl{}_hl{}_f0min{}_f0max{}_log{}.pt".format(
self.sampling_rate,
Expand Down Expand Up @@ -337,10 +326,7 @@ def __len__(self):

def sample_test_batch(self, size):
idx = np.random.choice(range(len(self)), size=size, replace=False)
test_batch = []
for index in idx:
test_batch.append(self.__getitem__(index))
return test_batch
return [self.__getitem__(index) for index in idx]

def get_f0_pvoiced(
self,
Expand Down Expand Up @@ -505,6 +491,8 @@ def __init__(

def load_data(self, datasets, split="|"):
dataset = []

duration = -1
for dset_name, dset_dict in datasets.items():
folder_path = dset_dict["basedir"]
audiodir = dset_dict["audiodir"]
Expand All @@ -521,9 +509,11 @@ def load_data(self, datasets, split="|"):
with open(filelist_path, encoding="utf-8") as f:
data = [line.strip().split(split) for line in f]



for d in data:
# NOTE (Sam): BEWARE! change/comment depending on filelist.
duration = -1

dataset.append(
{
"audiopath": os.path.join(wav_folder_prefix, d[0]),
Expand Down Expand Up @@ -776,9 +766,7 @@ def __getitem__(self, idx):
return None

def __len__(self):
nfiles = len(self.audiopaths)

return nfiles
return len(self.audiopaths)


def get_f0_pvoiced(
Expand Down Expand Up @@ -968,9 +956,7 @@ def __getitem__(self, idx):
return None

def __len__(self):
nfiles = len(self.audiopaths)

return nfiles
return len(self.audiopaths)


RADTTS_DEFAULTS = {
Expand Down Expand Up @@ -1073,8 +1059,7 @@ def _filter(self):
self.lengths = lengths

def get_sid(self, sid):
sid = torch.LongTensor([int(sid)])
return sid
return torch.LongTensor([int(sid)])

def get_audio_text_pair(self, audiopath_and_text):
file = audiopath_and_text[0]
Expand Down Expand Up @@ -1194,9 +1179,11 @@ def _create_buckets(self):
self.boundaries.pop(i + 1)

num_samples_per_bucket = []

total_batch_size = self.num_replicas * self.batch_size
for i in range(len(buckets)):
len_bucket = len(buckets[i])
total_batch_size = self.num_replicas * self.batch_size

rem = (
total_batch_size - (len_bucket % total_batch_size)
) % total_batch_size
Expand Down Expand Up @@ -1256,17 +1243,16 @@ def _bisect(self, x, lo=0, hi=None):
if hi is None:
hi = len(self.boundaries) - 1

if hi > lo:
mid = (hi + lo) // 2
if self.boundaries[mid] < x and x <= self.boundaries[mid + 1]:
return mid
elif x <= self.boundaries[mid]:
return self._bisect(x, lo, mid)
else:
return self._bisect(x, mid + 1, hi)
else:
if hi <= lo:
return -1

mid = (hi + lo) // 2
if self.boundaries[mid] < x and x <= self.boundaries[mid + 1]:
return mid
if x <= self.boundaries[mid]:
return self._bisect(x, lo, mid)
return self._bisect(x, mid + 1, hi)

def __len__(self):
return self.num_samples // self.batch_size

Expand Down Expand Up @@ -1331,4 +1317,4 @@ def __getitem__(self, index):
return output

def __len__(self):
return len(self.data_paths)
return len(self.data_paths)