Add files via upload

This commit is contained in:
Anjok07 2022-07-23 02:56:57 -05:00 committed by GitHub
parent 063f015d5d
commit b011d37a58
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 6150 additions and 2150 deletions

4176
UVR.py

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -1,37 +1,37 @@
import os
from pathlib import Path
import os.path
from datetime import datetime
import pydub
import shutil
from random import randrange
#MDX-Net
#----------------------------------------
import soundfile as sf
import torch
import numpy as np
from demucs.pretrained import get_model as _gm
from demucs.hdemucs import HDemucs
from demucs.apply import BagOfModels, apply_model
from demucs.audio import AudioFile
import time
import os
from tqdm import tqdm
import warnings
import sys
import librosa
import psutil
#----------------------------------------
from demucs.hdemucs import HDemucs
from demucs.model_v2 import Demucs
from demucs.pretrained import get_model as _gm
from demucs.tasnet_v2 import ConvTasNet
from demucs.utils import apply_model_v1
from demucs.utils import apply_model_v2
from diffq import DiffQuantizer
from lib_v5 import spec_utils
from lib_v5.model_param_init import ModelParameters
import torch
# Command line text parsing and widget manipulation
import tkinter as tk
import traceback # Error Message Recent Calls
from pathlib import Path
from random import randrange
from tqdm import tqdm
import gzip
import io
import librosa
import numpy as np
import os
import os
import os.path
import psutil
import pydub
import shutil
import soundfile as sf
import sys
import time
import time # Timer
import tkinter as tk
import torch
import torch.hub
import traceback # Error Message Recent Calls
import warnings
import zlib
class Predictor():
def __init__(self):
@ -46,40 +46,62 @@ class Predictor():
if data['gpu'] == -1:
device = torch.device('cpu')
self.demucs = HDemucs(sources=["drums", "bass", "other", "vocals"])
widget_text.write(base_text + 'Loading Demucs model... ')
update_progress(**progress_kwargs,
step=0.05)
path_d = Path('models/Demucs_Models')
print('What Demucs model was chosen? ', data['DemucsModel'])
self.demucs = _gm(name=data['DemucsModel'], repo=path_d)
widget_text.write('Done!\n')
if 'UVR' in data['DemucsModel']:
widget_text.write(base_text + "2 stem model selected.\n")
if isinstance(self.demucs, BagOfModels):
widget_text.write(base_text + f"Selected model is a bag of {len(self.demucs.models)} models.\n")
if data['segment'] == 'None':
segment = None
if isinstance(self.demucs, BagOfModels):
if segment is not None:
for sub in self.demucs.models:
sub.segment = segment
if demucs_model_version == 'v1':
load_from = "models/Demucs_Models/"f"{demucs_model_set_name}"
if str(load_from).endswith(".gz"):
load_from = gzip.open(load_from, "rb")
klass, args, kwargs, state = torch.load(load_from)
self.demucs = klass(*args, **kwargs)
widget_text.write(base_text + 'Loading Demucs v1 model... ')
update_progress(**progress_kwargs,
step=0.05)
self.demucs.to(device)
self.demucs.load_state_dict(state)
widget_text.write('Done!\n')
if not data['segment'] == 'None':
widget_text.write(base_text + 'Segments is only available in Demucs v3. Please use \"Chunks\" instead.\n')
else:
if segment is not None:
sub.segment = segment
else:
try:
segment = int(data['segment'])
if isinstance(self.demucs, BagOfModels):
if segment is not None:
for sub in self.demucs.models:
sub.segment = segment
else:
if segment is not None:
sub.segment = segment
widget_text.write(base_text + "Segments set to "f"{segment}.\n")
except:
pass
if demucs_model_version == 'v2':
if '48' in demucs_model_set_name:
channels=48
elif 'unittest' in demucs_model_set_name:
channels=4
else:
channels=64
if 'tasnet' in demucs_model_set_name:
self.demucs = ConvTasNet(sources=["drums", "bass", "other", "vocals"], X=10)
else:
self.demucs = Demucs(sources=["drums", "bass", "other", "vocals"], channels=channels)
widget_text.write(base_text + 'Loading Demucs v2 model... ')
update_progress(**progress_kwargs,
step=0.05)
self.demucs.to(device)
self.demucs.load_state_dict(torch.load("models/Demucs_Models/"f"{demucs_model_set_name}"))
widget_text.write('Done!\n')
if not data['segment'] == 'None':
widget_text.write(base_text + 'Segments is only available in Demucs v3. Please use \"Chunks\" instead.\n')
else:
pass
self.demucs.eval()
if demucs_model_version == 'v3':
self.demucs = HDemucs(sources=["drums", "bass", "other", "vocals"])
widget_text.write(base_text + 'Loading Demucs model... ')
update_progress(**progress_kwargs,
step=0.05)
path_d = Path('models/Demucs_Models/v3_repo')
#print('What Demucs model was chosen? ', demucs_model_set_name)
self.demucs = _gm(name=demucs_model_set_name, repo=path_d)
widget_text.write('Done!\n')
if 'UVR' in data['DemucsModel']:
widget_text.write(base_text + "2 stem model selected.\n")
if isinstance(self.demucs, BagOfModels):
widget_text.write(base_text + f"Selected model is a bag of {len(self.demucs.models)} models.\n")
if data['segment'] == 'None':
segment = None
if isinstance(self.demucs, BagOfModels):
if segment is not None:
@ -88,9 +110,29 @@ class Predictor():
else:
if segment is not None:
sub.segment = segment
self.demucs.to(device)
self.demucs.eval()
else:
try:
segment = int(data['segment'])
if isinstance(self.demucs, BagOfModels):
if segment is not None:
for sub in self.demucs.models:
sub.segment = segment
else:
if segment is not None:
sub.segment = segment
widget_text.write(base_text + "Segments set to "f"{segment}.\n")
except:
segment = None
if isinstance(self.demucs, BagOfModels):
if segment is not None:
for sub in self.demucs.models:
sub.segment = segment
else:
if segment is not None:
sub.segment = segment
self.demucs.to(device)
self.demucs.eval()
update_progress(**progress_kwargs,
step=0.1)
@ -646,7 +688,12 @@ class Predictor():
if end == samples:
break
sources = self.demix_demucs(segmented_mix, margin_size=margin)
if demucs_model_version == 'v1':
sources = self.demix_demucs_v1(segmented_mix, margin_size=margin)
if demucs_model_version == 'v2':
sources = self.demix_demucs_v2(segmented_mix, margin_size=margin)
if demucs_model_version == 'v3':
sources = self.demix_demucs(segmented_mix, margin_size=margin)
return sources
@ -683,31 +730,94 @@ class Predictor():
sources = np.concatenate(sources, axis=-1)
widget_text.write('Done!\n')
return sources
def demix_demucs_v1(self, mix, margin_size):
processed = {}
demucsitera = len(mix)
demucsitera_calc = demucsitera * 2
gui_progress_bar_demucs = 0
widget_text.write(base_text + "Running Demucs v1 Inference...\n")
widget_text.write(base_text + "Processing "f"{len(mix)} slices... ")
print(' Running Demucs Inference...')
for nmix in mix:
gui_progress_bar_demucs += 1
update_progress(**progress_kwargs,
step=(0.35 + (1.05/demucsitera_calc * gui_progress_bar_demucs)))
cmix = mix[nmix]
cmix = torch.tensor(cmix, dtype=torch.float32)
ref = cmix.mean(0)
cmix = (cmix - ref.mean()) / ref.std()
with torch.no_grad():
sources = apply_model_v1(self.demucs, cmix.to(device), split=split_mode, shifts=shift_set)
sources = (sources * ref.std() + ref.mean()).cpu().numpy()
sources[[0,1]] = sources[[1,0]]
start = 0 if nmix == 0 else margin_size
end = None if nmix == list(mix.keys())[::-1][0] else -margin_size
if margin_size == 0:
end = None
processed[nmix] = sources[:,:,start:end].copy()
sources = list(processed.values())
sources = np.concatenate(sources, axis=-1)
widget_text.write('Done!\n')
return sources
def demix_demucs_v2(self, mix, margin_size):
processed = {}
demucsitera = len(mix)
demucsitera_calc = demucsitera * 2
gui_progress_bar_demucs = 0
widget_text.write(base_text + "Running Demucs v2 Inference...\n")
widget_text.write(base_text + "Processing "f"{len(mix)} slices... ")
print(' Running Demucs Inference...')
for nmix in mix:
gui_progress_bar_demucs += 1
update_progress(**progress_kwargs,
step=(0.35 + (1.05/demucsitera_calc * gui_progress_bar_demucs)))
cmix = mix[nmix]
cmix = torch.tensor(cmix, dtype=torch.float32)
ref = cmix.mean(0)
cmix = (cmix - ref.mean()) / ref.std()
shift_set = 0
with torch.no_grad():
sources = apply_model_v2(self.demucs, cmix.to(device), split=split_mode, overlap=overlap_set, shifts=shift_set)
sources = (sources * ref.std() + ref.mean()).cpu().numpy()
sources[[0,1]] = sources[[1,0]]
start = 0 if nmix == 0 else margin_size
end = None if nmix == list(mix.keys())[::-1][0] else -margin_size
if margin_size == 0:
end = None
processed[nmix] = sources[:,:,start:end].copy()
sources = list(processed.values())
sources = np.concatenate(sources, axis=-1)
widget_text.write('Done!\n')
return sources
data = {
# Paths
'input_paths': None,
'export_path': None,
'saveFormat': 'Wav',
# Processing Options
'demucsmodel': True,
'gpu': -1,
'audfile': True,
'chunks_d': 'Full',
'settest': False,
'voc_only_b': False,
'inst_only_b': False,
'overlap_b': 0.25,
'shifts_b': 2,
'segment': 'None',
'margin': 44100,
'split_mode': False,
'normalize': False,
'compensate': 1.03597672895,
'demucs_stems': 'All Stems',
'DemucsModel': 'mdx_extra',
'audfile': True,
'wavtype': 'PCM_16',
'demucsmodel': True,
'export_path': None,
'gpu': -1,
'input_paths': None,
'inst_only_b': False,
'margin': 44100,
'mp3bit': '320k',
'normalize': False,
'overlap_b': 0.25,
'saveFormat': 'Wav',
'segment': 'None',
'settest': False,
'shifts_b': 2,
'split_mode': False,
'voc_only_b': False,
'wavtype': 'PCM_16',
}
default_chunks = data['chunks_d']
@ -756,6 +866,8 @@ def main(window: tk.Wm, text_widget: tk.Text, button_widget: tk.Button, progress
global shift_set
global source_val
global split_mode
global demucs_model_set_name
global demucs_model_version
global wav_type_set
global flac_type_set
@ -817,6 +929,69 @@ def main(window: tk.Wm, text_widget: tk.Text, button_widget: tk.Button, progress
progress_var.set(0)
text_widget.clear()
button_widget.configure(state=tk.DISABLED) # Disable Button
if data['DemucsModel'] == "Tasnet v1":
demucs_model_set_name = 'tasnet.th'
demucs_model_version = 'v1'
elif data['DemucsModel'] == "Tasnet_extra v1":
demucs_model_set_name = 'tasnet_extra.th'
demucs_model_version = 'v1'
elif data['DemucsModel'] == "Demucs v1":
demucs_model_set_name = 'demucs.th'
demucs_model_version = 'v1'
elif data['DemucsModel'] == "Demucs v1.gz":
demucs_model_set_name = 'demucs.th.gz'
demucs_model_version = 'v1'
elif data['DemucsModel'] == "Demucs_extra v1":
demucs_model_set_name = 'demucs_extra.th'
demucs_model_version = 'v1'
elif data['DemucsModel'] == "Demucs_extra v1.gz":
demucs_model_set_name = 'demucs_extra.th.gz'
demucs_model_version = 'v1'
elif data['DemucsModel'] == "Light v1":
demucs_model_set_name = 'light.th'
demucs_model_version = 'v1'
elif data['DemucsModel'] == "Light v1.gz":
demucs_model_set_name = 'light.th.gz'
demucs_model_version = 'v1'
elif data['DemucsModel'] == "Light_extra v1":
demucs_model_set_name = 'light_extra.th'
demucs_model_version = 'v1'
elif data['DemucsModel'] == "Light_extra v1.gz":
demucs_model_set_name = 'light_extra.th.gz'
demucs_model_version = 'v1'
elif data['DemucsModel'] == "Tasnet v2":
demucs_model_set_name = 'tasnet-beb46fac.th'
demucs_model_version = 'v2'
elif data['DemucsModel'] == "Tasnet_extra v2":
demucs_model_set_name = 'tasnet_extra-df3777b2.th'
demucs_model_version = 'v2'
elif data['DemucsModel'] == "Demucs48_hq v2":
demucs_model_set_name = 'demucs48_hq-28a1282c.th'
demucs_model_version = 'v2'
elif data['DemucsModel'] == "Demucs v2":
demucs_model_set_name = 'demucs-e07c671f.th'
demucs_model_version = 'v2'
elif data['DemucsModel'] == "Demucs_extra v2":
demucs_model_set_name = 'demucs_extra-3646af93.th'
demucs_model_version = 'v2'
elif data['DemucsModel'] == "Demucs_unittest v2":
demucs_model_set_name = 'demucs_unittest-09ebc15f.th'
demucs_model_version = 'v2'
elif '.ckpt' in data['DemucsModel'] and 'v2' in data['DemucsModel']:
demucs_model_set_name = data['DemucsModel']
demucs_model_version = 'v2'
elif '.ckpt' in data['DemucsModel'] and 'v1' in data['DemucsModel']:
demucs_model_set_name = data['DemucsModel']
demucs_model_version = 'v1'
elif '.gz' in data['DemucsModel']:
demucs_model_set_name = data['DemucsModel']
demucs_model_version = 'v1'
else:
demucs_model_set_name = data['DemucsModel']
demucs_model_version = 'v3'
try: #Load File(s)
for file_num, music_file in tqdm(enumerate(data['input_paths'], start=1)):
@ -880,7 +1055,10 @@ def main(window: tk.Wm, text_widget: tk.Text, button_widget: tk.Button, progress
channel_set = int(data['channel'])
margin_set = int(data['margin'])
shift_set = int(data['shifts_b'])
split_mode = data['split_mode']
#print('Split? ', split_mode)
def determinemusicfileFolderName():
"""

View File

@ -1,34 +1,31 @@
import os
import importlib
import pydub
import shutil
import hashlib
import cv2
import librosa
import math
import numpy as np
import soundfile as sf
from tqdm import tqdm
from demucs.pretrained import get_model as _gm
from demucs.hdemucs import HDemucs
from collections import defaultdict
from datetime import datetime
from demucs.apply import BagOfModels, apply_model
from pathlib import Path
from models import stft, istft
from demucs.hdemucs import HDemucs
from demucs.pretrained import get_model as _gm
from lib_v5 import dataset
from lib_v5 import spec_utils
from lib_v5.model_param_init import ModelParameters
import torch
from datetime import datetime
# Command line text parsing and widget manipulation
from collections import defaultdict
import tkinter as tk
import traceback # Error Message Recent Calls
import time # Timer
from models import stft, istft
from pathlib import Path
from random import randrange
from tqdm import tqdm
from tkinter import filedialog
import lib_v5.filelist
import cv2
import hashlib
import importlib
import librosa
import math
import numpy as np
import os
import pydub
import shutil
import soundfile as sf
import time # Timer
import tkinter as tk
import torch
import traceback # Error Message Recent Calls
class VocalRemover(object):
@ -40,35 +37,31 @@ class VocalRemover(object):
# self.offset = model.offset
data = {
# Paths
'input_paths': None,
'export_path': None,
'saveFormat': 'wav',
# Processing Options
'gpu': -1,
'postprocess': True,
'tta': True,
'output_image': True,
'voc_only': False,
'inst_only': False,
# Models
'instrumentalModel': None,
'useModel': None,
# Constants
'window_size': 512,
'agg': 10,
'high_end_process': 'mirroring',
'ModelParams': 'Auto',
'demucsmodel_sel_VR': 'UVR_Demucs_Model_1',
'overlap': 0.5,
'shifts': 0,
'segment': 'None',
'split_mode': False,
'normalize': False,
'demucsmodelVR': True,
'wavtype': 'PCM_16',
'export_path': None,
'gpu': -1,
'high_end_process': 'mirroring',
'input_paths': None,
'inst_only': False,
'instrumentalModel': None,
'ModelParams': 'Auto',
'mp3bit': '320k',
'normalize': False,
'output_image': True,
'overlap': 0.5,
'postprocess': True,
'saveFormat': 'wav',
'segment': 'None',
'settest': False,
'shifts': 0,
'split_mode': False,
'tta': True,
'useModel': None,
'voc_only': False,
'wavtype': 'PCM_16',
'window_size': 512,
}
default_window_size = data['window_size']
@ -144,7 +137,7 @@ def main(window: tk.Wm, text_widget: tk.Text, button_widget: tk.Button, progress
nn_arch_sizes = [
31191, # default
33966, 123821, 123812, 537238 # custom
33966, 123821, 123812, 129605, 537238 # custom
]
nn_architecture = list('{}KB'.format(s) for s in nn_arch_sizes)
@ -492,7 +485,7 @@ def main(window: tk.Wm, text_widget: tk.Text, button_widget: tk.Button, progress
return
#Load Model
text_widget.write(base_text + 'Loading models...')
text_widget.write(base_text + 'Loading model...')
model_size = math.ceil(os.stat(data['instrumentalModel']).st_size / 1024)
nn_architecture = '{}KB'.format(min(nn_arch_sizes, key=lambda x:abs(x-model_size)))
@ -504,212 +497,77 @@ def main(window: tk.Wm, text_widget: tk.Text, button_widget: tk.Button, progress
ModelName=(data['instrumentalModel'])
#Package Models
model_hash = hashlib.md5(open(ModelName,'rb').read()).hexdigest()
print(model_hash)
#v5 Models
if model_hash == '47939caf0cfe52a0e81442b85b971dfd':
model_params_auto=str('lib_v5/modelparams/4band_44100.json')
param_name_auto=str('4band_44100')
if model_hash == '4e4ecb9764c50a8c414fee6e10395bbe':
model_params_auto=str('lib_v5/modelparams/4band_v2.json')
param_name_auto=str('4band_v2')
if model_hash == 'e60a1e84803ce4efc0a6551206cc4b71':
model_params_auto=str('lib_v5/modelparams/4band_44100.json')
param_name_auto=str('4band_44100')
if model_hash == 'a82f14e75892e55e994376edbf0c8435':
model_params_auto=str('lib_v5/modelparams/4band_44100.json')
param_name_auto=str('4band_44100')
if model_hash == '6dd9eaa6f0420af9f1d403aaafa4cc06':
model_params_auto=str('lib_v5/modelparams/4band_v2_sn.json')
param_name_auto=str('4band_v2_sn')
if model_hash == '5c7bbca45a187e81abbbd351606164e5':
model_params_auto=str('lib_v5/modelparams/3band_44100_msb2.json')
param_name_auto=str('3band_44100_msb2')
if model_hash == 'd6b2cb685a058a091e5e7098192d3233':
model_params_auto=str('lib_v5/modelparams/3band_44100_msb2.json')
param_name_auto=str('3band_44100_msb2')
if model_hash == 'c1b9f38170a7c90e96f027992eb7c62b':
model_params_auto=str('lib_v5/modelparams/4band_44100.json')
param_name_auto=str('4band_44100')
if model_hash == 'c3448ec923fa0edf3d03a19e633faa53':
model_params_auto=str('lib_v5/modelparams/4band_44100.json')
param_name_auto=str('4band_44100')
if model_hash == '68aa2c8093d0080704b200d140f59e54':
model_params_auto=str('lib_v5/modelparams/3band_44100.json')
param_name_auto=str('3band_44100.json')
if model_hash == 'fdc83be5b798e4bd29fe00fe6600e147':
model_params_auto=str('lib_v5/modelparams/3band_44100_mid.json')
param_name_auto=str('3band_44100_mid.json')
if model_hash == '2ce34bc92fd57f55db16b7a4def3d745':
model_params_auto=str('lib_v5/modelparams/3band_44100_mid.json')
param_name_auto=str('3band_44100_mid.json')
if model_hash == '52fdca89576f06cf4340b74a4730ee5f':
model_params_auto=str('lib_v5/modelparams/4band_44100.json')
param_name_auto=str('4band_44100.json')
if model_hash == '41191165b05d38fc77f072fa9e8e8a30':
model_params_auto=str('lib_v5/modelparams/4band_44100.json')
param_name_auto=str('4band_44100.json')
if model_hash == '89e83b511ad474592689e562d5b1f80e':
model_params_auto=str('lib_v5/modelparams/2band_32000.json')
param_name_auto=str('2band_32000.json')
if model_hash == '0b954da81d453b716b114d6d7c95177f':
model_params_auto=str('lib_v5/modelparams/2band_32000.json')
param_name_auto=str('2band_32000.json')
#v4 Models
if model_hash == '6a00461c51c2920fd68937d4609ed6c8':
model_params_auto=str('lib_v5/modelparams/1band_sr16000_hl512.json')
param_name_auto=str('1band_sr16000_hl512')
if model_hash == '0ab504864d20f1bd378fe9c81ef37140':
model_params_auto=str('lib_v5/modelparams/1band_sr32000_hl512.json')
param_name_auto=str('1band_sr32000_hl512')
if model_hash == '7dd21065bf91c10f7fccb57d7d83b07f':
model_params_auto=str('lib_v5/modelparams/1band_sr32000_hl512.json')
param_name_auto=str('1band_sr32000_hl512')
if model_hash == '80ab74d65e515caa3622728d2de07d23':
model_params_auto=str('lib_v5/modelparams/1band_sr32000_hl512.json')
param_name_auto=str('1band_sr32000_hl512')
if model_hash == 'edc115e7fc523245062200c00caa847f':
model_params_auto=str('lib_v5/modelparams/1band_sr33075_hl384.json')
param_name_auto=str('1band_sr33075_hl384')
if model_hash == '28063e9f6ab5b341c5f6d3c67f2045b7':
model_params_auto=str('lib_v5/modelparams/1band_sr33075_hl384.json')
param_name_auto=str('1band_sr33075_hl384')
if model_hash == 'b58090534c52cbc3e9b5104bad666ef2':
model_params_auto=str('lib_v5/modelparams/1band_sr44100_hl512.json')
param_name_auto=str('1band_sr44100_hl512')
if model_hash == '0cdab9947f1b0928705f518f3c78ea8f':
model_params_auto=str('lib_v5/modelparams/1band_sr44100_hl512.json')
param_name_auto=str('1band_sr44100_hl512')
if model_hash == 'ae702fed0238afb5346db8356fe25f13':
model_params_auto=str('lib_v5/modelparams/1band_sr44100_hl1024.json')
param_name_auto=str('1band_sr44100_hl1024')
#User Models
#1 Band
if '1band_sr16000_hl512' in ModelName:
model_params_auto=str('lib_v5/modelparams/1band_sr16000_hl512.json')
param_name_auto=str('1band_sr16000_hl512')
if '1band_sr32000_hl512' in ModelName:
model_params_auto=str('lib_v5/modelparams/1band_sr32000_hl512.json')
param_name_auto=str('1band_sr32000_hl512')
if '1band_sr33075_hl384' in ModelName:
model_params_auto=str('lib_v5/modelparams/1band_sr33075_hl384.json')
param_name_auto=str('1band_sr33075_hl384')
if '1band_sr44100_hl256' in ModelName:
model_params_auto=str('lib_v5/modelparams/1band_sr44100_hl256.json')
param_name_auto=str('1band_sr44100_hl256')
if '1band_sr44100_hl512' in ModelName:
model_params_auto=str('lib_v5/modelparams/1band_sr44100_hl512.json')
param_name_auto=str('1band_sr44100_hl512')
if '1band_sr44100_hl1024' in ModelName:
model_params_auto=str('lib_v5/modelparams/1band_sr44100_hl1024.json')
param_name_auto=str('1band_sr44100_hl1024')
#2 Band
if '2band_44100_lofi' in ModelName:
model_params_auto=str('lib_v5/modelparams/2band_44100_lofi.json')
param_name_auto=str('2band_44100_lofi')
if '2band_32000' in ModelName:
model_params_auto=str('lib_v5/modelparams/2band_32000.json')
param_name_auto=str('2band_32000')
if '2band_48000' in ModelName:
model_params_auto=str('lib_v5/modelparams/2band_48000.json')
param_name_auto=str('2band_48000')
#3 Band
if '3band_44100' in ModelName:
model_params_auto=str('lib_v5/modelparams/3band_44100.json')
param_name_auto=str('3band_44100')
if '3band_44100_mid' in ModelName:
model_params_auto=str('lib_v5/modelparams/3band_44100_mid.json')
param_name_auto=str('3band_44100_mid')
if '3band_44100_msb2' in ModelName:
model_params_auto=str('lib_v5/modelparams/3band_44100_msb2.json')
param_name_auto=str('3band_44100_msb2')
#4 Band
if '4band_44100' in ModelName:
model_params_auto=str('lib_v5/modelparams/4band_44100.json')
param_name_auto=str('4band_44100')
if '4band_44100_mid' in ModelName:
model_params_auto=str('lib_v5/modelparams/4band_44100_mid.json')
param_name_auto=str('4band_44100_mid')
if '4band_44100_msb' in ModelName:
model_params_auto=str('lib_v5/modelparams/4band_44100_msb.json')
param_name_auto=str('4band_44100_msb')
if '4band_44100_msb2' in ModelName:
model_params_auto=str('lib_v5/modelparams/4band_44100_msb2.json')
param_name_auto=str('4band_44100_msb2')
if '4band_44100_reverse' in ModelName:
model_params_auto=str('lib_v5/modelparams/4band_44100_reverse.json')
param_name_auto=str('4band_44100_reverse')
if '4band_44100_sw' in ModelName:
model_params_auto=str('lib_v5/modelparams/4band_44100_sw.json')
param_name_auto=str('4band_44100_sw')
if '4band_v2' in ModelName:
model_params_auto=str('lib_v5/modelparams/4band_v2.json')
param_name_auto=str('4band_v2')
if '4band_v2_sn' in ModelName:
model_params_auto=str('lib_v5/modelparams/4band_v2_sn.json')
param_name_auto=str('4band_v2_sn')
if 'tmodelparam' in ModelName:
model_params_auto=str('lib_v5/modelparams/tmodelparam.json')
param_name_auto=str('User Model Param Set')
text_widget.write(' Done!\n')
text_widget.write('Done!\n')
if data['ModelParams'] == 'Auto':
param_name = param_name_auto
model_params_d = model_params_auto
model_hash = hashlib.md5(open(ModelName,'rb').read()).hexdigest()
model_params = []
model_params = lib_v5.filelist.provide_model_param_hash(model_hash)
print(model_params)
if model_params[0] == 'Not Found Using Hash':
model_params = []
model_params = lib_v5.filelist.provide_model_param_name(ModelName)
if model_params[0] == 'Not Found Using Name':
text_widget.write(base_text + f'Unable to set model parameters automatically with the selected model.\n')
confirm = tk.messagebox.askyesno(title='Unrecognized Model Detected',
message=f'\nThe application could not automatically set the model param for the selected model.\n\n' +
f'Would you like to select the model param file for this model?\n\n')
if confirm:
model_param_selection = filedialog.askopenfilename(initialdir='lib_v5/modelparams',
title=f'Select Model Param',
filetypes=[("Model Param", "*.json")])
model_param_file_path = str(model_param_selection)
model_param_file = os.path.splitext(os.path.basename(model_param_file_path))[0] + '.json'
model_params = [model_param_file_path, model_param_file]
with open(f"lib_v5/filelists/model_cache/vr_param_cache/{model_hash}.txt", 'w') as f:
f.write(model_param_file)
if model_params[0] == '':
text_widget.write("\n" + base_text + f'Separation failed for the following audio file:\n')
text_widget.write(base_text + f'"{os.path.basename(music_file)}"\n')
text_widget.write(f'\nError Received:\n\n')
text_widget.write(f'Model parameters are missing.\n\n')
text_widget.write(f'Please check the following:\n')
text_widget.write(f'1. Make sure the model is still present.\n')
text_widget.write(f'2. If you are running a model that was not originally included in this package, \nplease append the modelparam name to the model name.\n')
text_widget.write(f' - Example if using \"4band_v2.json\" modelparam: \"model_4band_v2.pth\"\n\n')
text_widget.write(f'Please address this and try again.\n\n')
text_widget.write(f'Time Elapsed: {time.strftime("%H:%M:%S", time.gmtime(int(time.perf_counter() - stime)))}')
torch.cuda.empty_cache()
progress_var.set(0)
button_widget.configure(state=tk.NORMAL) # Enable Button
return
else:
pass
else:
text_widget.write(base_text + f'Model param not selected.\n')
text_widget.write("\n" + base_text + f'Separation failed for the following audio file:\n')
text_widget.write(base_text + f'"{os.path.basename(music_file)}"\n')
text_widget.write(f'\nError Received:\n\n')
text_widget.write(f'Model parameters are missing.\n\n')
text_widget.write(f'Please check the following:\n')
text_widget.write(f'1. Make sure the model is still present.\n')
text_widget.write(f'2. If you are running a model that was not originally included in this package, \nplease append the modelparam name to the model name.\n')
text_widget.write(f' - Example if using \"4band_v2.json\" modelparam: \"model_4band_v2.pth\"\n\n')
text_widget.write(f'Please address this and try again.\n\n')
text_widget.write(f'Time Elapsed: {time.strftime("%H:%M:%S", time.gmtime(int(time.perf_counter() - stime)))}')
torch.cuda.empty_cache()
progress_var.set(0)
button_widget.configure(state=tk.NORMAL) # Enable Button
return
else:
param_name = str(data['ModelParams'])
model_params_d = str('lib_v5/modelparams/' + data['ModelParams'])
param = data['ModelParams']
model_param_file_path = f'lib_v5/modelparams/{param}'
model_params = [model_param_file_path, param]
try:
print('Model Parameters:', model_params_d)
text_widget.write(base_text + 'Loading assigned model parameters ' + '\"' + param_name + '\"... ')
except Exception as e:
traceback_text = ''.join(traceback.format_tb(e.__traceback__))
errmessage = f'Traceback Error: "{traceback_text}"\n{type(e).__name__}: "{e}"\n'
text_widget.write("\n" + base_text + f'Separation failed for the following audio file:\n')
text_widget.write(base_text + f'"{os.path.basename(music_file)}"\n')
text_widget.write(f'\nError Received:\n\n')
text_widget.write(f'Model parameters are missing.\n\n')
text_widget.write(f'Please check the following:\n')
text_widget.write(f'1. Make sure the model is still present.\n')
text_widget.write(f'2. If you are running a model that was not originally included in this package, \nplease append the modelparam name to the model name.\n')
text_widget.write(f' - Example if using \"4band_v2.json\" modelparam: \"model_4band_v2.pth\"\n\n')
text_widget.write(f'Please address this and try again.\n\n')
text_widget.write(f'Time Elapsed: {time.strftime("%H:%M:%S", time.gmtime(int(time.perf_counter() - stime)))}')
try:
with open('errorlog.txt', 'w') as f:
f.write(f'Last Error Received:\n\n' +
f'Error Received while processing "{os.path.basename(music_file)}":\n' +
f'Process Method: VR Architecture\n\n' +
f'Model parameters are missing.\n\n' +
f'Please check the following:\n' +
f'1. Make sure the model is still present.\n' +
f'2. If you are running a model that was not originally included in this package, please append the modelparam name to the model name.\n' +
f' - Example if using \"4band_v2.json\" modelparam: \"model_4band_v2.pth\"\n\n' +
f'Please address this and try again.\n\n' +
f'Raw error details:\n\n' +
errmessage + f'\nError Time Stamp: [{datetime.now().strftime("%Y-%m-%d %H:%M:%S")}]\n')
except:
pass
torch.cuda.empty_cache()
progress_var.set(0)
button_widget.configure(state=tk.NORMAL) # Enable Button
return
mp = ModelParameters(model_params_d)
text_widget.write(base_text + 'Loading assigned model parameters ' + '\"' + model_params[1] + '\"... ')
mp = ModelParameters(model_params[0])
text_widget.write('Done!\n')
# -Instrumental-
if os.path.isfile(data['instrumentalModel']):
@ -726,10 +584,8 @@ def main(window: tk.Wm, text_widget: tk.Text, button_widget: tk.Button, progress
model_name = os.path.basename(data[f'{data["useModel"]}Model'])
mp = ModelParameters(model_params_d)
# -Go through the different steps of seperation-
# -Go through the different steps of Separation-
# Wave source
text_widget.write(base_text + 'Loading audio source...')
@ -921,12 +777,12 @@ def main(window: tk.Wm, text_widget: tk.Text, button_widget: tk.Button, progress
text_widget.write(base_text + 'Loading Demucs model... ')
update_progress(**progress_kwargs,
step=0.95)
path_d = Path('models/Demucs_Models')
print('What Demucs model was chosen? ', demucs_model_set)
path_d = Path('models/Demucs_Models/v3_repo')
#print('What Demucs model was chosen? ', demucs_model_set)
demucs = _gm(name=demucs_model_set, repo=path_d)
text_widget.write('Done!\n')
print('segment: ', data['segment'])
#print('segment: ', data['segment'])
if data['segment'] == 'None':
segment = None
@ -958,7 +814,7 @@ def main(window: tk.Wm, text_widget: tk.Text, button_widget: tk.Button, progress
if segment is not None:
sub.segment = segment
print('segment port-process: ', segment)
#print('segment port-process: ', segment)
demucs.cpu()
demucs.eval()
@ -1048,7 +904,7 @@ def main(window: tk.Wm, text_widget: tk.Text, button_widget: tk.Button, progress
bin_image.tofile(f)
text_widget.write(base_text + 'Completed Seperation!\n\n')
text_widget.write(base_text + 'Completed Separation!\n\n')
except Exception as e:
traceback_text = ''.join(traceback.format_tb(e.__traceback__))
message = f'Traceback Error: "{traceback_text}"\n{type(e).__name__}: "{e}"\n'

File diff suppressed because it is too large Load Diff

View File

@ -7,8 +7,6 @@ import librosa
dim_c = 4
model_path = 'model'
#n_fft_scale = {'vocals-one':6144, 'vocals-two':7680,'*':2}
class Conv_TDF_net_trim(nn.Module):
def __init__(self, device, n_fft_scale, dim_f, load, model_name, target_name,
L, dim_t, hop=1024):
@ -20,9 +18,9 @@ class Conv_TDF_net_trim(nn.Module):
self.hop = hop
self.n_bins = self.n_fft//2+1
self.chunk_size = hop * (self.dim_t-1)
self.window = torch.hann_window(window_length=self.n_fft, periodic=True).to(device)
self.window = torch.hann_window(window_length=self.n_fft, periodic=False).to(device)
self.target_name = target_name
print(n_fft_scale)
#print(n_fft_scale)
out_c = dim_c*4 if target_name=='*' else dim_c
self.freq_pad = torch.zeros([1, out_c, self.n_bins-self.dim_f, self.dim_t]).to(device)
@ -61,17 +59,21 @@ def istft(spec, hl):
return wave
def spec_effects(wave, algorithm='Default', value=None):
spec = [stft(wave[0],2048,1024),stft(wave[1],2048,1024)]
doubleout = spec = [stft(wave[0],2048,1024),stft(wave[1],2048,1024)]
if algorithm == 'Min_Mag':
doubleout
v_spec_m = np.where(np.abs(spec[1]) <= np.abs(spec[0]), spec[1], spec[0])
wave = istft(v_spec_m,1024)
elif algorithm == 'Max_Mag':
doubleout
v_spec_m = np.where(np.abs(spec[1]) >= np.abs(spec[0]), spec[1], spec[0])
wave = istft(v_spec_m,1024)
elif algorithm == 'Default':
doubleout
#wave = [istft(spec[0],1024),istft(spec[1],1024)]
wave = (wave[1] * value) + (wave[0] * (1-value))
elif algorithm == 'Invert_p':
doubleout
X_mag = np.abs(spec[0])
y_mag = np.abs(spec[1])
max_mag = np.where(X_mag >= y_mag, X_mag, y_mag)