Skip to content

Commit

Permalink
changed to pretraineds hifigan + small fix on model download
Browse files Browse the repository at this point in the history
  • Loading branch information
blaisewf committed Jan 6, 2025
1 parent 494fee1 commit 778988f
Show file tree
Hide file tree
Showing 9 changed files with 18 additions and 62 deletions.
3 changes: 1 addition & 2 deletions app.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,7 @@
from core import run_prerequisites_script

run_prerequisites_script(
pretraineds_v2_f0=True,
pretraineds_v2_nof0=False,
pretraineds_hifigan=True,
models=True,
exe=True,
)
Expand Down
18 changes: 4 additions & 14 deletions core.py
Original file line number Diff line number Diff line change
Expand Up @@ -602,14 +602,12 @@ def run_download_script(model_link: str):

# Prerequisites
def run_prerequisites_script(
pretraineds_v2_f0: bool,
pretraineds_v2_nof0: bool,
pretraineds_hifigan: bool,
models: bool,
exe: bool,
):
prequisites_download_pipeline(
pretraineds_v2_f0,
pretraineds_v2_nof0,
pretraineds_hifigan,
models,
exe,
)
Expand Down Expand Up @@ -2152,19 +2150,12 @@ def parse_arguments():
"prerequisites", help="Install prerequisites for RVC."
)
prerequisites_parser.add_argument(
"--pretraineds_v2_f0",
"--pretraineds_hifigan",
type=lambda x: bool(strtobool(x)),
choices=[True, False],
default=True,
help="Download pretrained models for RVC v2.",
)
prerequisites_parser.add_argument(
"--pretraineds_v2_nof0",
type=lambda x: bool(strtobool(x)),
choices=[True, False],
default=False,
help="Download non f0 pretrained models for RVC v2.",
)
prerequisites_parser.add_argument(
"--models",
type=lambda x: bool(strtobool(x)),
Expand Down Expand Up @@ -2423,8 +2414,7 @@ def main():
)
elif args.mode == "prerequisites":
run_prerequisites_script(
pretraineds_v2_f0=args.pretraineds_v2_f0,
pretraineds_v2_nof0=args.pretraineds_v2_nof0,
pretraineds_hifigan=args.pretraineds_hifigan,
models=args.models,
exe=args.exe,
)
Expand Down
9 changes: 0 additions & 9 deletions rvc/infer/pipeline.py
Original file line number Diff line number Diff line change
Expand Up @@ -687,15 +687,6 @@ def pipeline(
audio_opt = AudioProcessor.change_rms(
audio, self.sample_rate, audio_opt, self.sample_rate, volume_envelope
)
# if resample_sr >= self.sample_rate and tgt_sr != resample_sr:
# audio_opt = librosa.resample(
# audio_opt, orig_sr=tgt_sr, target_sr=resample_sr
# )
# audio_max = np.abs(audio_opt).max() / 0.99
# max_int16 = 32768
# if audio_max > 1:
# max_int16 /= audio_max
# audio_opt = (audio_opt * 32768).astype(np.int16)
audio_max = np.abs(audio_opt).max() / 0.99
if audio_max > 1:
audio_opt /= audio_max
Expand Down
9 changes: 1 addition & 8 deletions rvc/lib/tools/model_download.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,7 @@
from rvc.lib.tools import gdown


def find_folder_parent(search_dir, folder_name):
for dirpath, dirnames, _ in os.walk(search_dir):
if folder_name in dirnames:
return os.path.abspath(dirpath)
return None


file_path = find_folder_parent(now_dir, "logs")
file_path = os.path.join(now_dir, "logs")
zips_path = os.path.join(file_path, "zips")
os.makedirs(zips_path, exist_ok=True)

Expand Down
28 changes: 7 additions & 21 deletions rvc/lib/tools/prerequisites_download.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,6 @@
(
"pretrained_v2/",
[
"D32k.pth",
"D40k.pth",
"D48k.pth",
"G32k.pth",
"G40k.pth",
"G48k.pth",
"f0D32k.pth",
"f0D40k.pth",
"f0D48k.pth",
Expand Down Expand Up @@ -106,14 +100,11 @@ def split_pretraineds(pretrained_list):
return f0_list, non_f0_list


pretraineds_v2_f0_list, pretraineds_v2_nof0_list = split_pretraineds(
pretraineds_hifigan_list
)
pretraineds_hifigan_list, _ = split_pretraineds(pretraineds_hifigan_list)


def calculate_total_size(
pretraineds_v2_f0,
pretraineds_v2_nof0,
pretraineds_hifigan,
models,
exe,
):
Expand All @@ -126,23 +117,20 @@ def calculate_total_size(
total_size += get_file_size_if_missing(embedders_list)
if exe and os.name == "nt":
total_size += get_file_size_if_missing(executables_list)
total_size += get_file_size_if_missing(pretraineds_v2_f0)
total_size += get_file_size_if_missing(pretraineds_v2_nof0)
total_size += get_file_size_if_missing(pretraineds_hifigan)
return total_size


def prequisites_download_pipeline(
pretraineds_v2_f0,
pretraineds_v2_nof0,
pretraineds_hifigan,
models,
exe,
):
"""
Manage the download pipeline for different categories of files.
"""
total_size = calculate_total_size(
pretraineds_v2_f0_list if pretraineds_v2_f0 else [],
pretraineds_v2_nof0_list if pretraineds_v2_nof0 else [],
pretraineds_hifigan_list if pretraineds_hifigan else [],
models,
exe,
)
Expand All @@ -159,9 +147,7 @@ def prequisites_download_pipeline(
download_mapping_files(executables_list, global_bar)
else:
print("No executables needed")
if pretraineds_v2_f0:
download_mapping_files(pretraineds_v2_f0_list, global_bar)
if pretraineds_v2_nof0:
download_mapping_files(pretraineds_v2_nof0_list, global_bar)
if pretraineds_hifigan:
download_mapping_files(pretraineds_hifigan_list, global_bar)
else:
pass
7 changes: 3 additions & 4 deletions rvc/lib/tools/pretrained_selector.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
import os


def pretrained_selector(vocoder, pitch_guidance, sample_rate):
def pretrained_selector(vocoder, sample_rate):
base_path = os.path.join("rvc", "models", "pretraineds", f"{vocoder.lower()}")
f0 = "f0" if pitch_guidance else ""

path_g = os.path.join(base_path, f"{f0}G{str(sample_rate)[:2]}k.pth")
path_d = os.path.join(base_path, f"{f0}D{str(sample_rate)[:2]}k.pth")
path_g = os.path.join(base_path, f"f0G{str(sample_rate)[:2]}k.pth")
path_d = os.path.join(base_path, f"f0D{str(sample_rate)[:2]}k.pth")

if os.path.exists(path_g) and os.path.exists(path_d):
return path_g, path_d
Expand Down
2 changes: 1 addition & 1 deletion rvc/train/process/extract_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,14 @@ def replace_keys_in_dict(d, old_key_part, new_key_part):
def extract_model(
ckpt,
sr,
pitch_guidance,
name,
model_path,
epoch,
step,
hps,
overtrain_info,
vocoder,
pitch_guidance=True,
version="v2",
):
try:
Expand Down
1 change: 0 additions & 1 deletion rvc/train/train.py
Original file line number Diff line number Diff line change
Expand Up @@ -999,7 +999,6 @@ def train_and_evaluate(
extract_model(
ckpt=ckpt,
sr=sample_rate,
pitch_guidance=True,
name=model_name,
model_path=m,
epoch=epoch,
Expand Down
3 changes: 1 addition & 2 deletions tabs/train/train.py
Original file line number Diff line number Diff line change
Expand Up @@ -876,8 +876,7 @@ def download_prerequisites():
"Checking for prerequisites with pitch guidance... Missing files will be downloaded. If you already have them, this step will be skipped."
)
run_prerequisites_script(
pretraineds_v2_f0=True,
pretraineds_v2_nof0=False,
pretraineds_hifigan=True,
models=False,
exe=False,
)
Expand Down

0 comments on commit 778988f

Please sign in to comment.