mirror of
https://github.com/RVC-Boss/GPT-SoVITS.git
synced 2025-06-24 21:39:17 +08:00
* Docker Auto-Build Workflow * Rename * Update * Fix Bugs * Disable Progress Bar When workflows triggered * Fix Wget * Fix Bugs * Fix Bugs * Update Wget * Update Workflows * Accelerate Docker Image Building * Fix Install.sh * Add Skip-Check For Action Runner * Fix Dockerfile * . * . * . * . * Delete File in Runner * Add Sort * Delete More Files * Delete More * . * . * . * Add Pre-Commit Hook Update Docker * Add Code Spell Check * [pre-commit.ci] trigger * [pre-commit.ci] trigger * [pre-commit.ci] trigger * Fix Bugs * . * Disable Progress Bar and Logs while using GitHub Actions * . * . * Fix Bugs * update conda * fix bugs * Fix Bugs * fix bugs * . * . * Quiet Installation * fix bugs * . * fix bug * . * Fix pre-commit.ci and Docker * fix bugs * . * Update Docker & Pre-Commit * fix bugs * Update Req * Update Req * Update OpenCC * update precommit * . * Update .pre-commit-config.yaml * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Update Docs and fix bugs * Fix \ * Fix MacOS * . * test * . * Add Tag Alias * . * fix bugs * fix bugs * make image smaller * update pre-commit config * . * . * fix bugs * use miniconda * Fix Wrong Path * . * debug * debug * revert * Fix Bugs * Update Docs, Add Dict Auto Download in install.sh * update docker_build * Update Docs for Install.sh * update docker docs about architecture * Add Xcode-Commandline-Tool Installation * Update Docs 1. Add Missing VC17 2. Modufied the Order of FFmpeg Installation and Requirements Installation 3. Remove Duplicate FFmpeg * Fix Wrong Cuda Version * Update TESTED ENV * Add PYTHONNOUSERSITE(-s) * Fix Wrapper * Update install.sh For Robustness * Ignore .git * Preload CUDNN For Ctranslate2 * Remove Gradio Warnings * Update Colab * Fix OpenCC Problems * Update Win DLL Strategy * Fix Onnxruntime-gpu NVRTC Error * Fix Path Problems * Add Windows Packages Workflow * WIP * WIP * WIP * WIP * WIP * WIP * . * WIP * WIP * WIP * WIP * WIP * WIP * WIP * WIP * WIP * WIP * WIP * WIP * WIP * WIP * WIP * WIP * WIP * WIP * WIP * WIP * WIP * WIP * WIP * WIP * WIP * WIP * WIP * WIP * WIP * WIP * WIP * WIP * WIP * WIP * WIP * WIP * WIP * Fix Path * Fix Path * Enable Logging * Set 7-Zip compression level to maximum (-mx=9) * Use Multithread in ONNX Session * Fix Tag Bugs * Add Time * Add Time * Add Time * Compress More * Copy DLL to Solve VC Runtime DLL Missing Issues * Expose FFmpeg Errors, Copy Only Part of Visual C++ Runtime * Update build_windows_packages.ps1 * Update build_windows_packages.ps1 * Update build_windows_packages.ps1 * Update build_windows_packages.ps1 * WIP * WIP * WIP * Update build_windows_packages.ps1 * Update install.sh * Update build_windows_packages.ps1 * Update docker-publish.yaml * Update install.sh * Update Dockerfile * Update docker_build.sh * Update miniconda_install.sh * Update README.md * Update README.md * Update README.md * Update README.md * Update README.md * Update README.md * Update Colab-WebUI.ipynb * Update Colab-Inference.ipynb * Update docker-compose.yaml * 更新 build_windows_packages.ps1 * Update install.sh --------- Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
114 lines
3.4 KiB
Python
114 lines
3.4 KiB
Python
import json
|
|
|
|
import numpy as np
|
|
import torch
|
|
from tqdm import tqdm
|
|
|
|
|
|
def load_data(file_name: str = "./lib/name_params.json") -> dict:
|
|
with open(file_name, "r") as f:
|
|
data = json.load(f)
|
|
|
|
return data
|
|
|
|
|
|
def make_padding(width, cropsize, offset):
|
|
left = offset
|
|
roi_size = cropsize - left * 2
|
|
if roi_size == 0:
|
|
roi_size = cropsize
|
|
right = roi_size - (width % roi_size) + left
|
|
|
|
return left, right, roi_size
|
|
|
|
|
|
def inference(X_spec, device, model, aggressiveness, data):
|
|
"""
|
|
data : dic configs
|
|
"""
|
|
|
|
def _execute(X_mag_pad, roi_size, n_window, device, model, aggressiveness, is_half=True):
|
|
model.eval()
|
|
with torch.no_grad():
|
|
preds = []
|
|
|
|
iterations = [n_window]
|
|
|
|
total_iterations = sum(iterations)
|
|
for i in tqdm(range(n_window)):
|
|
start = i * roi_size
|
|
X_mag_window = X_mag_pad[None, :, :, start : start + data["window_size"]]
|
|
X_mag_window = torch.from_numpy(X_mag_window)
|
|
if is_half:
|
|
X_mag_window = X_mag_window.half()
|
|
X_mag_window = X_mag_window.to(device)
|
|
|
|
pred = model.predict(X_mag_window, aggressiveness)
|
|
|
|
pred = pred.detach().cpu().numpy()
|
|
preds.append(pred[0])
|
|
|
|
pred = np.concatenate(preds, axis=2)
|
|
return pred
|
|
|
|
def preprocess(X_spec):
|
|
X_mag = np.abs(X_spec)
|
|
X_phase = np.angle(X_spec)
|
|
|
|
return X_mag, X_phase
|
|
|
|
X_mag, X_phase = preprocess(X_spec)
|
|
|
|
coef = X_mag.max()
|
|
X_mag_pre = X_mag / coef
|
|
|
|
n_frame = X_mag_pre.shape[2]
|
|
pad_l, pad_r, roi_size = make_padding(n_frame, data["window_size"], model.offset)
|
|
n_window = int(np.ceil(n_frame / roi_size))
|
|
|
|
X_mag_pad = np.pad(X_mag_pre, ((0, 0), (0, 0), (pad_l, pad_r)), mode="constant")
|
|
|
|
if list(model.state_dict().values())[0].dtype == torch.float16:
|
|
is_half = True
|
|
else:
|
|
is_half = False
|
|
pred = _execute(X_mag_pad, roi_size, n_window, device, model, aggressiveness, is_half)
|
|
pred = pred[:, :, :n_frame]
|
|
|
|
if data["tta"]:
|
|
pad_l += roi_size // 2
|
|
pad_r += roi_size // 2
|
|
n_window += 1
|
|
|
|
X_mag_pad = np.pad(X_mag_pre, ((0, 0), (0, 0), (pad_l, pad_r)), mode="constant")
|
|
|
|
pred_tta = _execute(X_mag_pad, roi_size, n_window, device, model, aggressiveness, is_half)
|
|
pred_tta = pred_tta[:, :, roi_size // 2 :]
|
|
pred_tta = pred_tta[:, :, :n_frame]
|
|
|
|
return (pred + pred_tta) * 0.5 * coef, X_mag, np.exp(1.0j * X_phase)
|
|
else:
|
|
return pred * coef, X_mag, np.exp(1.0j * X_phase)
|
|
|
|
|
|
def _get_name_params(model_path, model_hash):
|
|
data = load_data()
|
|
flag = False
|
|
ModelName = model_path
|
|
for type in list(data):
|
|
for model in list(data[type][0]):
|
|
for i in range(len(data[type][0][model])):
|
|
if str(data[type][0][model][i]["hash_name"]) == model_hash:
|
|
flag = True
|
|
elif str(data[type][0][model][i]["hash_name"]) in ModelName:
|
|
flag = True
|
|
|
|
if flag:
|
|
model_params_auto = data[type][0][model][i]["model_params"]
|
|
param_name_auto = data[type][0][model][i]["param_name"]
|
|
if type == "equivalent":
|
|
return param_name_auto, model_params_auto
|
|
else:
|
|
flag = False
|
|
return param_name_auto, model_params_auto
|