From dae79b0acd3cd316016078c40a1cc553ffb9405e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Eren=20G=C3=B6lge?= Date: Mon, 10 Oct 2022 13:32:27 +0200 Subject: [PATCH] Remove `/` prefix from the relative path (#2065) --- TTS/tts/datasets/__init__.py | 24 ++++++++----------- tests/__init__.py | 4 +++- tests/data/ljspeech/speakers.json | 20 ++++++++-------- tests/inference_tests/test_synthesizer.py | 8 +++---- .../dummy_model_config.json | 0 5 files changed, 27 insertions(+), 29 deletions(-) rename tests/{outputs => inputs}/dummy_model_config.json (100%) diff --git a/TTS/tts/datasets/__init__.py b/TTS/tts/datasets/__init__.py index eeadf7d3..1dce9fcd 100644 --- a/TTS/tts/datasets/__init__.py +++ b/TTS/tts/datasets/__init__.py @@ -1,3 +1,4 @@ +import os import sys from collections import Counter from pathlib import Path @@ -12,20 +13,16 @@ from TTS.tts.datasets.formatters import * def split_dataset(items, eval_split_max_size=None, eval_split_size=0.01): """Split a dataset into train and eval. Consider speaker distribution in multi-speaker training. - Args: - <<<<<<< HEAD - items (List[List]): - A list of samples. Each sample is a list of `[audio_path, text, speaker_id]`. + Args: + items (List[List]): + A list of samples. Each sample is a list of `[audio_path, text, speaker_id]`. - eval_split_max_size (int): - Number maximum of samples to be used for evaluation in proportion split. Defaults to None (Disabled). + eval_split_max_size (int): + Number maximum of samples to be used for evaluation in proportion split. Defaults to None (Disabled). - eval_split_size (float): - If between 0.0 and 1.0 represents the proportion of the dataset to include in the evaluation set. - If > 1, represents the absolute number of evaluation samples. Defaults to 0.01 (1%). - ======= - items (List[List]): A list of samples. Each sample is a list of `[text, audio_path, speaker_id]`. - >>>>>>> Fix docstring + eval_split_size (float): + If between 0.0 and 1.0 represents the proportion of the dataset to include in the evaluation set. + If > 1, represents the absolute number of evaluation samples. Defaults to 0.01 (1%). """ speakers = [item["speaker_name"] for item in items] is_multi_speaker = len(set(speakers)) > 1 @@ -64,10 +61,9 @@ def add_extra_keys(metadata, language, dataset_name): # add language name item["language"] = language # add unique audio name - relfilepath = os.path.splitext(item["audio_file"].replace(item["root_path"], ""))[0] + relfilepath = os.path.splitext(os.path.relpath(item["audio_file"], item["root_path"]))[0] audio_unique_name = f"{dataset_name}#{relfilepath}" item["audio_unique_name"] = audio_unique_name - return metadata diff --git a/tests/__init__.py b/tests/__init__.py index 34b072ae..e102a2df 100644 --- a/tests/__init__.py +++ b/tests/__init__.py @@ -33,7 +33,9 @@ def get_tests_data_path(): def get_tests_output_path(): """Returns the path to the directory for test outputs.""" - return os.path.join(get_tests_path(), "outputs") + path = os.path.join(get_tests_path(), "outputs") + os.makedirs(path, exist_ok=True) + return path def run_cli(command): diff --git a/tests/data/ljspeech/speakers.json b/tests/data/ljspeech/speakers.json index 2790a30e..461435c2 100644 --- a/tests/data/ljspeech/speakers.json +++ b/tests/data/ljspeech/speakers.json @@ -1,5 +1,5 @@ { - "#/wavs/LJ001-0001": { + "#wavs/LJ001-0001": { "name": "ljspeech-0", "embedding": [ 0.05539746582508087, @@ -260,7 +260,7 @@ -0.09469571709632874 ] }, - "#/wavs/LJ001-0002": { + "#wavs/LJ001-0002": { "name": "ljspeech-1", "embedding": [ 0.05539746582508087, @@ -521,7 +521,7 @@ -0.09469571709632874 ] }, - "#/wavs/LJ001-0003": { + "#wavs/LJ001-0003": { "name": "ljspeech-2", "embedding": [ 0.05539746582508087, @@ -782,7 +782,7 @@ -0.09469571709632874 ] }, - "#/wavs/LJ001-0004": { + "#wavs/LJ001-0004": { "name": "ljspeech-3", "embedding": [ 0.05539746582508087, @@ -1043,7 +1043,7 @@ -0.09469571709632874 ] }, - "#/wavs/LJ001-0005": { + "#wavs/LJ001-0005": { "name": "ljspeech-4", "embedding": [ 0.05539746582508087, @@ -1304,7 +1304,7 @@ -0.09469571709632874 ] }, - "#/wavs/LJ001-0006": { + "#wavs/LJ001-0006": { "name": "ljspeech-5", "embedding": [ 0.05539746582508087, @@ -1565,7 +1565,7 @@ -0.09469571709632874 ] }, - "#/wavs/LJ001-0007": { + "#wavs/LJ001-0007": { "name": "ljspeech-6", "embedding": [ 0.05539746582508087, @@ -1826,7 +1826,7 @@ -0.09469571709632874 ] }, - "#/wavs/LJ001-0008": { + "#wavs/LJ001-0008": { "name": "ljspeech-7", "embedding": [ 0.05539746582508087, @@ -2087,7 +2087,7 @@ -0.09469571709632874 ] }, - "#/wavs/LJ001-0009": { + "#wavs/LJ001-0009": { "name": "ljspeech-8", "embedding": [ 0.05539746582508087, @@ -2348,7 +2348,7 @@ -0.09469571709632874 ] }, - "#/wavs/LJ001-0010": { + "#wavs/LJ001-0010": { "name": "ljspeech-9", "embedding": [ 0.05539746582508087, diff --git a/tests/inference_tests/test_synthesizer.py b/tests/inference_tests/test_synthesizer.py index b5350b0f..40e83017 100644 --- a/tests/inference_tests/test_synthesizer.py +++ b/tests/inference_tests/test_synthesizer.py @@ -1,7 +1,7 @@ import os import unittest -from tests import get_tests_output_path +from tests import get_tests_input_path from TTS.config import load_config from TTS.tts.models import setup_model from TTS.utils.io import save_checkpoint @@ -12,14 +12,14 @@ class SynthesizerTest(unittest.TestCase): # pylint: disable=R0201 def _create_random_model(self): # pylint: disable=global-statement - config = load_config(os.path.join(get_tests_output_path(), "dummy_model_config.json")) + config = load_config(os.path.join(get_tests_input_path(), "dummy_model_config.json")) model = setup_model(config) - output_path = os.path.join(get_tests_output_path()) + output_path = os.path.join(get_tests_input_path()) save_checkpoint(config, model, None, None, 10, 1, output_path) def test_in_out(self): self._create_random_model() - tts_root_path = get_tests_output_path() + tts_root_path = get_tests_input_path() tts_checkpoint = os.path.join(tts_root_path, "checkpoint_10.pth") tts_config = os.path.join(tts_root_path, "dummy_model_config.json") synthesizer = Synthesizer(tts_checkpoint, tts_config, None, None) diff --git a/tests/outputs/dummy_model_config.json b/tests/inputs/dummy_model_config.json similarity index 100% rename from tests/outputs/dummy_model_config.json rename to tests/inputs/dummy_model_config.json