Fix generating style bug

This commit is contained in:
litagin02
2024-05-26 11:07:43 +09:00
parent e52453040c
commit 012f159ab5
3 changed files with 16 additions and 5 deletions

View File

@@ -42,11 +42,17 @@ def save_neutral_vector(wav_dir: Union[Path, str], output_path: Union[Path, str]
logger.info(f"Saved style config to {json_path}") logger.info(f"Saved style config to {json_path}")
def save_styles_by_dirs(wav_dir: Union[Path, str], output_dir: Union[Path, str]): def save_styles_by_dirs(
wav_dir: Union[Path, str],
output_dir: Union[Path, str],
config_path: Union[Path, str],
config_output_path: Union[Path, str],
):
wav_dir = Path(wav_dir) wav_dir = Path(wav_dir)
output_dir = Path(output_dir) output_dir = Path(output_dir)
output_dir.mkdir(parents=True, exist_ok=True) output_dir.mkdir(parents=True, exist_ok=True)
json_path = output_dir / "config.json" config_path = Path(config_path)
config_output_path = Path(config_output_path)
subdirs = [d for d in wav_dir.iterdir() if d.is_dir()] subdirs = [d for d in wav_dir.iterdir() if d.is_dir()]
subdirs.sort() subdirs.sort()
@@ -55,6 +61,7 @@ def save_styles_by_dirs(wav_dir: Union[Path, str], output_dir: Union[Path, str])
f"At least 2 subdirectories are required for generating style vectors with respect to them, found {len(subdirs)}." f"At least 2 subdirectories are required for generating style vectors with respect to them, found {len(subdirs)}."
) )
logger.info("Generating only neutral style vector instead.") logger.info("Generating only neutral style vector instead.")
set_style_config(config_path, config_output_path)
save_neutral_vector(wav_dir, output_dir) save_neutral_vector(wav_dir, output_dir)
# First get mean of all for Neutral # First get mean of all for Neutral
@@ -88,10 +95,10 @@ def save_styles_by_dirs(wav_dir: Union[Path, str], output_dir: Union[Path, str])
# Save style2id config to json # Save style2id config to json
style2id = {name: i for i, name in enumerate(names)} style2id = {name: i for i, name in enumerate(names)}
with open(json_path, encoding="utf-8") as f: with open(config_path, encoding="utf-8") as f:
json_dict = json.load(f) json_dict = json.load(f)
json_dict["data"]["num_styles"] = len(names) json_dict["data"]["num_styles"] = len(names)
json_dict["data"]["style2id"] = style2id json_dict["data"]["style2id"] = style2id
with open(json_path, "w", encoding="utf-8") as f: with open(config_output_path, "w", encoding="utf-8") as f:
json.dump(json_dict, f, indent=2, ensure_ascii=False) json.dump(json_dict, f, indent=2, ensure_ascii=False)
logger.info(f"Saved style config to {json_path}") logger.info(f"Saved style config to {config_output_path}")

View File

@@ -195,6 +195,8 @@ def run():
default_style.save_styles_by_dirs( default_style.save_styles_by_dirs(
os.path.join(args.model, "wavs"), os.path.join(args.model, "wavs"),
config.out_dir, config.out_dir,
config_path=args.config,
config_output_path=os.path.join(config.out_dir, "config.json"),
) )
torch.manual_seed(hps.train.seed) torch.manual_seed(hps.train.seed)

View File

@@ -201,6 +201,8 @@ def run():
default_style.save_styles_by_dirs( default_style.save_styles_by_dirs(
os.path.join(args.model, "wavs"), os.path.join(args.model, "wavs"),
config.out_dir, config.out_dir,
config_path=args.config,
config_output_path=os.path.join(config.out_dir, "config.json"),
) )
torch.manual_seed(hps.train.seed) torch.manual_seed(hps.train.seed)