remove invalid work options

This commit is contained in:
Brandon Thomas
2023-05-01 23:58:46 -07:00
parent 602f3f69e6
commit 4bc9418d50
@@ -119,29 +119,29 @@ def cli():
init_logger() init_logger()
@cli.command() #@cli.command()
@click.option( #@click.option(
"-c", # "-c",
"--config-path", # "--config-path",
type=click.Path(exists=True), # type=click.Path(exists=True),
help="path to config", # help="path to config",
default=Path("./configs/44k/config.json"), # default=Path("./configs/44k/config.json"),
) #)
@click.option( #@click.option(
"-m", # "-m",
"--model-path", # "--model-path",
type=click.Path(), # type=click.Path(),
help="path to output dir", # help="path to output dir",
default=Path("./logs/44k"), # default=Path("./logs/44k"),
) #)
def train(config_path: Path, model_path: Path): #def train(config_path: Path, model_path: Path):
"""Train model # """Train model
If D_0.pth or G_0.pth not found, automatically download from hub.""" # If D_0.pth or G_0.pth not found, automatically download from hub."""
from .train import train # from .train import train
#
config_path = Path(config_path) # config_path = Path(config_path)
model_path = Path(model_path) # model_path = Path(model_path)
train(config_path=config_path, model_path=model_path) # train(config_path=config_path, model_path=model_path)
@cli.command() @cli.command()
@@ -257,352 +257,352 @@ def infer(
) )
@cli.command() #@cli.command()
@click.option( #@click.option(
"-m", # "-m",
"--model-path", # "--model-path",
type=click.Path(exists=True), # type=click.Path(exists=True),
default=Path("./logs/44k/"), # default=Path("./logs/44k/"),
help="path to model", # help="path to model",
) #)
@click.option( #@click.option(
"-c", # "-c",
"--config-path", # "--config-path",
type=click.Path(exists=True), # type=click.Path(exists=True),
default=Path("./configs/44k/config.json"), # default=Path("./configs/44k/config.json"),
help="path to config", # help="path to config",
) #)
@click.option( #@click.option(
"-k", # "-k",
"--cluster-model-path", # "--cluster-model-path",
type=click.Path(exists=True), # type=click.Path(exists=True),
default=None, # default=None,
help="path to cluster model", # help="path to cluster model",
) #)
@click.option("-t", "--transpose", type=int, default=12, help="transpose") #@click.option("-t", "--transpose", type=int, default=12, help="transpose")
@click.option( #@click.option(
"-a", # "-a",
"--auto-predict-f0", # "--auto-predict-f0",
type=bool, # type=bool,
default=False, # default=False,
help="auto predict f0 (not recommended for realtime since voice pitch will not be stable)", # help="auto predict f0 (not recommended for realtime since voice pitch will not be stable)",
) #)
@click.option( #@click.option(
"-r", "--cluster-infer-ratio", type=float, default=0, help="cluster infer ratio" # "-r", "--cluster-infer-ratio", type=float, default=0, help="cluster infer ratio"
) #)
@click.option("-n", "--noise-scale", type=float, default=0.4, help="noise scale") #@click.option("-n", "--noise-scale", type=float, default=0.4, help="noise scale")
@click.option( #@click.option(
"-db", "--db-thresh", type=int, default=-30, help="threshold (DB) (ABSOLUTE)" # "-db", "--db-thresh", type=int, default=-30, help="threshold (DB) (ABSOLUTE)"
) #)
@click.option( #@click.option(
"-fm", # "-fm",
"--f0-method", # "--f0-method",
type=click.Choice(["crepe", "crepe-tiny", "parselmouth", "dio", "harvest"]), # type=click.Choice(["crepe", "crepe-tiny", "parselmouth", "dio", "harvest"]),
default="crepe", # default="crepe",
help="f0 prediction method", # help="f0 prediction method",
) #)
@click.option("-p", "--pad-seconds", type=float, default=0.02, help="pad seconds") #@click.option("-p", "--pad-seconds", type=float, default=0.02, help="pad seconds")
@click.option("-ch", "--chunk-seconds", type=float, default=0.5, help="chunk seconds") #@click.option("-ch", "--chunk-seconds", type=float, default=0.5, help="chunk seconds")
@click.option( #@click.option(
"-cr", # "-cr",
"--crossfade-seconds", # "--crossfade-seconds",
type=float, # type=float,
default=0.01, # default=0.01,
help="crossfade seconds", # help="crossfade seconds",
) #)
@click.option( #@click.option(
"-ab", # "-ab",
"--additional-infer-before-seconds", # "--additional-infer-before-seconds",
type=float, # type=float,
default=0.2, # default=0.2,
help="additional infer before seconds", # help="additional infer before seconds",
) #)
@click.option( #@click.option(
"-aa", # "-aa",
"--additional-infer-after-seconds", # "--additional-infer-after-seconds",
type=float, # type=float,
default=0.1, # default=0.1,
help="additional infer after seconds", # help="additional infer after seconds",
) #)
@click.option("-b", "--block-seconds", type=float, default=0.5, help="block seconds") #@click.option("-b", "--block-seconds", type=float, default=0.5, help="block seconds")
@click.option( #@click.option(
"-d", # "-d",
"--device", # "--device",
type=str, # type=str,
default="cuda" if torch.cuda.is_available() else "cpu", # default="cuda" if torch.cuda.is_available() else "cpu",
help="device", # help="device",
) #)
@click.option("-s", "--speaker", type=str, default=None, help="speaker name") #@click.option("-s", "--speaker", type=str, default=None, help="speaker name")
@click.option("-v", "--version", type=int, default=2, help="version") #@click.option("-v", "--version", type=int, default=2, help="version")
@click.option("-i", "--input-device", type=int, default=None, help="input device") #@click.option("-i", "--input-device", type=int, default=None, help="input device")
@click.option("-o", "--output-device", type=int, default=None, help="output device") #@click.option("-o", "--output-device", type=int, default=None, help="output device")
@click.option( #@click.option(
"-po", # "-po",
"--passthrough-original", # "--passthrough-original",
type=bool, # type=bool,
default=False, # default=False,
is_flag=True, # is_flag=True,
help="passthrough original (for latency check)", # help="passthrough original (for latency check)",
) #)
def vc( #def vc(
# paths # # paths
model_path: Path, # model_path: Path,
config_path: Path, # config_path: Path,
# svc config # # svc config
speaker: str, # speaker: str,
cluster_model_path: Path | None, # cluster_model_path: Path | None,
transpose: int, # transpose: int,
auto_predict_f0: bool, # auto_predict_f0: bool,
cluster_infer_ratio: float, # cluster_infer_ratio: float,
noise_scale: float, # noise_scale: float,
f0_method: Literal["crepe", "crepe-tiny", "parselmouth", "dio", "harvest"], # f0_method: Literal["crepe", "crepe-tiny", "parselmouth", "dio", "harvest"],
# slice config # # slice config
db_thresh: int, # db_thresh: int,
pad_seconds: float, # pad_seconds: float,
chunk_seconds: float, # chunk_seconds: float,
# realtime config # # realtime config
crossfade_seconds: float, # crossfade_seconds: float,
additional_infer_before_seconds: float, # additional_infer_before_seconds: float,
additional_infer_after_seconds: float, # additional_infer_after_seconds: float,
block_seconds: float, # block_seconds: float,
version: int, # version: int,
input_device: int | str | None, # input_device: int | str | None,
output_device: int | str | None, # output_device: int | str | None,
device: Literal["cpu", "cuda"], # device: Literal["cpu", "cuda"],
passthrough_original: bool = False, # passthrough_original: bool = False,
) -> None: #) -> None:
"""Realtime inference from microphone""" # """Realtime inference from microphone"""
from .inference_main import realtime # from .inference_main import realtime
#
if auto_predict_f0: # if auto_predict_f0:
LOG.warning( # LOG.warning(
"auto_predict_f0 = True in realtime inference will cause unstable voice pitch, use with caution" # "auto_predict_f0 = True in realtime inference will cause unstable voice pitch, use with caution"
) # )
else: # else:
LOG.warning( # LOG.warning(
f"auto_predict_f0 = False, transpose = {transpose}. If you want to change the pitch, please change the transpose value." # f"auto_predict_f0 = False, transpose = {transpose}. If you want to change the pitch, please change the transpose value."
"Generally transpose = 0 does not work because your voice pitch and target voice pitch are different." # "Generally transpose = 0 does not work because your voice pitch and target voice pitch are different."
) # )
model_path = Path(model_path) # model_path = Path(model_path)
config_path = Path(config_path) # config_path = Path(config_path)
if cluster_model_path is not None: # if cluster_model_path is not None:
cluster_model_path = Path(cluster_model_path) # cluster_model_path = Path(cluster_model_path)
if model_path.is_dir(): # if model_path.is_dir():
model_path = list(sorted(model_path.glob("*.pth")))[-1] # model_path = list(sorted(model_path.glob("*.pth")))[-1]
LOG.info(f"Since model_path is a directory, use {model_path}") # LOG.info(f"Since model_path is a directory, use {model_path}")
#
realtime( # realtime(
# paths # # paths
model_path=model_path, # model_path=model_path,
config_path=config_path, # config_path=config_path,
# svc config # # svc config
speaker=speaker, # speaker=speaker,
cluster_model_path=cluster_model_path, # cluster_model_path=cluster_model_path,
transpose=transpose, # transpose=transpose,
auto_predict_f0=auto_predict_f0, # auto_predict_f0=auto_predict_f0,
cluster_infer_ratio=cluster_infer_ratio, # cluster_infer_ratio=cluster_infer_ratio,
noise_scale=noise_scale, # noise_scale=noise_scale,
f0_method=f0_method, # f0_method=f0_method,
# slice config # # slice config
db_thresh=db_thresh, # db_thresh=db_thresh,
pad_seconds=pad_seconds, # pad_seconds=pad_seconds,
chunk_seconds=chunk_seconds, # chunk_seconds=chunk_seconds,
# realtime config # # realtime config
crossfade_seconds=crossfade_seconds, # crossfade_seconds=crossfade_seconds,
additional_infer_before_seconds=additional_infer_before_seconds, # additional_infer_before_seconds=additional_infer_before_seconds,
additional_infer_after_seconds=additional_infer_after_seconds, # additional_infer_after_seconds=additional_infer_after_seconds,
block_seconds=block_seconds, # block_seconds=block_seconds,
version=version, # version=version,
input_device=input_device, # input_device=input_device,
output_device=output_device, # output_device=output_device,
device=device, # device=device,
passthrough_original=passthrough_original, # passthrough_original=passthrough_original,
) # )
@cli.command() #@cli.command()
@click.option( #@click.option(
"-i", # "-i",
"--input-dir", # "--input-dir",
type=click.Path(exists=True), # type=click.Path(exists=True),
default=Path("./dataset_raw"), # default=Path("./dataset_raw"),
help="path to source dir", # help="path to source dir",
) #)
@click.option( #@click.option(
"-o", # "-o",
"--output-dir", # "--output-dir",
type=click.Path(), # type=click.Path(),
default=Path("./dataset/44k"), # default=Path("./dataset/44k"),
help="path to output dir", # help="path to output dir",
) #)
@click.option("-s", "--sampling-rate", type=int, default=44100, help="sampling rate") #@click.option("-s", "--sampling-rate", type=int, default=44100, help="sampling rate")
def pre_resample(input_dir: Path, output_dir: Path, sampling_rate: int) -> None: #def pre_resample(input_dir: Path, output_dir: Path, sampling_rate: int) -> None:
"""Preprocessing part 1: resample""" # """Preprocessing part 1: resample"""
from .preprocess_resample import preprocess_resample # from .preprocess_resample import preprocess_resample
#
input_dir = Path(input_dir) # input_dir = Path(input_dir)
output_dir = Path(output_dir) # output_dir = Path(output_dir)
preprocess_resample( # preprocess_resample(
input_dir=input_dir, output_dir=output_dir, sampling_rate=sampling_rate # input_dir=input_dir, output_dir=output_dir, sampling_rate=sampling_rate
) # )
@cli.command() #@cli.command()
@click.option( #@click.option(
"-i", # "-i",
"--input-dir", # "--input-dir",
type=click.Path(exists=True), # type=click.Path(exists=True),
default=Path("./dataset/44k"), # default=Path("./dataset/44k"),
help="path to source dir", # help="path to source dir",
) #)
@click.option( #@click.option(
"-f", # "-f",
"--filelist-path", # "--filelist-path",
type=click.Path(), # type=click.Path(),
default=Path("./filelists/44k"), # default=Path("./filelists/44k"),
help="path to filelist dir", # help="path to filelist dir",
) #)
@click.option( #@click.option(
"-c", # "-c",
"--config-path", # "--config-path",
type=click.Path(), # type=click.Path(),
default=Path("./configs/44k/config.json"), # default=Path("./configs/44k/config.json"),
help="path to config", # help="path to config",
) #)
def pre_config( #def pre_config(
input_dir: Path, # input_dir: Path,
filelist_path: Path, # filelist_path: Path,
config_path: Path, # config_path: Path,
): #):
"""Preprocessing part 2: config""" # """Preprocessing part 2: config"""
from .preprocess_flist_config import preprocess_config # from .preprocess_flist_config import preprocess_config
#
input_dir = Path(input_dir) # input_dir = Path(input_dir)
filelist_path = Path(filelist_path) # filelist_path = Path(filelist_path)
config_path = Path(config_path) # config_path = Path(config_path)
preprocess_config( # preprocess_config(
input_dir=input_dir, # input_dir=input_dir,
train_list_path=filelist_path / "train.txt", # train_list_path=filelist_path / "train.txt",
val_list_path=filelist_path / "val.txt", # val_list_path=filelist_path / "val.txt",
test_list_path=filelist_path / "test.txt", # test_list_path=filelist_path / "test.txt",
config_path=config_path, # config_path=config_path,
) # )
@cli.command() #@cli.command()
@click.option( #@click.option(
"-i", # "-i",
"--input-dir", # "--input-dir",
type=click.Path(exists=True), # type=click.Path(exists=True),
default=Path("./dataset/44k"), # default=Path("./dataset/44k"),
help="path to source dir", # help="path to source dir",
) #)
@click.option( #@click.option(
"-c", # "-c",
"--config-path", # "--config-path",
type=click.Path(exists=True), # type=click.Path(exists=True),
help="path to config", # help="path to config",
default=Path("./configs/44k/config.json"), # default=Path("./configs/44k/config.json"),
) #)
@click.option( #@click.option(
"-n", # "-n",
"--n_jobs", # "--n_jobs",
type=int, # type=int,
default=4, # default=4,
help="number of jobs (optimal value may depend on your VRAM capacity and audio duration per file)", # help="number of jobs (optimal value may depend on your VRAM capacity and audio duration per file)",
) #)
@click.option( #@click.option(
"-f", # "-f",
"--force-rebuild", # "--force-rebuild",
type=bool, # type=bool,
default=True, # default=True,
help="force rebuild existing preprocessed files", # help="force rebuild existing preprocessed files",
) #)
@click.option( #@click.option(
"-fm", # "-fm",
"--f0-method", # "--f0-method",
type=click.Choice(["crepe", "crepe-tiny", "parselmouth", "dio", "harvest"]), # type=click.Choice(["crepe", "crepe-tiny", "parselmouth", "dio", "harvest"]),
default="dio", # default="dio",
) #)
def pre_hubert( #def pre_hubert(
input_dir: Path, # input_dir: Path,
config_path: Path, # config_path: Path,
n_jobs: bool, # n_jobs: bool,
force_rebuild: bool, # force_rebuild: bool,
f0_method: Literal["crepe", "crepe-tiny", "parselmouth", "dio", "harvest"], # f0_method: Literal["crepe", "crepe-tiny", "parselmouth", "dio", "harvest"],
) -> None: #) -> None:
"""Preprocessing part 3: hubert # """Preprocessing part 3: hubert
If the HuBERT model is not found, it will be downloaded automatically.""" # If the HuBERT model is not found, it will be downloaded automatically."""
from .preprocess_hubert_f0 import preprocess_hubert_f0 # from .preprocess_hubert_f0 import preprocess_hubert_f0
#
input_dir = Path(input_dir) # input_dir = Path(input_dir)
config_path = Path(config_path) # config_path = Path(config_path)
preprocess_hubert_f0( # preprocess_hubert_f0(
input_dir=input_dir, # input_dir=input_dir,
config_path=config_path, # config_path=config_path,
n_jobs=n_jobs, # n_jobs=n_jobs,
force_rebuild=force_rebuild, # force_rebuild=force_rebuild,
f0_method=f0_method, # f0_method=f0_method,
) # )
@cli.command #@cli.command
def clean(): #def clean():
"""Clean up files, only useful if you are using the default file structure""" # """Clean up files, only useful if you are using the default file structure"""
import shutil # import shutil
#
folders = ["dataset", "filelists", "logs"] # folders = ["dataset", "filelists", "logs"]
if pyip.inputYesNo(f"Are you sure you want to delete files in {folders}?") == "yes": # if pyip.inputYesNo(f"Are you sure you want to delete files in {folders}?") == "yes":
for folder in folders: # for folder in folders:
if Path(folder).exists(): # if Path(folder).exists():
shutil.rmtree(folder) # shutil.rmtree(folder)
LOG.info("Cleaned up files") # LOG.info("Cleaned up files")
else: # else:
LOG.info("Aborted") # LOG.info("Aborted")
@cli.command #@cli.command
@click.option("-i", "--input-path", type=click.Path(exists=True), help="model path") #@click.option("-i", "--input-path", type=click.Path(exists=True), help="model path")
@click.option("-o", "--output-path", type=click.Path(), help="onnx model path to save") #@click.option("-o", "--output-path", type=click.Path(), help="onnx model path to save")
@click.option("-c", "--config-path", type=click.Path(), help="config path") #@click.option("-c", "--config-path", type=click.Path(), help="config path")
@click.option("-d", "--device", type=str, default="cpu", help="torch device") #@click.option("-d", "--device", type=str, default="cpu", help="torch device")
def onnx(input_path: Path, output_path: Path, config_path: Path, device: str) -> None: #def onnx(input_path: Path, output_path: Path, config_path: Path, device: str) -> None:
"""Export model to onnx""" # """Export model to onnx"""
input_path = Path(input_path) # input_path = Path(input_path)
output_path = Path(output_path) # output_path = Path(output_path)
config_path = Path(config_path) # config_path = Path(config_path)
device_ = torch.device(device) # device_ = torch.device(device)
from .onnx_export import onnx_export # from .onnx_export import onnx_export
#
onnx_export( # onnx_export(
input_path=input_path, # input_path=input_path,
output_path=output_path, # output_path=output_path,
config_path=config_path, # config_path=config_path,
device=device_, # device=device_,
) # )
@cli.command #@cli.command
@click.option( #@click.option(
"-i", # "-i",
"--input-dir", # "--input-dir",
type=click.Path(exists=True), # type=click.Path(exists=True),
help="dataset directory", # help="dataset directory",
default=Path("./dataset/44k"), # default=Path("./dataset/44k"),
) #)
@click.option( #@click.option(
"-o", # "-o",
"--output-path", # "--output-path",
type=click.Path(), # type=click.Path(),
help="model path to save", # help="model path to save",
default=Path("./models/44k/kmeans.pt"), # default=Path("./models/44k/kmeans.pt"),
) #)
@click.option("-n", "--n-clusters", type=int, help="number of clusters", default=10000) #@click.option("-n", "--n-clusters", type=int, help="number of clusters", default=10000)
def train_cluster(input_dir: Path, output_path: Path, n_clusters: int) -> None: #def train_cluster(input_dir: Path, output_path: Path, n_clusters: int) -> None:
"""Train k-means clustering""" # """Train k-means clustering"""
from .cluster.train_cluster import main # from .cluster.train_cluster import main
#
main(input_dir=input_dir, output_path=output_path, n_clusters=n_clusters) # main(input_dir=input_dir, output_path=output_path, n_clusters=n_clusters)
if __name__ == '__main__': if __name__ == '__main__':