Add files via upload

This commit is contained in:
Anjok07 2023-10-17 01:01:19 -05:00 committed by GitHub
parent 89b91563bd
commit 75cd5a7bef
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 152 additions and 71 deletions

104
UVR.py
View File

@ -44,7 +44,11 @@ from lib_v5.vr_network.model_param_init import ModelParameters
from kthread import KThread
from lib_v5 import spec_utils
from pathlib import Path
from separate import SeperateDemucs, SeperateMDX, SeperateMDXC, SeperateVR, save_format
from separate import (
SeperateDemucs, SeperateMDX, SeperateMDXC, SeperateVR, # Model-related
save_format, clear_gpu_cache, # Utility functions
cuda_available, mps_available, #directml_available,
)
from playsound import playsound
from typing import List
import onnx
@ -54,6 +58,15 @@ import yaml
from ml_collections import ConfigDict
from collections import Counter
# if not is_macos:
# import torch_directml
# is_choose_arch = cuda_available and directml_available
# is_opencl_only = not cuda_available and directml_available
# is_cuda_only = cuda_available and not directml_available
is_gpu_available = cuda_available or mps_available# or directml_available
# Change the current working directory to the directory
# this file sits in
if getattr(sys, 'frozen', False):
@ -109,13 +122,6 @@ elif OPERATING_SYSTEM=="Windows":
right_click_button = '<Button-3>'
application_extension = ".exe"
if is_macos:
from torch.mps import empty_cache
else:
from torch.cuda import empty_cache
clear_gpu_cache = empty_cache
def right_click_release_linux(window, top_win=None):
if OPERATING_SYSTEM=="Linux":
root.bind('<Button-1>', lambda e:window.destroy())
@ -332,13 +338,15 @@ class ModelData():
is_get_hash_dir_only=False,
is_vocal_split_model=False):
device_set = root.device_set_var.get()
self.DENOISER_MODEL = DENOISER_MODEL_PATH
self.DEVERBER_MODEL = DEVERBER_MODEL_PATH
self.is_deverb_vocals = root.is_deverb_vocals_var.get() if os.path.isfile(DEVERBER_MODEL_PATH) else False
self.deverb_vocal_opt = DEVERB_MAPPER[root.deverb_vocal_opt_var.get()]
self.is_denoise_model = True if root.denoise_option_var.get() == DENOISE_M and os.path.isfile(DENOISER_MODEL_PATH) else False
self.is_gpu_conversion = 0 if root.is_gpu_conversion_var.get() else -1
self.is_normalization = root.is_normalization_var.get()
self.is_normalization = root.is_normalization_var.get()#
self.is_use_opencl = False#True if is_opencl_only else root.is_use_opencl_var.get()
self.is_primary_stem_only = root.is_primary_stem_only_var.get()
self.is_secondary_stem_only = root.is_secondary_stem_only_var.get()
self.is_denoise = True if not root.denoise_option_var.get() == DENOISE_NONE else False
@ -361,8 +369,8 @@ class ModelData():
self.mdx_stem_count = 1
self.compensate = None
self.mdx_n_fft_scale_set = None
self.wav_type_set = root.wav_type_set#cuda_type
self.cuda_set = root.cuda_set_var.get()#cuda_type
self.wav_type_set = root.wav_type_set#
self.device_set = device_set.split(':')[-1].strip() if ':' in device_set else device_set
self.mp3_bit_set = root.mp3_bit_set_var.get()
self.save_format = root.save_format_var.get()
self.is_invert_spec = root.is_invert_spec_var.get()#
@ -1444,7 +1452,7 @@ class MainWindow(TkinterDnD.Tk if is_dnd_compatible else tk.Tk):
self.mdx_hash_MAPPER = load_model_hash_data(MDX_HASH_JSON)
self.mdx_name_select_MAPPER = load_model_hash_data(MDX_MODEL_NAME_SELECT)
self.demucs_name_select_MAPPER = load_model_hash_data(DEMUCS_MODEL_NAME_SELECT)
self.is_gpu_available = torch.cuda.is_available() if not OPERATING_SYSTEM == 'Darwin' else torch.backends.mps.is_available()
self.is_gpu_available = is_gpu_available
self.is_process_stopped = False
self.inputs_from_dir = []
self.iteration = 0
@ -1492,6 +1500,8 @@ class MainWindow(TkinterDnD.Tk if is_dnd_compatible else tk.Tk):
self.change_state_lambda = None
self.file_one_sub_var = tk.StringVar(value=FILE_ONE_MAIN_LABEL)
self.file_two_sub_var = tk.StringVar(value=FILE_TWO_MAIN_LABEL)
self.cuda_device_list = GPU_DEVICE_NUM_OPTS
self.opencl_list = GPU_DEVICE_NUM_OPTS
#Model Update
self.last_found_ensembles = ENSEMBLE_OPTIONS
@ -1518,6 +1528,7 @@ class MainWindow(TkinterDnD.Tk if is_dnd_compatible else tk.Tk):
self.check_dual_paths()
if not is_windows:
self.update_idletasks()
self.fill_gpu_list()
self.online_data_refresh(user_refresh=False, is_start_up=True)
# Menu Functions
@ -3157,6 +3168,30 @@ class MainWindow(TkinterDnD.Tk if is_dnd_compatible else tk.Tk):
return self.DualBatch_inputPaths
def fill_gpu_list(self):
try:
if cuda_available:
self.cuda_device_list = [f"{torch.cuda.get_device_properties(i).name}:{i}" for i in range(torch.cuda.device_count())]
self.cuda_device_list.insert(0, DEFAULT)
#print(self.cuda_device_list)
# if directml_available:
# self.opencl_list = [f"{torch_directml.device_name(i)}:{i}" for i in range(torch_directml.device_count())]
# self.opencl_list.insert(0, DEFAULT)
except Exception as e:
print(e)
# if is_cuda_only:
# self.is_use_opencl_var.set(False)
check_gpu_list = self.cuda_device_list#self.opencl_list if is_opencl_only or self.is_use_opencl_var.get() else self.cuda_device_list
if not self.device_set_var.get() in check_gpu_list:
self.device_set_var.set(DEFAULT)
def loop_gpu_list(self, option_menu:ComboBoxMenu, menu_name, option_list):
option_menu['values'] = option_list
option_menu.update_dropdown_size(option_list, menu_name)
def menu_settings(self, select_tab_2=False, select_tab_3=False):#**
"""Open Settings and Download Center"""
@ -3210,7 +3245,7 @@ class MainWindow(TkinterDnD.Tk if is_dnd_compatible else tk.Tk):
select_Label = self.menu_sub_LABEL_SET(settings_menu_main_Frame, ADDITIONAL_MENUS_INFORMATION_TEXT)
select_Label.grid(pady=MENU_PADDING_1)
select_Option = ComboBoxMenu(settings_menu_main_Frame, textvariable=self.main_menu_var, values=OPTION_LIST, width=GEN_SETTINGS_WIDTH+(3 if is_windows else 3))
select_Option = ComboBoxMenu(settings_menu_main_Frame, textvariable=self.main_menu_var, values=OPTION_LIST, width=GEN_SETTINGS_WIDTH+3)
select_Option.update_dropdown_size(OPTION_LIST, 'menuchoose', command=lambda e:(self.check_is_menu_open(self.main_menu_var.get()), close_window()))
select_Option.grid(pady=MENU_PADDING_1)
@ -3231,7 +3266,7 @@ class MainWindow(TkinterDnD.Tk if is_dnd_compatible else tk.Tk):
delete_your_settings_Label.grid(pady=MENU_PADDING_2)
self.help_hints(delete_your_settings_Label, text=DELETE_YOUR_SETTINGS_HELP)
delete_your_settings_Option = ComboBoxMenu(settings_menu_main_Frame, textvariable=option_var, width=GEN_SETTINGS_WIDTH+(3 if is_windows else 3))
delete_your_settings_Option = ComboBoxMenu(settings_menu_main_Frame, textvariable=option_var, width=GEN_SETTINGS_WIDTH+3)
delete_your_settings_Option.grid(padx=20,pady=MENU_PADDING_1)
self.deletion_list_fill(delete_your_settings_Option, option_var, SETTINGS_CACHE_DIR, SELECT_SAVED_SETTING, menu_name='deletesetting')
@ -3299,17 +3334,29 @@ class MainWindow(TkinterDnD.Tk if is_dnd_compatible else tk.Tk):
change_model_default_Button = ttk.Button(settings_menu_format_Frame, text=CHANGE_MODEL_DEFAULTS_TEXT, command=lambda:self.pop_up_change_model_defaults(settings_menu), width=SETTINGS_BUT_WIDTH-2)#
change_model_default_Button.grid(pady=MENU_PADDING_4)
#if not is_choose_arch:
self.vocal_splitter_Button_opt(settings_menu, settings_menu_format_Frame, width=SETTINGS_BUT_WIDTH-2, pady=MENU_PADDING_4)
if not is_macos and self.is_gpu_available:
cuda_set_Label = self.menu_title_LABEL_SET(settings_menu_format_Frame, CUDA_NUM_TEXT)
cuda_set_Label.grid(pady=MENU_PADDING_2)
gpu_list_options = lambda:self.loop_gpu_list(device_set_Option, 'gpudevice', self.cuda_device_list)#self.opencl_list if is_opencl_only or self.is_use_opencl_var.get() else self.cuda_device_list)
device_set_Label = self.menu_title_LABEL_SET(settings_menu_format_Frame, CUDA_NUM_TEXT)
device_set_Label.grid(pady=MENU_PADDING_2)
cuda_set_Option = ComboBoxMenu(settings_menu_format_Frame, textvariable=self.cuda_set_var, values=CUDA_TYPE, width=HELP_HINT_CHECKBOX_WIDTH)
cuda_set_Option.grid(padx=20,pady=MENU_PADDING_1)
self.help_hints(cuda_set_Label, text=IS_CUDA_SELECT_HELP)
device_set_Option = ComboBoxMenu(settings_menu_format_Frame, textvariable=self.device_set_var, values=GPU_DEVICE_NUM_OPTS, width=GEN_SETTINGS_WIDTH+1)
device_set_Option.grid(padx=20,pady=MENU_PADDING_1)
gpu_list_options()
self.help_hints(device_set_Label, text=IS_CUDA_SELECT_HELP)
# if is_choose_arch:
# is_use_opencl_Option = ttk.Checkbutton(settings_menu_format_Frame,
# text=USE_OPENCL_TEXT,
# width=9,
# variable=self.is_use_opencl_var,
# command=lambda:(gpu_list_options(), self.device_set_var.set(DEFAULT)))
# is_use_opencl_Option.grid()
# self.help_hints(is_use_opencl_Option, text=IS_NORMALIZATION_HELP)
model_sample_mode_Label = self.menu_title_LABEL_SET(settings_menu_format_Frame, MODEL_SAMPLE_MODE_SETTINGS_TEXT)
model_sample_mode_Label.grid(pady=MENU_PADDING_2)
@ -5147,7 +5194,7 @@ class MainWindow(TkinterDnD.Tk if is_dnd_compatible else tk.Tk):
self.download_update_link_var.set(UPDATE_LINUX_REPO)
if not user_refresh:
if not is_beta_version and not self.lastest_version == PATCH:
if not is_beta_version and not self.lastest_version == current_patch:
self.command_Text.write(NEW_UPDATE_FOUND_TEXT(self.lastest_version))
@ -5497,7 +5544,7 @@ class MainWindow(TkinterDnD.Tk if is_dnd_compatible else tk.Tk):
def update_loop(self):
"""Update the model dropdown menus"""
if self.clear_cache_torch:
clear_gpu_cache()
self.clear_cache_torch = False
@ -6775,7 +6822,7 @@ class MainWindow(TkinterDnD.Tk if is_dnd_compatible else tk.Tk):
self.mp3_bit_set_var = tk.StringVar(value=data['mp3_bit_set'])
self.save_format_var = tk.StringVar(value=data['save_format'])
self.wav_type_set_var = tk.StringVar(value=data['wav_type_set'])#
self.cuda_set_var = tk.StringVar(value=data['cuda_set'])#
self.device_set_var = tk.StringVar(value=data['device_set'])#
self.user_code_var = tk.StringVar(value=data['user_code'])
self.is_gpu_conversion_var = tk.BooleanVar(value=data['is_gpu_conversion'])
self.is_primary_stem_only_var = tk.BooleanVar(value=data['is_primary_stem_only'])
@ -6787,6 +6834,7 @@ class MainWindow(TkinterDnD.Tk if is_dnd_compatible else tk.Tk):
self.is_accept_any_input_var = tk.BooleanVar(value=data['is_accept_any_input'])
self.is_task_complete_var = tk.BooleanVar(value=data['is_task_complete'])
self.is_normalization_var = tk.BooleanVar(value=data['is_normalization'])#
self.is_use_opencl_var = tk.BooleanVar(value=False)#True if is_opencl_only else data['is_use_opencl'])#
self.is_wav_ensemble_var = tk.BooleanVar(value=data['is_wav_ensemble'])#
self.is_create_model_folder_var = tk.BooleanVar(value=data['is_create_model_folder'])
self.help_hints_var = tk.BooleanVar(value=data['help_hints_var'])
@ -6918,7 +6966,7 @@ class MainWindow(TkinterDnD.Tk if is_dnd_compatible else tk.Tk):
self.semitone_shift_var.set(loaded_setting['semitone_shift'])#
self.save_format_var.set(loaded_setting['save_format'])
self.wav_type_set_var.set(loaded_setting['wav_type_set'])#
self.cuda_set_var.set(loaded_setting['cuda_set'])#
self.device_set_var.set(loaded_setting['device_set'])#
self.user_code_var.set(loaded_setting['user_code'])
self.phase_option_var.set(loaded_setting['phase_option'])#
self.phase_shifts_var.set(loaded_setting['phase_shifts'])#
@ -6936,6 +6984,7 @@ class MainWindow(TkinterDnD.Tk if is_dnd_compatible else tk.Tk):
self.is_gpu_conversion_var.set(loaded_setting['is_gpu_conversion'])
self.is_normalization_var.set(loaded_setting['is_normalization'])#
self.is_use_opencl_var.set(False)#True if is_opencl_only else loaded_setting['is_use_opencl'])#
self.is_wav_ensemble_var.set(loaded_setting['is_wav_ensemble'])#
self.help_hints_var.set(loaded_setting['help_hints_var'])
self.is_wav_ensemble_var.set(loaded_setting['is_wav_ensemble'])
@ -7046,13 +7095,14 @@ class MainWindow(TkinterDnD.Tk if is_dnd_compatible else tk.Tk):
'is_accept_any_input': self.is_accept_any_input_var.get(),
'is_task_complete': self.is_task_complete_var.get(),
'is_normalization': self.is_normalization_var.get(),#
'is_use_opencl': self.is_use_opencl_var.get(),#
'is_wav_ensemble': self.is_wav_ensemble_var.get(),#
'is_create_model_folder': self.is_create_model_folder_var.get(),
'mp3_bit_set': self.mp3_bit_set_var.get(),
'semitone_shift': self.semitone_shift_var.get(),#
'save_format': self.save_format_var.get(),
'wav_type_set': self.wav_type_set_var.get(),#
'cuda_set': self.cuda_set_var.get(),#
'device_set': self.device_set_var.get(),#
'user_code': self.user_code_var.get(),
'help_hints_var': self.help_hints_var.get(),
'set_vocal_splitter': self.set_vocal_splitter_var.get(),

View File

@ -31,20 +31,40 @@ import math
#import random
from onnx import load
from onnx2pytorch import ConvertModel
if is_macos:
from torch.mps import empty_cache
else:
from torch.cuda import empty_cache
import gc
if TYPE_CHECKING:
from UVR import ModelData
# if not is_macos:
# import torch_directml
mps_available = torch.backends.mps.is_available() if is_macos else False
cuda_available = torch.cuda.is_available()
# def get_gpu_info():
# directml_device, directml_available = DIRECTML_DEVICE, False
# if not is_macos:
# directml_available = torch_directml.is_available()
# if directml_available:
# directml_device = str(torch_directml.device()).partition(":")[0]
# return directml_device, directml_available
# DIRECTML_DEVICE, directml_available = get_gpu_info()
def clear_gpu_cache():
gc.collect()
if is_macos:
torch.mps.empty_cache()
else:
torch.cuda.empty_cache()
warnings.filterwarnings("ignore")
cpu = torch.device('cpu')
clear_gpu_cache = empty_cache
class SeperateAttributes:
def __init__(self, model_data: ModelData,
process_data: dict,
@ -97,7 +117,6 @@ class SeperateAttributes:
self.model_name = model_data.model_name
self.model_basename = model_data.model_basename
self.wav_type_set = model_data.wav_type_set
self.cuda_set = model_data.cuda_set
self.mp3_bit_set = model_data.mp3_bit_set
self.save_format = model_data.save_format
self.is_gpu_conversion = model_data.is_gpu_conversion
@ -125,7 +144,7 @@ class SeperateAttributes:
self.main_model_primary = main_model_primary
self.ensemble_primary_stem = model_data.ensemble_primary_stem
self.is_multi_stem_ensemble = model_data.is_multi_stem_ensemble
self.is_mps = False
self.is_other_gpu = False
self.is_deverb = True
self.DENOISER_MODEL = model_data.DENOISER_MODEL
self.DEVERBER_MODEL = model_data.DEVERBER_MODEL
@ -145,8 +164,11 @@ class SeperateAttributes:
self.stem_path_init = os.path.join(self.export_path, f'{self.audio_file_base}_({self.secondary_stem}).wav')
self.deverb_vocal_opt = model_data.deverb_vocal_opt
self.is_save_vocal_only = model_data.is_save_vocal_only
self.device = 'cpu'
self.device = cpu
self.run_type = ['CPUExecutionProvider']
self.is_opencl = False
self.device_set = model_data.device_set
self.is_use_opencl = model_data.is_use_opencl
if self.is_inst_only_voc_splitter or self.is_sec_bv_rebalance:
self.is_primary_stem_only = False
@ -156,13 +178,19 @@ class SeperateAttributes:
self.primary_stem, self.secondary_stem = main_model_primary, secondary_stem(main_model_primary)
if self.is_gpu_conversion >= 0:
if OPERATING_SYSTEM == 'Darwin' and torch.backends.mps.is_available():
self.device = 'mps'
self.is_mps = True
elif torch.cuda.is_available():
#print("CUDA: ", self.cuda_set)
self.device = 'cuda' if self.cuda_set == DEFAULT else f'cuda:{self.cuda_set}'
self.run_type = ['CUDAExecutionProvider']
if mps_available:
self.device, self.is_other_gpu = 'mps', True
else:
device_prefix = None
if self.device_set != DEFAULT:
device_prefix = CUDA_DEVICE#DIRECTML_DEVICE if self.is_use_opencl and directml_available else CUDA_DEVICE
# if directml_available and self.is_use_opencl:
# self.device = torch_directml.device() if not device_prefix else f'{device_prefix}:{self.device_set}'
# self.is_other_gpu = True
if cuda_available:# and not self.is_use_opencl:
self.device = CUDA_DEVICE if not device_prefix else f'{device_prefix}:{self.device_set}'
self.run_type = ['CUDAExecutionProvider']
if model_data.process_method == MDX_ARCH_TYPE:
self.is_mdx_ckpt = model_data.is_mdx_ckpt
@ -201,7 +229,7 @@ class SeperateAttributes:
self.is_demucs_combine_stems = model_data.is_demucs_combine_stems
self.demucs_stem_count = model_data.demucs_stem_count
self.pre_proc_model = model_data.pre_proc_model
self.device = 'cpu' if self.is_mps and not self.demucs_version == DEMUCS_V4 else self.device
self.device = cpu if self.is_other_gpu and not self.demucs_version in [DEMUCS_V3, DEMUCS_V4] else self.device
self.primary_stem = model_data.ensemble_primary_stem if process_data['is_ensemble_master'] else model_data.primary_stem
self.secondary_stem = model_data.ensemble_secondary_stem if process_data['is_ensemble_master'] else model_data.secondary_stem
@ -458,7 +486,7 @@ class SeperateMDX(SeperateAttributes):
separator = MdxnetSet.ConvTDFNet(**model_params)
self.model_run = separator.load_from_checkpoint(self.model_path).to(self.device).eval()
else:
if self.mdx_segment_size == self.dim_t and not self.is_mps:
if self.mdx_segment_size == self.dim_t and not self.is_other_gpu:
ort_ = ort.InferenceSession(self.model_path, providers=self.run_type)
self.model_run = lambda spek:ort_.run(None, {'input': spek.cpu().numpy()})[0]
else:
@ -467,6 +495,7 @@ class SeperateMDX(SeperateAttributes):
self.running_inference_console_write()
mix = prepare_mix(self.audio_file)
source = self.demix(mix)
if not self.is_vocal_split_model:
@ -493,7 +522,7 @@ class SeperateMDX(SeperateAttributes):
self.primary_source = source.T
self.primary_source_map = self.final_process(primary_stem_path, self.primary_source, self.secondary_source_primary, self.primary_stem, samplerate)
clear_gpu_cache()
secondary_sources = {**self.primary_source_map, **self.secondary_source_map}
@ -508,7 +537,7 @@ class SeperateMDX(SeperateAttributes):
self.trim = self.n_fft//2
self.chunk_size = self.hop * (self.mdx_segment_size-1)
self.gen_size = self.chunk_size-2*self.trim
self.stft = STFT(self.n_fft, self.hop, self.dim_f)
self.stft = STFT(self.n_fft, self.hop, self.dim_f, self.device)
def demix(self, mix, is_match_mix=False):
self.initialize_model_settings()
@ -557,13 +586,13 @@ class SeperateMDX(SeperateAttributes):
mix_part = torch.tensor([mix_part_], dtype=torch.float32).to(self.device)
mix_waves = mix_part.split(self.mdx_batch_size)
with torch.no_grad():
for mix_wave in mix_waves:
self.running_inference_progress_bar(total_chunks, is_match_mix=is_match_mix)
tar_waves = self.run_model(mix_wave, is_match_mix=is_match_mix)
if window is not None:
tar_waves[..., :chunk_size_actual] *= window
divider[..., start:end] += window
@ -571,7 +600,7 @@ class SeperateMDX(SeperateAttributes):
divider[..., start:end] += 1
result[..., start:end] += tar_waves[..., :end-start]
tar_waves = result / divider
tar_waves_.append(tar_waves)
@ -707,9 +736,10 @@ class SeperateMDXC(SeperateAttributes):
org_mix = mix
if self.is_pitch_change:
mix, sr_pitched = spec_utils.change_pitch_semitones(mix, 44100, semitone_shift=-self.semitone_shift)
model = TFC_TDF_net(self.mdx_c_configs).eval().to(self.device)
model.load_state_dict(torch.load(self.model_path, map_location=self.device))
model = TFC_TDF_net(self.mdx_c_configs, device=self.device)
model.load_state_dict(torch.load(self.model_path, map_location=cpu))
model.to(self.device).eval()
mix = torch.tensor(mix, dtype=torch.float32)
try:
@ -720,37 +750,37 @@ class SeperateMDXC(SeperateAttributes):
mdx_segment_size = self.mdx_c_configs.inference.dim_t if self.is_mdx_c_seg_def else self.mdx_segment_size
batch_size = self.mdx_batch_size
C = self.mdx_c_configs.audio.hop_length * (mdx_segment_size - 1)
N = self.overlap_mdx23
chunk_size = self.mdx_c_configs.audio.hop_length * (mdx_segment_size - 1)
overlap = self.overlap_mdx23
H = C // N
L = mix.shape[1]
pad_size = H - (L - C) % H
mix = torch.cat([torch.zeros(2, C - H), mix, torch.zeros(2, pad_size + C - H)], 1)
hop_size = chunk_size // overlap
mix_shape = mix.shape[1]
pad_size = hop_size - (mix_shape - chunk_size) % hop_size
mix = torch.cat([torch.zeros(2, chunk_size - hop_size), mix, torch.zeros(2, pad_size + chunk_size - hop_size)], 1)
mix = mix.to(self.device)
chunks = mix.unfold(1, C, H).transpose(0, 1)
chunks = mix.unfold(1, chunk_size, hop_size).transpose(0, 1)
batches = [chunks[i : i + batch_size] for i in range(0, len(chunks), batch_size)]
X = torch.zeros(S, *mix.shape).to(self.device) if S > 1 else torch.zeros_like(mix)
#with torch.cuda.amp.autocast():
X = torch.zeros(S, *mix.shape).to(self.device) if S > 1 else torch.zeros_like(mix).to(self.device)
with torch.no_grad():
cnt = 0
for batch in batches:
self.running_inference_progress_bar(len(batches))
x = model(batch)
for w in x:
X[..., cnt * H : cnt * H + C] += w
X[..., cnt * hop_size : cnt * hop_size + chunk_size] += w
cnt += 1
estimated_sources = X[..., C - H:-(pad_size + C - H)] / N
estimated_sources = X[..., chunk_size - hop_size:-(pad_size + chunk_size - hop_size)] / overlap
del X
pitch_fix = lambda s:self.pitch_fix(s, sr_pitched, org_mix)
if S > 1:
sources = {k: pitch_fix(v) if self.is_pitch_change else v for k, v in zip(self.mdx_c_configs.training.instruments, estimated_sources.cpu().detach().numpy())}
del estimated_sources
if self.is_denoise_model:
if VOCAL_STEM in sources.keys() and INST_STEM in sources.keys():
sources[VOCAL_STEM] = vr_denoiser(sources[VOCAL_STEM], self.device, model_path=self.DENOISER_MODEL)
@ -761,6 +791,7 @@ class SeperateMDXC(SeperateAttributes):
return sources
else:
est_s = estimated_sources.cpu().detach().numpy()
del estimated_sources
return pitch_fix(est_s) if self.is_pitch_change else est_s
class SeperateDemucs(SeperateAttributes):
@ -1328,7 +1359,7 @@ def vr_denoiser(X, device, hop_length=1024, n_fft=2048, cropsize=256, is_deverbe
nout, nout_lstm = 16, 128
model = nets_new.CascadedNet(n_fft, nout=nout, nout_lstm=nout_lstm)
model.load_state_dict(torch.load(model_path, map_location=device))
model.load_state_dict(torch.load(model_path, map_location=cpu))
model.to(device)
if mp is None:
@ -1425,4 +1456,4 @@ def loading_mix(X, mp):
del X_wave, X_spec_s
return X_spec
return X_spec