Fix: gen style in beginning of train for nested folders
This commit is contained in:
@@ -1,5 +1,7 @@
|
|||||||
import json
|
import json
|
||||||
import os
|
import os
|
||||||
|
from pathlib import Path
|
||||||
|
from typing import Union
|
||||||
|
|
||||||
import numpy as np
|
import numpy as np
|
||||||
|
|
||||||
@@ -7,7 +9,7 @@ from style_bert_vits2.constants import DEFAULT_STYLE
|
|||||||
from style_bert_vits2.logging import logger
|
from style_bert_vits2.logging import logger
|
||||||
|
|
||||||
|
|
||||||
def set_style_config(json_path, output_path):
|
def set_style_config(json_path: Path, output_path: Path):
|
||||||
with open(json_path, "r", encoding="utf-8") as f:
|
with open(json_path, "r", encoding="utf-8") as f:
|
||||||
json_dict = json.load(f)
|
json_dict = json.load(f)
|
||||||
json_dict["data"]["num_styles"] = 1
|
json_dict["data"]["num_styles"] = 1
|
||||||
@@ -17,10 +19,11 @@ def set_style_config(json_path, output_path):
|
|||||||
logger.info(f"Save style config (only {DEFAULT_STYLE}) to {output_path}")
|
logger.info(f"Save style config (only {DEFAULT_STYLE}) to {output_path}")
|
||||||
|
|
||||||
|
|
||||||
def save_mean_vector(wav_dir, output_path):
|
def save_neutral_vector(wav_dir: Union[Path, str], output_path: Union[Path, str]):
|
||||||
|
wav_dir = Path(wav_dir)
|
||||||
|
output_path = Path(output_path)
|
||||||
embs = []
|
embs = []
|
||||||
for file in os.listdir(wav_dir):
|
for file in wav_dir.rglob("*.npy"):
|
||||||
if file.endswith(".npy"):
|
|
||||||
xvec = np.load(os.path.join(wav_dir, file))
|
xvec = np.load(os.path.join(wav_dir, file))
|
||||||
embs.append(np.expand_dims(xvec, axis=0))
|
embs.append(np.expand_dims(xvec, axis=0))
|
||||||
|
|
||||||
|
|||||||
@@ -196,7 +196,7 @@ def run():
|
|||||||
default_style.set_style_config(
|
default_style.set_style_config(
|
||||||
args.config, os.path.join(config.out_dir, "config.json")
|
args.config, os.path.join(config.out_dir, "config.json")
|
||||||
)
|
)
|
||||||
default_style.save_mean_vector(
|
default_style.save_neutral_vector(
|
||||||
os.path.join(args.model, "wavs"),
|
os.path.join(args.model, "wavs"),
|
||||||
os.path.join(config.out_dir, "style_vectors.npy"),
|
os.path.join(config.out_dir, "style_vectors.npy"),
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -195,7 +195,7 @@ def run():
|
|||||||
default_style.set_style_config(
|
default_style.set_style_config(
|
||||||
args.config, os.path.join(config.out_dir, "config.json")
|
args.config, os.path.join(config.out_dir, "config.json")
|
||||||
)
|
)
|
||||||
default_style.save_mean_vector(
|
default_style.save_neutral_vector(
|
||||||
os.path.join(args.model, "wavs"),
|
os.path.join(args.model, "wavs"),
|
||||||
os.path.join(config.out_dir, "style_vectors.npy"),
|
os.path.join(config.out_dir, "style_vectors.npy"),
|
||||||
)
|
)
|
||||||
|
|||||||
Reference in New Issue
Block a user