Spaces:
Runtime error
Runtime error
Eddycrack864
commited on
Commit
•
d198ea5
1
Parent(s):
2809163
Upload 41 files
Browse files- lib_v5/mdxnet.py +140 -0
- lib_v5/mixer.ckpt +3 -0
- lib_v5/modules.py +74 -0
- lib_v5/pyrb.py +92 -0
- lib_v5/spec_utils.py +692 -0
- lib_v5/vr_network/__init__.py +1 -0
- lib_v5/vr_network/__pycache__/__init__.cpython-310.pyc +0 -0
- lib_v5/vr_network/__pycache__/layers.cpython-310.pyc +0 -0
- lib_v5/vr_network/__pycache__/layers_new.cpython-310.pyc +0 -0
- lib_v5/vr_network/__pycache__/model_param_init.cpython-310.pyc +0 -0
- lib_v5/vr_network/__pycache__/nets.cpython-310.pyc +0 -0
- lib_v5/vr_network/__pycache__/nets_new.cpython-310.pyc +0 -0
- lib_v5/vr_network/layers.py +143 -0
- lib_v5/vr_network/layers_new.py +126 -0
- lib_v5/vr_network/model_param_init.py +59 -0
- lib_v5/vr_network/modelparams/1band_sr16000_hl512.json +19 -0
- lib_v5/vr_network/modelparams/1band_sr32000_hl512.json +19 -0
- lib_v5/vr_network/modelparams/1band_sr33075_hl384.json +19 -0
- lib_v5/vr_network/modelparams/1band_sr44100_hl1024.json +19 -0
- lib_v5/vr_network/modelparams/1band_sr44100_hl256.json +19 -0
- lib_v5/vr_network/modelparams/1band_sr44100_hl512.json +19 -0
- lib_v5/vr_network/modelparams/1band_sr44100_hl512_cut.json +19 -0
- lib_v5/vr_network/modelparams/1band_sr44100_hl512_nf1024.json +19 -0
- lib_v5/vr_network/modelparams/2band_32000.json +30 -0
- lib_v5/vr_network/modelparams/2band_44100_lofi.json +30 -0
- lib_v5/vr_network/modelparams/2band_48000.json +30 -0
- lib_v5/vr_network/modelparams/3band_44100.json +42 -0
- lib_v5/vr_network/modelparams/3band_44100_mid.json +43 -0
- lib_v5/vr_network/modelparams/3band_44100_msb2.json +43 -0
- lib_v5/vr_network/modelparams/4band_44100.json +54 -0
- lib_v5/vr_network/modelparams/4band_44100_mid.json +55 -0
- lib_v5/vr_network/modelparams/4band_44100_msb.json +55 -0
- lib_v5/vr_network/modelparams/4band_44100_msb2.json +55 -0
- lib_v5/vr_network/modelparams/4band_44100_reverse.json +55 -0
- lib_v5/vr_network/modelparams/4band_44100_sw.json +55 -0
- lib_v5/vr_network/modelparams/4band_v2.json +54 -0
- lib_v5/vr_network/modelparams/4band_v2_sn.json +55 -0
- lib_v5/vr_network/modelparams/4band_v3.json +54 -0
- lib_v5/vr_network/modelparams/ensemble.json +43 -0
- lib_v5/vr_network/nets.py +166 -0
- lib_v5/vr_network/nets_new.py +125 -0
lib_v5/mdxnet.py
ADDED
@@ -0,0 +1,140 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from abc import ABCMeta
|
2 |
+
|
3 |
+
import torch
|
4 |
+
import torch.nn as nn
|
5 |
+
from pytorch_lightning import LightningModule
|
6 |
+
from .modules import TFC_TDF
|
7 |
+
|
8 |
+
dim_s = 4
|
9 |
+
|
10 |
+
class AbstractMDXNet(LightningModule):
|
11 |
+
__metaclass__ = ABCMeta
|
12 |
+
|
13 |
+
def __init__(self, target_name, lr, optimizer, dim_c, dim_f, dim_t, n_fft, hop_length, overlap):
|
14 |
+
super().__init__()
|
15 |
+
self.target_name = target_name
|
16 |
+
self.lr = lr
|
17 |
+
self.optimizer = optimizer
|
18 |
+
self.dim_c = dim_c
|
19 |
+
self.dim_f = dim_f
|
20 |
+
self.dim_t = dim_t
|
21 |
+
self.n_fft = n_fft
|
22 |
+
self.n_bins = n_fft // 2 + 1
|
23 |
+
self.hop_length = hop_length
|
24 |
+
self.window = nn.Parameter(torch.hann_window(window_length=self.n_fft, periodic=True), requires_grad=False)
|
25 |
+
self.freq_pad = nn.Parameter(torch.zeros([1, dim_c, self.n_bins - self.dim_f, self.dim_t]), requires_grad=False)
|
26 |
+
|
27 |
+
def configure_optimizers(self):
|
28 |
+
if self.optimizer == 'rmsprop':
|
29 |
+
return torch.optim.RMSprop(self.parameters(), self.lr)
|
30 |
+
|
31 |
+
if self.optimizer == 'adamw':
|
32 |
+
return torch.optim.AdamW(self.parameters(), self.lr)
|
33 |
+
|
34 |
+
class ConvTDFNet(AbstractMDXNet):
|
35 |
+
def __init__(self, target_name, lr, optimizer, dim_c, dim_f, dim_t, n_fft, hop_length,
|
36 |
+
num_blocks, l, g, k, bn, bias, overlap):
|
37 |
+
|
38 |
+
super(ConvTDFNet, self).__init__(
|
39 |
+
target_name, lr, optimizer, dim_c, dim_f, dim_t, n_fft, hop_length, overlap)
|
40 |
+
self.save_hyperparameters()
|
41 |
+
|
42 |
+
self.num_blocks = num_blocks
|
43 |
+
self.l = l
|
44 |
+
self.g = g
|
45 |
+
self.k = k
|
46 |
+
self.bn = bn
|
47 |
+
self.bias = bias
|
48 |
+
|
49 |
+
if optimizer == 'rmsprop':
|
50 |
+
norm = nn.BatchNorm2d
|
51 |
+
|
52 |
+
if optimizer == 'adamw':
|
53 |
+
norm = lambda input:nn.GroupNorm(2, input)
|
54 |
+
|
55 |
+
self.n = num_blocks // 2
|
56 |
+
scale = (2, 2)
|
57 |
+
|
58 |
+
self.first_conv = nn.Sequential(
|
59 |
+
nn.Conv2d(in_channels=self.dim_c, out_channels=g, kernel_size=(1, 1)),
|
60 |
+
norm(g),
|
61 |
+
nn.ReLU(),
|
62 |
+
)
|
63 |
+
|
64 |
+
f = self.dim_f
|
65 |
+
c = g
|
66 |
+
self.encoding_blocks = nn.ModuleList()
|
67 |
+
self.ds = nn.ModuleList()
|
68 |
+
for i in range(self.n):
|
69 |
+
self.encoding_blocks.append(TFC_TDF(c, l, f, k, bn, bias=bias, norm=norm))
|
70 |
+
self.ds.append(
|
71 |
+
nn.Sequential(
|
72 |
+
nn.Conv2d(in_channels=c, out_channels=c + g, kernel_size=scale, stride=scale),
|
73 |
+
norm(c + g),
|
74 |
+
nn.ReLU()
|
75 |
+
)
|
76 |
+
)
|
77 |
+
f = f // 2
|
78 |
+
c += g
|
79 |
+
|
80 |
+
self.bottleneck_block = TFC_TDF(c, l, f, k, bn, bias=bias, norm=norm)
|
81 |
+
|
82 |
+
self.decoding_blocks = nn.ModuleList()
|
83 |
+
self.us = nn.ModuleList()
|
84 |
+
for i in range(self.n):
|
85 |
+
self.us.append(
|
86 |
+
nn.Sequential(
|
87 |
+
nn.ConvTranspose2d(in_channels=c, out_channels=c - g, kernel_size=scale, stride=scale),
|
88 |
+
norm(c - g),
|
89 |
+
nn.ReLU()
|
90 |
+
)
|
91 |
+
)
|
92 |
+
f = f * 2
|
93 |
+
c -= g
|
94 |
+
|
95 |
+
self.decoding_blocks.append(TFC_TDF(c, l, f, k, bn, bias=bias, norm=norm))
|
96 |
+
|
97 |
+
self.final_conv = nn.Sequential(
|
98 |
+
nn.Conv2d(in_channels=c, out_channels=self.dim_c, kernel_size=(1, 1)),
|
99 |
+
)
|
100 |
+
|
101 |
+
def forward(self, x):
|
102 |
+
|
103 |
+
x = self.first_conv(x)
|
104 |
+
|
105 |
+
x = x.transpose(-1, -2)
|
106 |
+
|
107 |
+
ds_outputs = []
|
108 |
+
for i in range(self.n):
|
109 |
+
x = self.encoding_blocks[i](x)
|
110 |
+
ds_outputs.append(x)
|
111 |
+
x = self.ds[i](x)
|
112 |
+
|
113 |
+
x = self.bottleneck_block(x)
|
114 |
+
|
115 |
+
for i in range(self.n):
|
116 |
+
x = self.us[i](x)
|
117 |
+
x *= ds_outputs[-i - 1]
|
118 |
+
x = self.decoding_blocks[i](x)
|
119 |
+
|
120 |
+
x = x.transpose(-1, -2)
|
121 |
+
|
122 |
+
x = self.final_conv(x)
|
123 |
+
|
124 |
+
return x
|
125 |
+
|
126 |
+
class Mixer(nn.Module):
|
127 |
+
def __init__(self, device, mixer_path):
|
128 |
+
|
129 |
+
super(Mixer, self).__init__()
|
130 |
+
|
131 |
+
self.linear = nn.Linear((dim_s+1)*2, dim_s*2, bias=False)
|
132 |
+
|
133 |
+
self.load_state_dict(
|
134 |
+
torch.load(mixer_path, map_location=device)
|
135 |
+
)
|
136 |
+
|
137 |
+
def forward(self, x):
|
138 |
+
x = x.reshape(1,(dim_s+1)*2,-1).transpose(-1,-2)
|
139 |
+
x = self.linear(x)
|
140 |
+
return x.transpose(-1,-2).reshape(dim_s,2,-1)
|
lib_v5/mixer.ckpt
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:946e03c789160ae4631f7037e54b5de90c32fe2c302fc2e5022696bde6902300
|
3 |
+
size 129
|
lib_v5/modules.py
ADDED
@@ -0,0 +1,74 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import torch
|
2 |
+
import torch.nn as nn
|
3 |
+
|
4 |
+
|
5 |
+
class TFC(nn.Module):
|
6 |
+
def __init__(self, c, l, k, norm):
|
7 |
+
super(TFC, self).__init__()
|
8 |
+
|
9 |
+
self.H = nn.ModuleList()
|
10 |
+
for i in range(l):
|
11 |
+
self.H.append(
|
12 |
+
nn.Sequential(
|
13 |
+
nn.Conv2d(in_channels=c, out_channels=c, kernel_size=k, stride=1, padding=k // 2),
|
14 |
+
norm(c),
|
15 |
+
nn.ReLU(),
|
16 |
+
)
|
17 |
+
)
|
18 |
+
|
19 |
+
def forward(self, x):
|
20 |
+
for h in self.H:
|
21 |
+
x = h(x)
|
22 |
+
return x
|
23 |
+
|
24 |
+
|
25 |
+
class DenseTFC(nn.Module):
|
26 |
+
def __init__(self, c, l, k, norm):
|
27 |
+
super(DenseTFC, self).__init__()
|
28 |
+
|
29 |
+
self.conv = nn.ModuleList()
|
30 |
+
for i in range(l):
|
31 |
+
self.conv.append(
|
32 |
+
nn.Sequential(
|
33 |
+
nn.Conv2d(in_channels=c, out_channels=c, kernel_size=k, stride=1, padding=k // 2),
|
34 |
+
norm(c),
|
35 |
+
nn.ReLU(),
|
36 |
+
)
|
37 |
+
)
|
38 |
+
|
39 |
+
def forward(self, x):
|
40 |
+
for layer in self.conv[:-1]:
|
41 |
+
x = torch.cat([layer(x), x], 1)
|
42 |
+
return self.conv[-1](x)
|
43 |
+
|
44 |
+
|
45 |
+
class TFC_TDF(nn.Module):
|
46 |
+
def __init__(self, c, l, f, k, bn, dense=False, bias=True, norm=nn.BatchNorm2d):
|
47 |
+
|
48 |
+
super(TFC_TDF, self).__init__()
|
49 |
+
|
50 |
+
self.use_tdf = bn is not None
|
51 |
+
|
52 |
+
self.tfc = DenseTFC(c, l, k, norm) if dense else TFC(c, l, k, norm)
|
53 |
+
|
54 |
+
if self.use_tdf:
|
55 |
+
if bn == 0:
|
56 |
+
self.tdf = nn.Sequential(
|
57 |
+
nn.Linear(f, f, bias=bias),
|
58 |
+
norm(c),
|
59 |
+
nn.ReLU()
|
60 |
+
)
|
61 |
+
else:
|
62 |
+
self.tdf = nn.Sequential(
|
63 |
+
nn.Linear(f, f // bn, bias=bias),
|
64 |
+
norm(c),
|
65 |
+
nn.ReLU(),
|
66 |
+
nn.Linear(f // bn, f, bias=bias),
|
67 |
+
norm(c),
|
68 |
+
nn.ReLU()
|
69 |
+
)
|
70 |
+
|
71 |
+
def forward(self, x):
|
72 |
+
x = self.tfc(x)
|
73 |
+
return x + self.tdf(x) if self.use_tdf else x
|
74 |
+
|
lib_v5/pyrb.py
ADDED
@@ -0,0 +1,92 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import os
|
2 |
+
import subprocess
|
3 |
+
import tempfile
|
4 |
+
import six
|
5 |
+
import numpy as np
|
6 |
+
import soundfile as sf
|
7 |
+
import sys
|
8 |
+
|
9 |
+
if getattr(sys, 'frozen', False):
|
10 |
+
BASE_PATH_RUB = sys._MEIPASS
|
11 |
+
else:
|
12 |
+
BASE_PATH_RUB = os.path.dirname(os.path.abspath(__file__))
|
13 |
+
|
14 |
+
__all__ = ['time_stretch', 'pitch_shift']
|
15 |
+
|
16 |
+
__RUBBERBAND_UTIL = os.path.join(BASE_PATH_RUB, 'rubberband')
|
17 |
+
|
18 |
+
if six.PY2:
|
19 |
+
DEVNULL = open(os.devnull, 'w')
|
20 |
+
else:
|
21 |
+
DEVNULL = subprocess.DEVNULL
|
22 |
+
|
23 |
+
def __rubberband(y, sr, **kwargs):
|
24 |
+
|
25 |
+
assert sr > 0
|
26 |
+
|
27 |
+
# Get the input and output tempfile
|
28 |
+
fd, infile = tempfile.mkstemp(suffix='.wav')
|
29 |
+
os.close(fd)
|
30 |
+
fd, outfile = tempfile.mkstemp(suffix='.wav')
|
31 |
+
os.close(fd)
|
32 |
+
|
33 |
+
# dump the audio
|
34 |
+
sf.write(infile, y, sr)
|
35 |
+
|
36 |
+
try:
|
37 |
+
# Execute rubberband
|
38 |
+
arguments = [__RUBBERBAND_UTIL, '-q']
|
39 |
+
|
40 |
+
for key, value in six.iteritems(kwargs):
|
41 |
+
arguments.append(str(key))
|
42 |
+
arguments.append(str(value))
|
43 |
+
|
44 |
+
arguments.extend([infile, outfile])
|
45 |
+
|
46 |
+
subprocess.check_call(arguments, stdout=DEVNULL, stderr=DEVNULL)
|
47 |
+
|
48 |
+
# Load the processed audio.
|
49 |
+
y_out, _ = sf.read(outfile, always_2d=True)
|
50 |
+
|
51 |
+
# make sure that output dimensions matches input
|
52 |
+
if y.ndim == 1:
|
53 |
+
y_out = np.squeeze(y_out)
|
54 |
+
|
55 |
+
except OSError as exc:
|
56 |
+
six.raise_from(RuntimeError('Failed to execute rubberband. '
|
57 |
+
'Please verify that rubberband-cli '
|
58 |
+
'is installed.'),
|
59 |
+
exc)
|
60 |
+
|
61 |
+
finally:
|
62 |
+
# Remove temp files
|
63 |
+
os.unlink(infile)
|
64 |
+
os.unlink(outfile)
|
65 |
+
|
66 |
+
return y_out
|
67 |
+
|
68 |
+
def time_stretch(y, sr, rate, rbargs=None):
|
69 |
+
if rate <= 0:
|
70 |
+
raise ValueError('rate must be strictly positive')
|
71 |
+
|
72 |
+
if rate == 1.0:
|
73 |
+
return y
|
74 |
+
|
75 |
+
if rbargs is None:
|
76 |
+
rbargs = dict()
|
77 |
+
|
78 |
+
rbargs.setdefault('--tempo', rate)
|
79 |
+
|
80 |
+
return __rubberband(y, sr, **rbargs)
|
81 |
+
|
82 |
+
def pitch_shift(y, sr, n_steps, rbargs=None):
|
83 |
+
|
84 |
+
if n_steps == 0:
|
85 |
+
return y
|
86 |
+
|
87 |
+
if rbargs is None:
|
88 |
+
rbargs = dict()
|
89 |
+
|
90 |
+
rbargs.setdefault('--pitch', n_steps)
|
91 |
+
|
92 |
+
return __rubberband(y, sr, **rbargs)
|
lib_v5/spec_utils.py
ADDED
@@ -0,0 +1,692 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import librosa
|
2 |
+
import numpy as np
|
3 |
+
import soundfile as sf
|
4 |
+
import math
|
5 |
+
import random
|
6 |
+
import math
|
7 |
+
import platform
|
8 |
+
import traceback
|
9 |
+
from . import pyrb
|
10 |
+
#cur
|
11 |
+
OPERATING_SYSTEM = platform.system()
|
12 |
+
SYSTEM_ARCH = platform.platform()
|
13 |
+
SYSTEM_PROC = platform.processor()
|
14 |
+
ARM = 'arm'
|
15 |
+
|
16 |
+
if OPERATING_SYSTEM == 'Windows':
|
17 |
+
from pyrubberband import pyrb
|
18 |
+
else:
|
19 |
+
from . import pyrb
|
20 |
+
|
21 |
+
if OPERATING_SYSTEM == 'Darwin':
|
22 |
+
wav_resolution = "polyphase" if SYSTEM_PROC == ARM or ARM in SYSTEM_ARCH else "sinc_fastest"
|
23 |
+
else:
|
24 |
+
wav_resolution = "sinc_fastest"
|
25 |
+
|
26 |
+
MAX_SPEC = 'Max Spec'
|
27 |
+
MIN_SPEC = 'Min Spec'
|
28 |
+
AVERAGE = 'Average'
|
29 |
+
|
30 |
+
def crop_center(h1, h2):
|
31 |
+
h1_shape = h1.size()
|
32 |
+
h2_shape = h2.size()
|
33 |
+
|
34 |
+
if h1_shape[3] == h2_shape[3]:
|
35 |
+
return h1
|
36 |
+
elif h1_shape[3] < h2_shape[3]:
|
37 |
+
raise ValueError('h1_shape[3] must be greater than h2_shape[3]')
|
38 |
+
|
39 |
+
s_time = (h1_shape[3] - h2_shape[3]) // 2
|
40 |
+
e_time = s_time + h2_shape[3]
|
41 |
+
h1 = h1[:, :, :, s_time:e_time]
|
42 |
+
|
43 |
+
return h1
|
44 |
+
|
45 |
+
def preprocess(X_spec):
|
46 |
+
X_mag = np.abs(X_spec)
|
47 |
+
X_phase = np.angle(X_spec)
|
48 |
+
|
49 |
+
return X_mag, X_phase
|
50 |
+
|
51 |
+
def make_padding(width, cropsize, offset):
|
52 |
+
left = offset
|
53 |
+
roi_size = cropsize - offset * 2
|
54 |
+
if roi_size == 0:
|
55 |
+
roi_size = cropsize
|
56 |
+
right = roi_size - (width % roi_size) + left
|
57 |
+
|
58 |
+
return left, right, roi_size
|
59 |
+
|
60 |
+
def wave_to_spectrogram(wave, hop_length, n_fft, mid_side=False, mid_side_b2=False, reverse=False):
|
61 |
+
if reverse:
|
62 |
+
wave_left = np.flip(np.asfortranarray(wave[0]))
|
63 |
+
wave_right = np.flip(np.asfortranarray(wave[1]))
|
64 |
+
elif mid_side:
|
65 |
+
wave_left = np.asfortranarray(np.add(wave[0], wave[1]) / 2)
|
66 |
+
wave_right = np.asfortranarray(np.subtract(wave[0], wave[1]))
|
67 |
+
elif mid_side_b2:
|
68 |
+
wave_left = np.asfortranarray(np.add(wave[1], wave[0] * .5))
|
69 |
+
wave_right = np.asfortranarray(np.subtract(wave[0], wave[1] * .5))
|
70 |
+
else:
|
71 |
+
wave_left = np.asfortranarray(wave[0])
|
72 |
+
wave_right = np.asfortranarray(wave[1])
|
73 |
+
|
74 |
+
spec_left = librosa.stft(wave_left, n_fft, hop_length=hop_length)
|
75 |
+
spec_right = librosa.stft(wave_right, n_fft, hop_length=hop_length)
|
76 |
+
|
77 |
+
spec = np.asfortranarray([spec_left, spec_right])
|
78 |
+
|
79 |
+
return spec
|
80 |
+
|
81 |
+
def wave_to_spectrogram_mt(wave, hop_length, n_fft, mid_side=False, mid_side_b2=False, reverse=False):
|
82 |
+
import threading
|
83 |
+
|
84 |
+
if reverse:
|
85 |
+
wave_left = np.flip(np.asfortranarray(wave[0]))
|
86 |
+
wave_right = np.flip(np.asfortranarray(wave[1]))
|
87 |
+
elif mid_side:
|
88 |
+
wave_left = np.asfortranarray(np.add(wave[0], wave[1]) / 2)
|
89 |
+
wave_right = np.asfortranarray(np.subtract(wave[0], wave[1]))
|
90 |
+
elif mid_side_b2:
|
91 |
+
wave_left = np.asfortranarray(np.add(wave[1], wave[0] * .5))
|
92 |
+
wave_right = np.asfortranarray(np.subtract(wave[0], wave[1] * .5))
|
93 |
+
else:
|
94 |
+
wave_left = np.asfortranarray(wave[0])
|
95 |
+
wave_right = np.asfortranarray(wave[1])
|
96 |
+
|
97 |
+
def run_thread(**kwargs):
|
98 |
+
global spec_left
|
99 |
+
spec_left = librosa.stft(**kwargs)
|
100 |
+
|
101 |
+
thread = threading.Thread(target=run_thread, kwargs={'y': wave_left, 'n_fft': n_fft, 'hop_length': hop_length})
|
102 |
+
thread.start()
|
103 |
+
spec_right = librosa.stft(wave_right, n_fft, hop_length=hop_length)
|
104 |
+
thread.join()
|
105 |
+
|
106 |
+
spec = np.asfortranarray([spec_left, spec_right])
|
107 |
+
|
108 |
+
return spec
|
109 |
+
|
110 |
+
def normalize(wave, is_normalize=False):
|
111 |
+
"""Save output music files"""
|
112 |
+
maxv = np.abs(wave).max()
|
113 |
+
if maxv > 1.0:
|
114 |
+
print(f"\nNormalization Set {is_normalize}: Input above threshold for clipping. Max:{maxv}")
|
115 |
+
if is_normalize:
|
116 |
+
print(f"The result was normalized.")
|
117 |
+
wave /= maxv
|
118 |
+
else:
|
119 |
+
print(f"The result was not normalized.")
|
120 |
+
else:
|
121 |
+
print(f"\nNormalization Set {is_normalize}: Input not above threshold for clipping. Max:{maxv}")
|
122 |
+
|
123 |
+
return wave
|
124 |
+
|
125 |
+
def normalize_two_stem(wave, mix, is_normalize=False):
|
126 |
+
"""Save output music files"""
|
127 |
+
|
128 |
+
maxv = np.abs(wave).max()
|
129 |
+
max_mix = np.abs(mix).max()
|
130 |
+
|
131 |
+
if maxv > 1.0:
|
132 |
+
print(f"\nNormalization Set {is_normalize}: Primary source above threshold for clipping. Max:{maxv}")
|
133 |
+
print(f"\nNormalization Set {is_normalize}: Mixture above threshold for clipping. Max:{max_mix}")
|
134 |
+
if is_normalize:
|
135 |
+
print(f"The result was normalized.")
|
136 |
+
wave /= maxv
|
137 |
+
mix /= maxv
|
138 |
+
else:
|
139 |
+
print(f"The result was not normalized.")
|
140 |
+
else:
|
141 |
+
print(f"\nNormalization Set {is_normalize}: Input not above threshold for clipping. Max:{maxv}")
|
142 |
+
|
143 |
+
|
144 |
+
print(f"\nNormalization Set {is_normalize}: Primary source - Max:{np.abs(wave).max()}")
|
145 |
+
print(f"\nNormalization Set {is_normalize}: Mixture - Max:{np.abs(mix).max()}")
|
146 |
+
|
147 |
+
return wave, mix
|
148 |
+
|
149 |
+
def combine_spectrograms(specs, mp):
|
150 |
+
l = min([specs[i].shape[2] for i in specs])
|
151 |
+
spec_c = np.zeros(shape=(2, mp.param['bins'] + 1, l), dtype=np.complex64)
|
152 |
+
offset = 0
|
153 |
+
bands_n = len(mp.param['band'])
|
154 |
+
|
155 |
+
for d in range(1, bands_n + 1):
|
156 |
+
h = mp.param['band'][d]['crop_stop'] - mp.param['band'][d]['crop_start']
|
157 |
+
spec_c[:, offset:offset+h, :l] = specs[d][:, mp.param['band'][d]['crop_start']:mp.param['band'][d]['crop_stop'], :l]
|
158 |
+
offset += h
|
159 |
+
|
160 |
+
if offset > mp.param['bins']:
|
161 |
+
raise ValueError('Too much bins')
|
162 |
+
|
163 |
+
# lowpass fiter
|
164 |
+
if mp.param['pre_filter_start'] > 0: # and mp.param['band'][bands_n]['res_type'] in ['scipy', 'polyphase']:
|
165 |
+
if bands_n == 1:
|
166 |
+
spec_c = fft_lp_filter(spec_c, mp.param['pre_filter_start'], mp.param['pre_filter_stop'])
|
167 |
+
else:
|
168 |
+
gp = 1
|
169 |
+
for b in range(mp.param['pre_filter_start'] + 1, mp.param['pre_filter_stop']):
|
170 |
+
g = math.pow(10, -(b - mp.param['pre_filter_start']) * (3.5 - gp) / 20.0)
|
171 |
+
gp = g
|
172 |
+
spec_c[:, b, :] *= g
|
173 |
+
|
174 |
+
return np.asfortranarray(spec_c)
|
175 |
+
|
176 |
+
def spectrogram_to_image(spec, mode='magnitude'):
|
177 |
+
if mode == 'magnitude':
|
178 |
+
if np.iscomplexobj(spec):
|
179 |
+
y = np.abs(spec)
|
180 |
+
else:
|
181 |
+
y = spec
|
182 |
+
y = np.log10(y ** 2 + 1e-8)
|
183 |
+
elif mode == 'phase':
|
184 |
+
if np.iscomplexobj(spec):
|
185 |
+
y = np.angle(spec)
|
186 |
+
else:
|
187 |
+
y = spec
|
188 |
+
|
189 |
+
y -= y.min()
|
190 |
+
y *= 255 / y.max()
|
191 |
+
img = np.uint8(y)
|
192 |
+
|
193 |
+
if y.ndim == 3:
|
194 |
+
img = img.transpose(1, 2, 0)
|
195 |
+
img = np.concatenate([
|
196 |
+
np.max(img, axis=2, keepdims=True), img
|
197 |
+
], axis=2)
|
198 |
+
|
199 |
+
return img
|
200 |
+
|
201 |
+
def reduce_vocal_aggressively(X, y, softmask):
|
202 |
+
v = X - y
|
203 |
+
y_mag_tmp = np.abs(y)
|
204 |
+
v_mag_tmp = np.abs(v)
|
205 |
+
|
206 |
+
v_mask = v_mag_tmp > y_mag_tmp
|
207 |
+
y_mag = np.clip(y_mag_tmp - v_mag_tmp * v_mask * softmask, 0, np.inf)
|
208 |
+
|
209 |
+
return y_mag * np.exp(1.j * np.angle(y))
|
210 |
+
|
211 |
+
def merge_artifacts(y_mask, thres=0.01, min_range=64, fade_size=32):
|
212 |
+
mask = y_mask
|
213 |
+
|
214 |
+
try:
|
215 |
+
if min_range < fade_size * 2:
|
216 |
+
raise ValueError('min_range must be >= fade_size * 2')
|
217 |
+
|
218 |
+
idx = np.where(y_mask.min(axis=(0, 1)) > thres)[0]
|
219 |
+
start_idx = np.insert(idx[np.where(np.diff(idx) != 1)[0] + 1], 0, idx[0])
|
220 |
+
end_idx = np.append(idx[np.where(np.diff(idx) != 1)[0]], idx[-1])
|
221 |
+
artifact_idx = np.where(end_idx - start_idx > min_range)[0]
|
222 |
+
weight = np.zeros_like(y_mask)
|
223 |
+
if len(artifact_idx) > 0:
|
224 |
+
start_idx = start_idx[artifact_idx]
|
225 |
+
end_idx = end_idx[artifact_idx]
|
226 |
+
old_e = None
|
227 |
+
for s, e in zip(start_idx, end_idx):
|
228 |
+
if old_e is not None and s - old_e < fade_size:
|
229 |
+
s = old_e - fade_size * 2
|
230 |
+
|
231 |
+
if s != 0:
|
232 |
+
weight[:, :, s:s + fade_size] = np.linspace(0, 1, fade_size)
|
233 |
+
else:
|
234 |
+
s -= fade_size
|
235 |
+
|
236 |
+
if e != y_mask.shape[2]:
|
237 |
+
weight[:, :, e - fade_size:e] = np.linspace(1, 0, fade_size)
|
238 |
+
else:
|
239 |
+
e += fade_size
|
240 |
+
|
241 |
+
weight[:, :, s + fade_size:e - fade_size] = 1
|
242 |
+
old_e = e
|
243 |
+
|
244 |
+
v_mask = 1 - y_mask
|
245 |
+
y_mask += weight * v_mask
|
246 |
+
|
247 |
+
mask = y_mask
|
248 |
+
except Exception as e:
|
249 |
+
error_name = f'{type(e).__name__}'
|
250 |
+
traceback_text = ''.join(traceback.format_tb(e.__traceback__))
|
251 |
+
message = f'{error_name}: "{e}"\n{traceback_text}"'
|
252 |
+
print('Post Process Failed: ', message)
|
253 |
+
|
254 |
+
|
255 |
+
return mask
|
256 |
+
|
257 |
+
def align_wave_head_and_tail(a, b):
|
258 |
+
l = min([a[0].size, b[0].size])
|
259 |
+
|
260 |
+
return a[:l,:l], b[:l,:l]
|
261 |
+
|
262 |
+
def spectrogram_to_wave(spec, hop_length, mid_side, mid_side_b2, reverse, clamp=False):
|
263 |
+
spec_left = np.asfortranarray(spec[0])
|
264 |
+
spec_right = np.asfortranarray(spec[1])
|
265 |
+
|
266 |
+
wave_left = librosa.istft(spec_left, hop_length=hop_length)
|
267 |
+
wave_right = librosa.istft(spec_right, hop_length=hop_length)
|
268 |
+
|
269 |
+
if reverse:
|
270 |
+
return np.asfortranarray([np.flip(wave_left), np.flip(wave_right)])
|
271 |
+
elif mid_side:
|
272 |
+
return np.asfortranarray([np.add(wave_left, wave_right / 2), np.subtract(wave_left, wave_right / 2)])
|
273 |
+
elif mid_side_b2:
|
274 |
+
return np.asfortranarray([np.add(wave_right / 1.25, .4 * wave_left), np.subtract(wave_left / 1.25, .4 * wave_right)])
|
275 |
+
else:
|
276 |
+
return np.asfortranarray([wave_left, wave_right])
|
277 |
+
|
278 |
+
def spectrogram_to_wave_mt(spec, hop_length, mid_side, reverse, mid_side_b2):
|
279 |
+
import threading
|
280 |
+
|
281 |
+
spec_left = np.asfortranarray(spec[0])
|
282 |
+
spec_right = np.asfortranarray(spec[1])
|
283 |
+
|
284 |
+
def run_thread(**kwargs):
|
285 |
+
global wave_left
|
286 |
+
wave_left = librosa.istft(**kwargs)
|
287 |
+
|
288 |
+
thread = threading.Thread(target=run_thread, kwargs={'stft_matrix': spec_left, 'hop_length': hop_length})
|
289 |
+
thread.start()
|
290 |
+
wave_right = librosa.istft(spec_right, hop_length=hop_length)
|
291 |
+
thread.join()
|
292 |
+
|
293 |
+
if reverse:
|
294 |
+
return np.asfortranarray([np.flip(wave_left), np.flip(wave_right)])
|
295 |
+
elif mid_side:
|
296 |
+
return np.asfortranarray([np.add(wave_left, wave_right / 2), np.subtract(wave_left, wave_right / 2)])
|
297 |
+
elif mid_side_b2:
|
298 |
+
return np.asfortranarray([np.add(wave_right / 1.25, .4 * wave_left), np.subtract(wave_left / 1.25, .4 * wave_right)])
|
299 |
+
else:
|
300 |
+
return np.asfortranarray([wave_left, wave_right])
|
301 |
+
|
302 |
+
def cmb_spectrogram_to_wave(spec_m, mp, extra_bins_h=None, extra_bins=None):
|
303 |
+
bands_n = len(mp.param['band'])
|
304 |
+
offset = 0
|
305 |
+
|
306 |
+
for d in range(1, bands_n + 1):
|
307 |
+
bp = mp.param['band'][d]
|
308 |
+
spec_s = np.ndarray(shape=(2, bp['n_fft'] // 2 + 1, spec_m.shape[2]), dtype=complex)
|
309 |
+
h = bp['crop_stop'] - bp['crop_start']
|
310 |
+
spec_s[:, bp['crop_start']:bp['crop_stop'], :] = spec_m[:, offset:offset+h, :]
|
311 |
+
|
312 |
+
offset += h
|
313 |
+
if d == bands_n: # higher
|
314 |
+
if extra_bins_h: # if --high_end_process bypass
|
315 |
+
max_bin = bp['n_fft'] // 2
|
316 |
+
spec_s[:, max_bin-extra_bins_h:max_bin, :] = extra_bins[:, :extra_bins_h, :]
|
317 |
+
if bp['hpf_start'] > 0:
|
318 |
+
spec_s = fft_hp_filter(spec_s, bp['hpf_start'], bp['hpf_stop'] - 1)
|
319 |
+
if bands_n == 1:
|
320 |
+
wave = spectrogram_to_wave(spec_s, bp['hl'], mp.param['mid_side'], mp.param['mid_side_b2'], mp.param['reverse'])
|
321 |
+
else:
|
322 |
+
wave = np.add(wave, spectrogram_to_wave(spec_s, bp['hl'], mp.param['mid_side'], mp.param['mid_side_b2'], mp.param['reverse']))
|
323 |
+
else:
|
324 |
+
sr = mp.param['band'][d+1]['sr']
|
325 |
+
if d == 1: # lower
|
326 |
+
spec_s = fft_lp_filter(spec_s, bp['lpf_start'], bp['lpf_stop'])
|
327 |
+
wave = librosa.resample(spectrogram_to_wave(spec_s, bp['hl'], mp.param['mid_side'], mp.param['mid_side_b2'], mp.param['reverse']), bp['sr'], sr, res_type=wav_resolution)
|
328 |
+
else: # mid
|
329 |
+
spec_s = fft_hp_filter(spec_s, bp['hpf_start'], bp['hpf_stop'] - 1)
|
330 |
+
spec_s = fft_lp_filter(spec_s, bp['lpf_start'], bp['lpf_stop'])
|
331 |
+
wave2 = np.add(wave, spectrogram_to_wave(spec_s, bp['hl'], mp.param['mid_side'], mp.param['mid_side_b2'], mp.param['reverse']))
|
332 |
+
wave = librosa.resample(wave2, bp['sr'], sr, res_type=wav_resolution)
|
333 |
+
|
334 |
+
return wave
|
335 |
+
|
336 |
+
def fft_lp_filter(spec, bin_start, bin_stop):
|
337 |
+
g = 1.0
|
338 |
+
for b in range(bin_start, bin_stop):
|
339 |
+
g -= 1 / (bin_stop - bin_start)
|
340 |
+
spec[:, b, :] = g * spec[:, b, :]
|
341 |
+
|
342 |
+
spec[:, bin_stop:, :] *= 0
|
343 |
+
|
344 |
+
return spec
|
345 |
+
|
346 |
+
def fft_hp_filter(spec, bin_start, bin_stop):
|
347 |
+
g = 1.0
|
348 |
+
for b in range(bin_start, bin_stop, -1):
|
349 |
+
g -= 1 / (bin_start - bin_stop)
|
350 |
+
spec[:, b, :] = g * spec[:, b, :]
|
351 |
+
|
352 |
+
spec[:, 0:bin_stop+1, :] *= 0
|
353 |
+
|
354 |
+
return spec
|
355 |
+
|
356 |
+
def mirroring(a, spec_m, input_high_end, mp):
|
357 |
+
if 'mirroring' == a:
|
358 |
+
mirror = np.flip(np.abs(spec_m[:, mp.param['pre_filter_start']-10-input_high_end.shape[1]:mp.param['pre_filter_start']-10, :]), 1)
|
359 |
+
mirror = mirror * np.exp(1.j * np.angle(input_high_end))
|
360 |
+
|
361 |
+
return np.where(np.abs(input_high_end) <= np.abs(mirror), input_high_end, mirror)
|
362 |
+
|
363 |
+
if 'mirroring2' == a:
|
364 |
+
mirror = np.flip(np.abs(spec_m[:, mp.param['pre_filter_start']-10-input_high_end.shape[1]:mp.param['pre_filter_start']-10, :]), 1)
|
365 |
+
mi = np.multiply(mirror, input_high_end * 1.7)
|
366 |
+
|
367 |
+
return np.where(np.abs(input_high_end) <= np.abs(mi), input_high_end, mi)
|
368 |
+
|
369 |
+
def adjust_aggr(mask, is_non_accom_stem, aggressiveness):
|
370 |
+
aggr = aggressiveness['value']
|
371 |
+
|
372 |
+
if aggr != 0:
|
373 |
+
if is_non_accom_stem:
|
374 |
+
aggr = 1 - aggr
|
375 |
+
|
376 |
+
aggr = [aggr, aggr]
|
377 |
+
|
378 |
+
if aggressiveness['aggr_correction'] is not None:
|
379 |
+
aggr[0] += aggressiveness['aggr_correction']['left']
|
380 |
+
aggr[1] += aggressiveness['aggr_correction']['right']
|
381 |
+
|
382 |
+
for ch in range(2):
|
383 |
+
mask[ch, :aggressiveness['split_bin']] = np.power(mask[ch, :aggressiveness['split_bin']], 1 + aggr[ch] / 3)
|
384 |
+
mask[ch, aggressiveness['split_bin']:] = np.power(mask[ch, aggressiveness['split_bin']:], 1 + aggr[ch])
|
385 |
+
|
386 |
+
# if is_non_accom_stem:
|
387 |
+
# mask = (1.0 - mask)
|
388 |
+
|
389 |
+
return mask
|
390 |
+
|
391 |
+
def stft(wave, nfft, hl):
|
392 |
+
wave_left = np.asfortranarray(wave[0])
|
393 |
+
wave_right = np.asfortranarray(wave[1])
|
394 |
+
spec_left = librosa.stft(wave_left, nfft, hop_length=hl)
|
395 |
+
spec_right = librosa.stft(wave_right, nfft, hop_length=hl)
|
396 |
+
spec = np.asfortranarray([spec_left, spec_right])
|
397 |
+
|
398 |
+
return spec
|
399 |
+
|
400 |
+
def istft(spec, hl):
|
401 |
+
spec_left = np.asfortranarray(spec[0])
|
402 |
+
spec_right = np.asfortranarray(spec[1])
|
403 |
+
wave_left = librosa.istft(spec_left, hop_length=hl)
|
404 |
+
wave_right = librosa.istft(spec_right, hop_length=hl)
|
405 |
+
wave = np.asfortranarray([wave_left, wave_right])
|
406 |
+
|
407 |
+
return wave
|
408 |
+
|
409 |
+
def spec_effects(wave, algorithm='Default', value=None):
|
410 |
+
spec = [stft(wave[0],2048,1024), stft(wave[1],2048,1024)]
|
411 |
+
if algorithm == 'Min_Mag':
|
412 |
+
v_spec_m = np.where(np.abs(spec[1]) <= np.abs(spec[0]), spec[1], spec[0])
|
413 |
+
wave = istft(v_spec_m,1024)
|
414 |
+
elif algorithm == 'Max_Mag':
|
415 |
+
v_spec_m = np.where(np.abs(spec[1]) >= np.abs(spec[0]), spec[1], spec[0])
|
416 |
+
wave = istft(v_spec_m,1024)
|
417 |
+
elif algorithm == 'Default':
|
418 |
+
wave = (wave[1] * value) + (wave[0] * (1-value))
|
419 |
+
elif algorithm == 'Invert_p':
|
420 |
+
X_mag = np.abs(spec[0])
|
421 |
+
y_mag = np.abs(spec[1])
|
422 |
+
max_mag = np.where(X_mag >= y_mag, X_mag, y_mag)
|
423 |
+
v_spec = spec[1] - max_mag * np.exp(1.j * np.angle(spec[0]))
|
424 |
+
wave = istft(v_spec,1024)
|
425 |
+
|
426 |
+
return wave
|
427 |
+
|
428 |
+
def spectrogram_to_wave_no_mp(spec, n_fft=2048, hop_length=1024):
|
429 |
+
wave = librosa.istft(spec, n_fft=n_fft, hop_length=hop_length)
|
430 |
+
|
431 |
+
if wave.ndim == 1:
|
432 |
+
wave = np.asfortranarray([wave,wave])
|
433 |
+
|
434 |
+
return wave
|
435 |
+
|
436 |
+
def wave_to_spectrogram_no_mp(wave):
|
437 |
+
|
438 |
+
spec = librosa.stft(wave, n_fft=2048, hop_length=1024)
|
439 |
+
|
440 |
+
if spec.ndim == 1:
|
441 |
+
spec = np.asfortranarray([spec,spec])
|
442 |
+
|
443 |
+
return spec
|
444 |
+
|
445 |
+
def invert_audio(specs, invert_p=True):
|
446 |
+
|
447 |
+
ln = min([specs[0].shape[2], specs[1].shape[2]])
|
448 |
+
specs[0] = specs[0][:,:,:ln]
|
449 |
+
specs[1] = specs[1][:,:,:ln]
|
450 |
+
|
451 |
+
if invert_p:
|
452 |
+
X_mag = np.abs(specs[0])
|
453 |
+
y_mag = np.abs(specs[1])
|
454 |
+
max_mag = np.where(X_mag >= y_mag, X_mag, y_mag)
|
455 |
+
v_spec = specs[1] - max_mag * np.exp(1.j * np.angle(specs[0]))
|
456 |
+
else:
|
457 |
+
specs[1] = reduce_vocal_aggressively(specs[0], specs[1], 0.2)
|
458 |
+
v_spec = specs[0] - specs[1]
|
459 |
+
|
460 |
+
return v_spec
|
461 |
+
|
462 |
+
def invert_stem(mixture, stem):
|
463 |
+
|
464 |
+
mixture = wave_to_spectrogram_no_mp(mixture)
|
465 |
+
stem = wave_to_spectrogram_no_mp(stem)
|
466 |
+
output = spectrogram_to_wave_no_mp(invert_audio([mixture, stem]))
|
467 |
+
|
468 |
+
return -output.T
|
469 |
+
|
470 |
+
def ensembling(a, specs):
|
471 |
+
for i in range(1, len(specs)):
|
472 |
+
if i == 1:
|
473 |
+
spec = specs[0]
|
474 |
+
|
475 |
+
ln = min([spec.shape[2], specs[i].shape[2]])
|
476 |
+
spec = spec[:,:,:ln]
|
477 |
+
specs[i] = specs[i][:,:,:ln]
|
478 |
+
|
479 |
+
if MIN_SPEC == a:
|
480 |
+
spec = np.where(np.abs(specs[i]) <= np.abs(spec), specs[i], spec)
|
481 |
+
if MAX_SPEC == a:
|
482 |
+
spec = np.where(np.abs(specs[i]) >= np.abs(spec), specs[i], spec)
|
483 |
+
if AVERAGE == a:
|
484 |
+
spec = np.where(np.abs(specs[i]) == np.abs(spec), specs[i], spec)
|
485 |
+
|
486 |
+
return spec
|
487 |
+
|
488 |
+
def ensemble_inputs(audio_input, algorithm, is_normalization, wav_type_set, save_path):
|
489 |
+
|
490 |
+
wavs_ = []
|
491 |
+
|
492 |
+
if algorithm == AVERAGE:
|
493 |
+
output = average_audio(audio_input)
|
494 |
+
samplerate = 44100
|
495 |
+
else:
|
496 |
+
specs = []
|
497 |
+
|
498 |
+
for i in range(len(audio_input)):
|
499 |
+
wave, samplerate = librosa.load(audio_input[i], mono=False, sr=44100)
|
500 |
+
wavs_.append(wave)
|
501 |
+
spec = wave_to_spectrogram_no_mp(wave)
|
502 |
+
specs.append(spec)
|
503 |
+
|
504 |
+
wave_shapes = [w.shape[1] for w in wavs_]
|
505 |
+
target_shape = wavs_[wave_shapes.index(max(wave_shapes))]
|
506 |
+
|
507 |
+
output = spectrogram_to_wave_no_mp(ensembling(algorithm, specs))
|
508 |
+
output = to_shape(output, target_shape.shape)
|
509 |
+
|
510 |
+
sf.write(save_path, normalize(output.T, is_normalization), samplerate, subtype=wav_type_set)
|
511 |
+
|
512 |
+
def to_shape(x, target_shape):
|
513 |
+
padding_list = []
|
514 |
+
for x_dim, target_dim in zip(x.shape, target_shape):
|
515 |
+
pad_value = (target_dim - x_dim)
|
516 |
+
pad_tuple = ((0, pad_value))
|
517 |
+
padding_list.append(pad_tuple)
|
518 |
+
|
519 |
+
return np.pad(x, tuple(padding_list), mode='constant')
|
520 |
+
|
521 |
+
def to_shape_minimize(x: np.ndarray, target_shape):
|
522 |
+
|
523 |
+
padding_list = []
|
524 |
+
for x_dim, target_dim in zip(x.shape, target_shape):
|
525 |
+
pad_value = (target_dim - x_dim)
|
526 |
+
pad_tuple = ((0, pad_value))
|
527 |
+
padding_list.append(pad_tuple)
|
528 |
+
|
529 |
+
return np.pad(x, tuple(padding_list), mode='constant')
|
530 |
+
|
531 |
+
def augment_audio(export_path, audio_file, rate, is_normalization, wav_type_set, save_format=None, is_pitch=False):
|
532 |
+
|
533 |
+
wav, sr = librosa.load(audio_file, sr=44100, mono=False)
|
534 |
+
|
535 |
+
if wav.ndim == 1:
|
536 |
+
wav = np.asfortranarray([wav,wav])
|
537 |
+
|
538 |
+
if is_pitch:
|
539 |
+
wav_1 = pyrb.pitch_shift(wav[0], sr, rate, rbargs=None)
|
540 |
+
wav_2 = pyrb.pitch_shift(wav[1], sr, rate, rbargs=None)
|
541 |
+
else:
|
542 |
+
wav_1 = pyrb.time_stretch(wav[0], sr, rate, rbargs=None)
|
543 |
+
wav_2 = pyrb.time_stretch(wav[1], sr, rate, rbargs=None)
|
544 |
+
|
545 |
+
if wav_1.shape > wav_2.shape:
|
546 |
+
wav_2 = to_shape(wav_2, wav_1.shape)
|
547 |
+
if wav_1.shape < wav_2.shape:
|
548 |
+
wav_1 = to_shape(wav_1, wav_2.shape)
|
549 |
+
|
550 |
+
wav_mix = np.asfortranarray([wav_1, wav_2])
|
551 |
+
|
552 |
+
sf.write(export_path, normalize(wav_mix.T, is_normalization), sr, subtype=wav_type_set)
|
553 |
+
save_format(export_path)
|
554 |
+
|
555 |
+
def average_audio(audio):
|
556 |
+
|
557 |
+
waves = []
|
558 |
+
wave_shapes = []
|
559 |
+
final_waves = []
|
560 |
+
|
561 |
+
for i in range(len(audio)):
|
562 |
+
wave = librosa.load(audio[i], sr=44100, mono=False)
|
563 |
+
waves.append(wave[0])
|
564 |
+
wave_shapes.append(wave[0].shape[1])
|
565 |
+
|
566 |
+
wave_shapes_index = wave_shapes.index(max(wave_shapes))
|
567 |
+
target_shape = waves[wave_shapes_index]
|
568 |
+
waves.pop(wave_shapes_index)
|
569 |
+
final_waves.append(target_shape)
|
570 |
+
|
571 |
+
for n_array in waves:
|
572 |
+
wav_target = to_shape(n_array, target_shape.shape)
|
573 |
+
final_waves.append(wav_target)
|
574 |
+
|
575 |
+
waves = sum(final_waves)
|
576 |
+
waves = waves/len(audio)
|
577 |
+
|
578 |
+
return waves
|
579 |
+
|
580 |
+
def average_dual_sources(wav_1, wav_2, value):
|
581 |
+
|
582 |
+
if wav_1.shape > wav_2.shape:
|
583 |
+
wav_2 = to_shape(wav_2, wav_1.shape)
|
584 |
+
if wav_1.shape < wav_2.shape:
|
585 |
+
wav_1 = to_shape(wav_1, wav_2.shape)
|
586 |
+
|
587 |
+
wave = (wav_1 * value) + (wav_2 * (1-value))
|
588 |
+
|
589 |
+
return wave
|
590 |
+
|
591 |
+
def reshape_sources(wav_1: np.ndarray, wav_2: np.ndarray):
|
592 |
+
|
593 |
+
if wav_1.shape > wav_2.shape:
|
594 |
+
wav_2 = to_shape(wav_2, wav_1.shape)
|
595 |
+
if wav_1.shape < wav_2.shape:
|
596 |
+
ln = min([wav_1.shape[1], wav_2.shape[1]])
|
597 |
+
wav_2 = wav_2[:,:ln]
|
598 |
+
|
599 |
+
ln = min([wav_1.shape[1], wav_2.shape[1]])
|
600 |
+
wav_1 = wav_1[:,:ln]
|
601 |
+
wav_2 = wav_2[:,:ln]
|
602 |
+
|
603 |
+
return wav_2
|
604 |
+
|
605 |
+
def align_audio(file1, file2, file2_aligned, file_subtracted, wav_type_set, is_normalization, command_Text, progress_bar_main_var, save_format):
|
606 |
+
def get_diff(a, b):
|
607 |
+
corr = np.correlate(a, b, "full")
|
608 |
+
diff = corr.argmax() - (b.shape[0] - 1)
|
609 |
+
return diff
|
610 |
+
|
611 |
+
progress_bar_main_var.set(10)
|
612 |
+
|
613 |
+
# read tracks
|
614 |
+
wav1, sr1 = librosa.load(file1, sr=44100, mono=False)
|
615 |
+
wav2, sr2 = librosa.load(file2, sr=44100, mono=False)
|
616 |
+
wav1 = wav1.transpose()
|
617 |
+
wav2 = wav2.transpose()
|
618 |
+
|
619 |
+
command_Text(f"Audio file shapes: {wav1.shape} / {wav2.shape}\n")
|
620 |
+
|
621 |
+
wav2_org = wav2.copy()
|
622 |
+
progress_bar_main_var.set(20)
|
623 |
+
|
624 |
+
command_Text("Processing files... \n")
|
625 |
+
|
626 |
+
# pick random position and get diff
|
627 |
+
|
628 |
+
counts = {} # counting up for each diff value
|
629 |
+
progress = 20
|
630 |
+
|
631 |
+
check_range = 64
|
632 |
+
|
633 |
+
base = (64 / check_range)
|
634 |
+
|
635 |
+
for i in range(check_range):
|
636 |
+
index = int(random.uniform(44100 * 2, min(wav1.shape[0], wav2.shape[0]) - 44100 * 2))
|
637 |
+
shift = int(random.uniform(-22050,+22050))
|
638 |
+
samp1 = wav1[index :index +44100, 0] # currently use left channel
|
639 |
+
samp2 = wav2[index+shift:index+shift+44100, 0]
|
640 |
+
progress += 1 * base
|
641 |
+
progress_bar_main_var.set(progress)
|
642 |
+
diff = get_diff(samp1, samp2)
|
643 |
+
diff -= shift
|
644 |
+
|
645 |
+
if abs(diff) < 22050:
|
646 |
+
if not diff in counts:
|
647 |
+
counts[diff] = 0
|
648 |
+
counts[diff] += 1
|
649 |
+
|
650 |
+
# use max counted diff value
|
651 |
+
max_count = 0
|
652 |
+
est_diff = 0
|
653 |
+
for diff in counts.keys():
|
654 |
+
if counts[diff] > max_count:
|
655 |
+
max_count = counts[diff]
|
656 |
+
est_diff = diff
|
657 |
+
|
658 |
+
command_Text(f"Estimated difference is {est_diff} (count: {max_count})\n")
|
659 |
+
|
660 |
+
progress_bar_main_var.set(90)
|
661 |
+
|
662 |
+
audio_files = []
|
663 |
+
|
664 |
+
def save_aligned_audio(wav2_aligned):
|
665 |
+
command_Text(f"Aligned File 2 with File 1.\n")
|
666 |
+
command_Text(f"Saving files... ")
|
667 |
+
sf.write(file2_aligned, normalize(wav2_aligned, is_normalization), sr2, subtype=wav_type_set)
|
668 |
+
save_format(file2_aligned)
|
669 |
+
min_len = min(wav1.shape[0], wav2_aligned.shape[0])
|
670 |
+
wav_sub = wav1[:min_len] - wav2_aligned[:min_len]
|
671 |
+
audio_files.append(file2_aligned)
|
672 |
+
return min_len, wav_sub
|
673 |
+
|
674 |
+
# make aligned track 2
|
675 |
+
if est_diff > 0:
|
676 |
+
wav2_aligned = np.append(np.zeros((est_diff, 2)), wav2_org, axis=0)
|
677 |
+
min_len, wav_sub = save_aligned_audio(wav2_aligned)
|
678 |
+
elif est_diff < 0:
|
679 |
+
wav2_aligned = wav2_org[-est_diff:]
|
680 |
+
min_len, wav_sub = save_aligned_audio(wav2_aligned)
|
681 |
+
else:
|
682 |
+
command_Text(f"Audio files already aligned.\n")
|
683 |
+
command_Text(f"Saving inverted track... ")
|
684 |
+
min_len = min(wav1.shape[0], wav2.shape[0])
|
685 |
+
wav_sub = wav1[:min_len] - wav2[:min_len]
|
686 |
+
|
687 |
+
wav_sub = np.clip(wav_sub, -1, +1)
|
688 |
+
|
689 |
+
sf.write(file_subtracted, normalize(wav_sub, is_normalization), sr1, subtype=wav_type_set)
|
690 |
+
save_format(file_subtracted)
|
691 |
+
|
692 |
+
progress_bar_main_var.set(95)
|
lib_v5/vr_network/__init__.py
ADDED
@@ -0,0 +1 @@
|
|
|
|
|
1 |
+
# VR init.
|
lib_v5/vr_network/__pycache__/__init__.cpython-310.pyc
ADDED
Binary file (152 Bytes). View file
|
|
lib_v5/vr_network/__pycache__/layers.cpython-310.pyc
ADDED
Binary file (4.47 kB). View file
|
|
lib_v5/vr_network/__pycache__/layers_new.cpython-310.pyc
ADDED
Binary file (4.44 kB). View file
|
|
lib_v5/vr_network/__pycache__/model_param_init.cpython-310.pyc
ADDED
Binary file (1.62 kB). View file
|
|
lib_v5/vr_network/__pycache__/nets.cpython-310.pyc
ADDED
Binary file (4.39 kB). View file
|
|
lib_v5/vr_network/__pycache__/nets_new.cpython-310.pyc
ADDED
Binary file (4 kB). View file
|
|
lib_v5/vr_network/layers.py
ADDED
@@ -0,0 +1,143 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import torch
|
2 |
+
from torch import nn
|
3 |
+
import torch.nn.functional as F
|
4 |
+
|
5 |
+
from lib_v5 import spec_utils
|
6 |
+
|
7 |
+
class Conv2DBNActiv(nn.Module):
|
8 |
+
|
9 |
+
def __init__(self, nin, nout, ksize=3, stride=1, pad=1, dilation=1, activ=nn.ReLU):
|
10 |
+
super(Conv2DBNActiv, self).__init__()
|
11 |
+
self.conv = nn.Sequential(
|
12 |
+
nn.Conv2d(
|
13 |
+
nin, nout,
|
14 |
+
kernel_size=ksize,
|
15 |
+
stride=stride,
|
16 |
+
padding=pad,
|
17 |
+
dilation=dilation,
|
18 |
+
bias=False),
|
19 |
+
nn.BatchNorm2d(nout),
|
20 |
+
activ()
|
21 |
+
)
|
22 |
+
|
23 |
+
def __call__(self, x):
|
24 |
+
return self.conv(x)
|
25 |
+
|
26 |
+
class SeperableConv2DBNActiv(nn.Module):
|
27 |
+
|
28 |
+
def __init__(self, nin, nout, ksize=3, stride=1, pad=1, dilation=1, activ=nn.ReLU):
|
29 |
+
super(SeperableConv2DBNActiv, self).__init__()
|
30 |
+
self.conv = nn.Sequential(
|
31 |
+
nn.Conv2d(
|
32 |
+
nin, nin,
|
33 |
+
kernel_size=ksize,
|
34 |
+
stride=stride,
|
35 |
+
padding=pad,
|
36 |
+
dilation=dilation,
|
37 |
+
groups=nin,
|
38 |
+
bias=False),
|
39 |
+
nn.Conv2d(
|
40 |
+
nin, nout,
|
41 |
+
kernel_size=1,
|
42 |
+
bias=False),
|
43 |
+
nn.BatchNorm2d(nout),
|
44 |
+
activ()
|
45 |
+
)
|
46 |
+
|
47 |
+
def __call__(self, x):
|
48 |
+
return self.conv(x)
|
49 |
+
|
50 |
+
|
51 |
+
class Encoder(nn.Module):
|
52 |
+
|
53 |
+
def __init__(self, nin, nout, ksize=3, stride=1, pad=1, activ=nn.LeakyReLU):
|
54 |
+
super(Encoder, self).__init__()
|
55 |
+
self.conv1 = Conv2DBNActiv(nin, nout, ksize, 1, pad, activ=activ)
|
56 |
+
self.conv2 = Conv2DBNActiv(nout, nout, ksize, stride, pad, activ=activ)
|
57 |
+
|
58 |
+
def __call__(self, x):
|
59 |
+
skip = self.conv1(x)
|
60 |
+
h = self.conv2(skip)
|
61 |
+
|
62 |
+
return h, skip
|
63 |
+
|
64 |
+
|
65 |
+
class Decoder(nn.Module):
|
66 |
+
|
67 |
+
def __init__(self, nin, nout, ksize=3, stride=1, pad=1, activ=nn.ReLU, dropout=False):
|
68 |
+
super(Decoder, self).__init__()
|
69 |
+
self.conv = Conv2DBNActiv(nin, nout, ksize, 1, pad, activ=activ)
|
70 |
+
self.dropout = nn.Dropout2d(0.1) if dropout else None
|
71 |
+
|
72 |
+
def __call__(self, x, skip=None):
|
73 |
+
x = F.interpolate(x, scale_factor=2, mode='bilinear', align_corners=True)
|
74 |
+
if skip is not None:
|
75 |
+
skip = spec_utils.crop_center(skip, x)
|
76 |
+
x = torch.cat([x, skip], dim=1)
|
77 |
+
h = self.conv(x)
|
78 |
+
|
79 |
+
if self.dropout is not None:
|
80 |
+
h = self.dropout(h)
|
81 |
+
|
82 |
+
return h
|
83 |
+
|
84 |
+
|
85 |
+
class ASPPModule(nn.Module):
|
86 |
+
|
87 |
+
def __init__(self, nn_architecture, nin, nout, dilations=(4, 8, 16), activ=nn.ReLU):
|
88 |
+
super(ASPPModule, self).__init__()
|
89 |
+
self.conv1 = nn.Sequential(
|
90 |
+
nn.AdaptiveAvgPool2d((1, None)),
|
91 |
+
Conv2DBNActiv(nin, nin, 1, 1, 0, activ=activ)
|
92 |
+
)
|
93 |
+
|
94 |
+
self.nn_architecture = nn_architecture
|
95 |
+
self.six_layer = [129605]
|
96 |
+
self.seven_layer = [537238, 537227, 33966]
|
97 |
+
|
98 |
+
extra_conv = SeperableConv2DBNActiv(
|
99 |
+
nin, nin, 3, 1, dilations[2], dilations[2], activ=activ)
|
100 |
+
|
101 |
+
self.conv2 = Conv2DBNActiv(nin, nin, 1, 1, 0, activ=activ)
|
102 |
+
self.conv3 = SeperableConv2DBNActiv(
|
103 |
+
nin, nin, 3, 1, dilations[0], dilations[0], activ=activ)
|
104 |
+
self.conv4 = SeperableConv2DBNActiv(
|
105 |
+
nin, nin, 3, 1, dilations[1], dilations[1], activ=activ)
|
106 |
+
self.conv5 = SeperableConv2DBNActiv(
|
107 |
+
nin, nin, 3, 1, dilations[2], dilations[2], activ=activ)
|
108 |
+
|
109 |
+
if self.nn_architecture in self.six_layer:
|
110 |
+
self.conv6 = extra_conv
|
111 |
+
nin_x = 6
|
112 |
+
elif self.nn_architecture in self.seven_layer:
|
113 |
+
self.conv6 = extra_conv
|
114 |
+
self.conv7 = extra_conv
|
115 |
+
nin_x = 7
|
116 |
+
else:
|
117 |
+
nin_x = 5
|
118 |
+
|
119 |
+
self.bottleneck = nn.Sequential(
|
120 |
+
Conv2DBNActiv(nin * nin_x, nout, 1, 1, 0, activ=activ),
|
121 |
+
nn.Dropout2d(0.1)
|
122 |
+
)
|
123 |
+
|
124 |
+
def forward(self, x):
|
125 |
+
_, _, h, w = x.size()
|
126 |
+
feat1 = F.interpolate(self.conv1(x), size=(h, w), mode='bilinear', align_corners=True)
|
127 |
+
feat2 = self.conv2(x)
|
128 |
+
feat3 = self.conv3(x)
|
129 |
+
feat4 = self.conv4(x)
|
130 |
+
feat5 = self.conv5(x)
|
131 |
+
|
132 |
+
if self.nn_architecture in self.six_layer:
|
133 |
+
feat6 = self.conv6(x)
|
134 |
+
out = torch.cat((feat1, feat2, feat3, feat4, feat5, feat6), dim=1)
|
135 |
+
elif self.nn_architecture in self.seven_layer:
|
136 |
+
feat6 = self.conv6(x)
|
137 |
+
feat7 = self.conv7(x)
|
138 |
+
out = torch.cat((feat1, feat2, feat3, feat4, feat5, feat6, feat7), dim=1)
|
139 |
+
else:
|
140 |
+
out = torch.cat((feat1, feat2, feat3, feat4, feat5), dim=1)
|
141 |
+
|
142 |
+
bottle = self.bottleneck(out)
|
143 |
+
return bottle
|
lib_v5/vr_network/layers_new.py
ADDED
@@ -0,0 +1,126 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import torch
|
2 |
+
from torch import nn
|
3 |
+
import torch.nn.functional as F
|
4 |
+
|
5 |
+
from lib_v5 import spec_utils
|
6 |
+
|
7 |
+
class Conv2DBNActiv(nn.Module):
|
8 |
+
|
9 |
+
def __init__(self, nin, nout, ksize=3, stride=1, pad=1, dilation=1, activ=nn.ReLU):
|
10 |
+
super(Conv2DBNActiv, self).__init__()
|
11 |
+
self.conv = nn.Sequential(
|
12 |
+
nn.Conv2d(
|
13 |
+
nin, nout,
|
14 |
+
kernel_size=ksize,
|
15 |
+
stride=stride,
|
16 |
+
padding=pad,
|
17 |
+
dilation=dilation,
|
18 |
+
bias=False),
|
19 |
+
nn.BatchNorm2d(nout),
|
20 |
+
activ()
|
21 |
+
)
|
22 |
+
|
23 |
+
def __call__(self, x):
|
24 |
+
return self.conv(x)
|
25 |
+
|
26 |
+
class Encoder(nn.Module):
|
27 |
+
|
28 |
+
def __init__(self, nin, nout, ksize=3, stride=1, pad=1, activ=nn.LeakyReLU):
|
29 |
+
super(Encoder, self).__init__()
|
30 |
+
self.conv1 = Conv2DBNActiv(nin, nout, ksize, stride, pad, activ=activ)
|
31 |
+
self.conv2 = Conv2DBNActiv(nout, nout, ksize, 1, pad, activ=activ)
|
32 |
+
|
33 |
+
def __call__(self, x):
|
34 |
+
h = self.conv1(x)
|
35 |
+
h = self.conv2(h)
|
36 |
+
|
37 |
+
return h
|
38 |
+
|
39 |
+
|
40 |
+
class Decoder(nn.Module):
|
41 |
+
|
42 |
+
def __init__(self, nin, nout, ksize=3, stride=1, pad=1, activ=nn.ReLU, dropout=False):
|
43 |
+
super(Decoder, self).__init__()
|
44 |
+
self.conv1 = Conv2DBNActiv(nin, nout, ksize, 1, pad, activ=activ)
|
45 |
+
# self.conv2 = Conv2DBNActiv(nout, nout, ksize, 1, pad, activ=activ)
|
46 |
+
self.dropout = nn.Dropout2d(0.1) if dropout else None
|
47 |
+
|
48 |
+
def __call__(self, x, skip=None):
|
49 |
+
x = F.interpolate(x, scale_factor=2, mode='bilinear', align_corners=True)
|
50 |
+
|
51 |
+
if skip is not None:
|
52 |
+
skip = spec_utils.crop_center(skip, x)
|
53 |
+
x = torch.cat([x, skip], dim=1)
|
54 |
+
|
55 |
+
h = self.conv1(x)
|
56 |
+
# h = self.conv2(h)
|
57 |
+
|
58 |
+
if self.dropout is not None:
|
59 |
+
h = self.dropout(h)
|
60 |
+
|
61 |
+
return h
|
62 |
+
|
63 |
+
|
64 |
+
class ASPPModule(nn.Module):
|
65 |
+
|
66 |
+
def __init__(self, nin, nout, dilations=(4, 8, 12), activ=nn.ReLU, dropout=False):
|
67 |
+
super(ASPPModule, self).__init__()
|
68 |
+
self.conv1 = nn.Sequential(
|
69 |
+
nn.AdaptiveAvgPool2d((1, None)),
|
70 |
+
Conv2DBNActiv(nin, nout, 1, 1, 0, activ=activ)
|
71 |
+
)
|
72 |
+
self.conv2 = Conv2DBNActiv(nin, nout, 1, 1, 0, activ=activ)
|
73 |
+
self.conv3 = Conv2DBNActiv(
|
74 |
+
nin, nout, 3, 1, dilations[0], dilations[0], activ=activ
|
75 |
+
)
|
76 |
+
self.conv4 = Conv2DBNActiv(
|
77 |
+
nin, nout, 3, 1, dilations[1], dilations[1], activ=activ
|
78 |
+
)
|
79 |
+
self.conv5 = Conv2DBNActiv(
|
80 |
+
nin, nout, 3, 1, dilations[2], dilations[2], activ=activ
|
81 |
+
)
|
82 |
+
self.bottleneck = Conv2DBNActiv(nout * 5, nout, 1, 1, 0, activ=activ)
|
83 |
+
self.dropout = nn.Dropout2d(0.1) if dropout else None
|
84 |
+
|
85 |
+
def forward(self, x):
|
86 |
+
_, _, h, w = x.size()
|
87 |
+
feat1 = F.interpolate(self.conv1(x), size=(h, w), mode='bilinear', align_corners=True)
|
88 |
+
feat2 = self.conv2(x)
|
89 |
+
feat3 = self.conv3(x)
|
90 |
+
feat4 = self.conv4(x)
|
91 |
+
feat5 = self.conv5(x)
|
92 |
+
out = torch.cat((feat1, feat2, feat3, feat4, feat5), dim=1)
|
93 |
+
out = self.bottleneck(out)
|
94 |
+
|
95 |
+
if self.dropout is not None:
|
96 |
+
out = self.dropout(out)
|
97 |
+
|
98 |
+
return out
|
99 |
+
|
100 |
+
|
101 |
+
class LSTMModule(nn.Module):
|
102 |
+
|
103 |
+
def __init__(self, nin_conv, nin_lstm, nout_lstm):
|
104 |
+
super(LSTMModule, self).__init__()
|
105 |
+
self.conv = Conv2DBNActiv(nin_conv, 1, 1, 1, 0)
|
106 |
+
self.lstm = nn.LSTM(
|
107 |
+
input_size=nin_lstm,
|
108 |
+
hidden_size=nout_lstm // 2,
|
109 |
+
bidirectional=True
|
110 |
+
)
|
111 |
+
self.dense = nn.Sequential(
|
112 |
+
nn.Linear(nout_lstm, nin_lstm),
|
113 |
+
nn.BatchNorm1d(nin_lstm),
|
114 |
+
nn.ReLU()
|
115 |
+
)
|
116 |
+
|
117 |
+
def forward(self, x):
|
118 |
+
N, _, nbins, nframes = x.size()
|
119 |
+
h = self.conv(x)[:, 0] # N, nbins, nframes
|
120 |
+
h = h.permute(2, 0, 1) # nframes, N, nbins
|
121 |
+
h, _ = self.lstm(h)
|
122 |
+
h = self.dense(h.reshape(-1, h.size()[-1])) # nframes * N, nbins
|
123 |
+
h = h.reshape(nframes, N, 1, nbins)
|
124 |
+
h = h.permute(1, 2, 3, 0)
|
125 |
+
|
126 |
+
return h
|
lib_v5/vr_network/model_param_init.py
ADDED
@@ -0,0 +1,59 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import json
|
2 |
+
import pathlib
|
3 |
+
|
4 |
+
default_param = {}
|
5 |
+
default_param['bins'] = 768
|
6 |
+
default_param['unstable_bins'] = 9 # training only
|
7 |
+
default_param['reduction_bins'] = 762 # training only
|
8 |
+
default_param['sr'] = 44100
|
9 |
+
default_param['pre_filter_start'] = 757
|
10 |
+
default_param['pre_filter_stop'] = 768
|
11 |
+
default_param['band'] = {}
|
12 |
+
|
13 |
+
|
14 |
+
default_param['band'][1] = {
|
15 |
+
'sr': 11025,
|
16 |
+
'hl': 128,
|
17 |
+
'n_fft': 960,
|
18 |
+
'crop_start': 0,
|
19 |
+
'crop_stop': 245,
|
20 |
+
'lpf_start': 61, # inference only
|
21 |
+
'res_type': 'polyphase'
|
22 |
+
}
|
23 |
+
|
24 |
+
default_param['band'][2] = {
|
25 |
+
'sr': 44100,
|
26 |
+
'hl': 512,
|
27 |
+
'n_fft': 1536,
|
28 |
+
'crop_start': 24,
|
29 |
+
'crop_stop': 547,
|
30 |
+
'hpf_start': 81, # inference only
|
31 |
+
'res_type': 'sinc_best'
|
32 |
+
}
|
33 |
+
|
34 |
+
|
35 |
+
def int_keys(d):
|
36 |
+
r = {}
|
37 |
+
for k, v in d:
|
38 |
+
if k.isdigit():
|
39 |
+
k = int(k)
|
40 |
+
r[k] = v
|
41 |
+
return r
|
42 |
+
|
43 |
+
|
44 |
+
class ModelParameters(object):
|
45 |
+
def __init__(self, config_path=''):
|
46 |
+
if '.pth' == pathlib.Path(config_path).suffix:
|
47 |
+
import zipfile
|
48 |
+
|
49 |
+
with zipfile.ZipFile(config_path, 'r') as zip:
|
50 |
+
self.param = json.loads(zip.read('param.json'), object_pairs_hook=int_keys)
|
51 |
+
elif '.json' == pathlib.Path(config_path).suffix:
|
52 |
+
with open(config_path, 'r') as f:
|
53 |
+
self.param = json.loads(f.read(), object_pairs_hook=int_keys)
|
54 |
+
else:
|
55 |
+
self.param = default_param
|
56 |
+
|
57 |
+
for k in ['mid_side', 'mid_side_b', 'mid_side_b2', 'stereo_w', 'stereo_n', 'reverse']:
|
58 |
+
if not k in self.param:
|
59 |
+
self.param[k] = False
|
lib_v5/vr_network/modelparams/1band_sr16000_hl512.json
ADDED
@@ -0,0 +1,19 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"bins": 1024,
|
3 |
+
"unstable_bins": 0,
|
4 |
+
"reduction_bins": 0,
|
5 |
+
"band": {
|
6 |
+
"1": {
|
7 |
+
"sr": 16000,
|
8 |
+
"hl": 512,
|
9 |
+
"n_fft": 2048,
|
10 |
+
"crop_start": 0,
|
11 |
+
"crop_stop": 1024,
|
12 |
+
"hpf_start": -1,
|
13 |
+
"res_type": "sinc_best"
|
14 |
+
}
|
15 |
+
},
|
16 |
+
"sr": 16000,
|
17 |
+
"pre_filter_start": 1023,
|
18 |
+
"pre_filter_stop": 1024
|
19 |
+
}
|
lib_v5/vr_network/modelparams/1band_sr32000_hl512.json
ADDED
@@ -0,0 +1,19 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"bins": 1024,
|
3 |
+
"unstable_bins": 0,
|
4 |
+
"reduction_bins": 0,
|
5 |
+
"band": {
|
6 |
+
"1": {
|
7 |
+
"sr": 32000,
|
8 |
+
"hl": 512,
|
9 |
+
"n_fft": 2048,
|
10 |
+
"crop_start": 0,
|
11 |
+
"crop_stop": 1024,
|
12 |
+
"hpf_start": -1,
|
13 |
+
"res_type": "kaiser_fast"
|
14 |
+
}
|
15 |
+
},
|
16 |
+
"sr": 32000,
|
17 |
+
"pre_filter_start": 1000,
|
18 |
+
"pre_filter_stop": 1021
|
19 |
+
}
|
lib_v5/vr_network/modelparams/1band_sr33075_hl384.json
ADDED
@@ -0,0 +1,19 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"bins": 1024,
|
3 |
+
"unstable_bins": 0,
|
4 |
+
"reduction_bins": 0,
|
5 |
+
"band": {
|
6 |
+
"1": {
|
7 |
+
"sr": 33075,
|
8 |
+
"hl": 384,
|
9 |
+
"n_fft": 2048,
|
10 |
+
"crop_start": 0,
|
11 |
+
"crop_stop": 1024,
|
12 |
+
"hpf_start": -1,
|
13 |
+
"res_type": "sinc_best"
|
14 |
+
}
|
15 |
+
},
|
16 |
+
"sr": 33075,
|
17 |
+
"pre_filter_start": 1000,
|
18 |
+
"pre_filter_stop": 1021
|
19 |
+
}
|
lib_v5/vr_network/modelparams/1band_sr44100_hl1024.json
ADDED
@@ -0,0 +1,19 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"bins": 1024,
|
3 |
+
"unstable_bins": 0,
|
4 |
+
"reduction_bins": 0,
|
5 |
+
"band": {
|
6 |
+
"1": {
|
7 |
+
"sr": 44100,
|
8 |
+
"hl": 1024,
|
9 |
+
"n_fft": 2048,
|
10 |
+
"crop_start": 0,
|
11 |
+
"crop_stop": 1024,
|
12 |
+
"hpf_start": -1,
|
13 |
+
"res_type": "sinc_best"
|
14 |
+
}
|
15 |
+
},
|
16 |
+
"sr": 44100,
|
17 |
+
"pre_filter_start": 1023,
|
18 |
+
"pre_filter_stop": 1024
|
19 |
+
}
|
lib_v5/vr_network/modelparams/1band_sr44100_hl256.json
ADDED
@@ -0,0 +1,19 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"bins": 256,
|
3 |
+
"unstable_bins": 0,
|
4 |
+
"reduction_bins": 0,
|
5 |
+
"band": {
|
6 |
+
"1": {
|
7 |
+
"sr": 44100,
|
8 |
+
"hl": 256,
|
9 |
+
"n_fft": 512,
|
10 |
+
"crop_start": 0,
|
11 |
+
"crop_stop": 256,
|
12 |
+
"hpf_start": -1,
|
13 |
+
"res_type": "sinc_best"
|
14 |
+
}
|
15 |
+
},
|
16 |
+
"sr": 44100,
|
17 |
+
"pre_filter_start": 256,
|
18 |
+
"pre_filter_stop": 256
|
19 |
+
}
|
lib_v5/vr_network/modelparams/1band_sr44100_hl512.json
ADDED
@@ -0,0 +1,19 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"bins": 1024,
|
3 |
+
"unstable_bins": 0,
|
4 |
+
"reduction_bins": 0,
|
5 |
+
"band": {
|
6 |
+
"1": {
|
7 |
+
"sr": 44100,
|
8 |
+
"hl": 512,
|
9 |
+
"n_fft": 2048,
|
10 |
+
"crop_start": 0,
|
11 |
+
"crop_stop": 1024,
|
12 |
+
"hpf_start": -1,
|
13 |
+
"res_type": "sinc_best"
|
14 |
+
}
|
15 |
+
},
|
16 |
+
"sr": 44100,
|
17 |
+
"pre_filter_start": 1023,
|
18 |
+
"pre_filter_stop": 1024
|
19 |
+
}
|
lib_v5/vr_network/modelparams/1band_sr44100_hl512_cut.json
ADDED
@@ -0,0 +1,19 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"bins": 1024,
|
3 |
+
"unstable_bins": 0,
|
4 |
+
"reduction_bins": 0,
|
5 |
+
"band": {
|
6 |
+
"1": {
|
7 |
+
"sr": 44100,
|
8 |
+
"hl": 512,
|
9 |
+
"n_fft": 2048,
|
10 |
+
"crop_start": 0,
|
11 |
+
"crop_stop": 700,
|
12 |
+
"hpf_start": -1,
|
13 |
+
"res_type": "sinc_best"
|
14 |
+
}
|
15 |
+
},
|
16 |
+
"sr": 44100,
|
17 |
+
"pre_filter_start": 1023,
|
18 |
+
"pre_filter_stop": 700
|
19 |
+
}
|
lib_v5/vr_network/modelparams/1band_sr44100_hl512_nf1024.json
ADDED
@@ -0,0 +1,19 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"bins": 512,
|
3 |
+
"unstable_bins": 0,
|
4 |
+
"reduction_bins": 0,
|
5 |
+
"band": {
|
6 |
+
"1": {
|
7 |
+
"sr": 44100,
|
8 |
+
"hl": 512,
|
9 |
+
"n_fft": 1024,
|
10 |
+
"crop_start": 0,
|
11 |
+
"crop_stop": 512,
|
12 |
+
"hpf_start": -1,
|
13 |
+
"res_type": "sinc_best"
|
14 |
+
}
|
15 |
+
},
|
16 |
+
"sr": 44100,
|
17 |
+
"pre_filter_start": 511,
|
18 |
+
"pre_filter_stop": 512
|
19 |
+
}
|
lib_v5/vr_network/modelparams/2band_32000.json
ADDED
@@ -0,0 +1,30 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"bins": 768,
|
3 |
+
"unstable_bins": 7,
|
4 |
+
"reduction_bins": 705,
|
5 |
+
"band": {
|
6 |
+
"1": {
|
7 |
+
"sr": 6000,
|
8 |
+
"hl": 66,
|
9 |
+
"n_fft": 512,
|
10 |
+
"crop_start": 0,
|
11 |
+
"crop_stop": 240,
|
12 |
+
"lpf_start": 60,
|
13 |
+
"lpf_stop": 118,
|
14 |
+
"res_type": "sinc_fastest"
|
15 |
+
},
|
16 |
+
"2": {
|
17 |
+
"sr": 32000,
|
18 |
+
"hl": 352,
|
19 |
+
"n_fft": 1024,
|
20 |
+
"crop_start": 22,
|
21 |
+
"crop_stop": 505,
|
22 |
+
"hpf_start": 44,
|
23 |
+
"hpf_stop": 23,
|
24 |
+
"res_type": "sinc_medium"
|
25 |
+
}
|
26 |
+
},
|
27 |
+
"sr": 32000,
|
28 |
+
"pre_filter_start": 710,
|
29 |
+
"pre_filter_stop": 731
|
30 |
+
}
|
lib_v5/vr_network/modelparams/2band_44100_lofi.json
ADDED
@@ -0,0 +1,30 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"bins": 512,
|
3 |
+
"unstable_bins": 7,
|
4 |
+
"reduction_bins": 510,
|
5 |
+
"band": {
|
6 |
+
"1": {
|
7 |
+
"sr": 11025,
|
8 |
+
"hl": 160,
|
9 |
+
"n_fft": 768,
|
10 |
+
"crop_start": 0,
|
11 |
+
"crop_stop": 192,
|
12 |
+
"lpf_start": 41,
|
13 |
+
"lpf_stop": 139,
|
14 |
+
"res_type": "sinc_fastest"
|
15 |
+
},
|
16 |
+
"2": {
|
17 |
+
"sr": 44100,
|
18 |
+
"hl": 640,
|
19 |
+
"n_fft": 1024,
|
20 |
+
"crop_start": 10,
|
21 |
+
"crop_stop": 320,
|
22 |
+
"hpf_start": 47,
|
23 |
+
"hpf_stop": 15,
|
24 |
+
"res_type": "sinc_medium"
|
25 |
+
}
|
26 |
+
},
|
27 |
+
"sr": 44100,
|
28 |
+
"pre_filter_start": 510,
|
29 |
+
"pre_filter_stop": 512
|
30 |
+
}
|
lib_v5/vr_network/modelparams/2band_48000.json
ADDED
@@ -0,0 +1,30 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"bins": 768,
|
3 |
+
"unstable_bins": 7,
|
4 |
+
"reduction_bins": 705,
|
5 |
+
"band": {
|
6 |
+
"1": {
|
7 |
+
"sr": 6000,
|
8 |
+
"hl": 66,
|
9 |
+
"n_fft": 512,
|
10 |
+
"crop_start": 0,
|
11 |
+
"crop_stop": 240,
|
12 |
+
"lpf_start": 60,
|
13 |
+
"lpf_stop": 240,
|
14 |
+
"res_type": "sinc_fastest"
|
15 |
+
},
|
16 |
+
"2": {
|
17 |
+
"sr": 48000,
|
18 |
+
"hl": 528,
|
19 |
+
"n_fft": 1536,
|
20 |
+
"crop_start": 22,
|
21 |
+
"crop_stop": 505,
|
22 |
+
"hpf_start": 82,
|
23 |
+
"hpf_stop": 22,
|
24 |
+
"res_type": "sinc_medium"
|
25 |
+
}
|
26 |
+
},
|
27 |
+
"sr": 48000,
|
28 |
+
"pre_filter_start": 710,
|
29 |
+
"pre_filter_stop": 731
|
30 |
+
}
|
lib_v5/vr_network/modelparams/3band_44100.json
ADDED
@@ -0,0 +1,42 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"bins": 768,
|
3 |
+
"unstable_bins": 5,
|
4 |
+
"reduction_bins": 733,
|
5 |
+
"band": {
|
6 |
+
"1": {
|
7 |
+
"sr": 11025,
|
8 |
+
"hl": 128,
|
9 |
+
"n_fft": 768,
|
10 |
+
"crop_start": 0,
|
11 |
+
"crop_stop": 278,
|
12 |
+
"lpf_start": 28,
|
13 |
+
"lpf_stop": 140,
|
14 |
+
"res_type": "polyphase"
|
15 |
+
},
|
16 |
+
"2": {
|
17 |
+
"sr": 22050,
|
18 |
+
"hl": 256,
|
19 |
+
"n_fft": 768,
|
20 |
+
"crop_start": 14,
|
21 |
+
"crop_stop": 322,
|
22 |
+
"hpf_start": 70,
|
23 |
+
"hpf_stop": 14,
|
24 |
+
"lpf_start": 283,
|
25 |
+
"lpf_stop": 314,
|
26 |
+
"res_type": "polyphase"
|
27 |
+
},
|
28 |
+
"3": {
|
29 |
+
"sr": 44100,
|
30 |
+
"hl": 512,
|
31 |
+
"n_fft": 768,
|
32 |
+
"crop_start": 131,
|
33 |
+
"crop_stop": 313,
|
34 |
+
"hpf_start": 154,
|
35 |
+
"hpf_stop": 141,
|
36 |
+
"res_type": "sinc_medium"
|
37 |
+
}
|
38 |
+
},
|
39 |
+
"sr": 44100,
|
40 |
+
"pre_filter_start": 757,
|
41 |
+
"pre_filter_stop": 768
|
42 |
+
}
|
lib_v5/vr_network/modelparams/3band_44100_mid.json
ADDED
@@ -0,0 +1,43 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"mid_side": true,
|
3 |
+
"bins": 768,
|
4 |
+
"unstable_bins": 5,
|
5 |
+
"reduction_bins": 733,
|
6 |
+
"band": {
|
7 |
+
"1": {
|
8 |
+
"sr": 11025,
|
9 |
+
"hl": 128,
|
10 |
+
"n_fft": 768,
|
11 |
+
"crop_start": 0,
|
12 |
+
"crop_stop": 278,
|
13 |
+
"lpf_start": 28,
|
14 |
+
"lpf_stop": 140,
|
15 |
+
"res_type": "polyphase"
|
16 |
+
},
|
17 |
+
"2": {
|
18 |
+
"sr": 22050,
|
19 |
+
"hl": 256,
|
20 |
+
"n_fft": 768,
|
21 |
+
"crop_start": 14,
|
22 |
+
"crop_stop": 322,
|
23 |
+
"hpf_start": 70,
|
24 |
+
"hpf_stop": 14,
|
25 |
+
"lpf_start": 283,
|
26 |
+
"lpf_stop": 314,
|
27 |
+
"res_type": "polyphase"
|
28 |
+
},
|
29 |
+
"3": {
|
30 |
+
"sr": 44100,
|
31 |
+
"hl": 512,
|
32 |
+
"n_fft": 768,
|
33 |
+
"crop_start": 131,
|
34 |
+
"crop_stop": 313,
|
35 |
+
"hpf_start": 154,
|
36 |
+
"hpf_stop": 141,
|
37 |
+
"res_type": "sinc_medium"
|
38 |
+
}
|
39 |
+
},
|
40 |
+
"sr": 44100,
|
41 |
+
"pre_filter_start": 757,
|
42 |
+
"pre_filter_stop": 768
|
43 |
+
}
|
lib_v5/vr_network/modelparams/3band_44100_msb2.json
ADDED
@@ -0,0 +1,43 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"mid_side_b2": true,
|
3 |
+
"bins": 640,
|
4 |
+
"unstable_bins": 7,
|
5 |
+
"reduction_bins": 565,
|
6 |
+
"band": {
|
7 |
+
"1": {
|
8 |
+
"sr": 11025,
|
9 |
+
"hl": 108,
|
10 |
+
"n_fft": 1024,
|
11 |
+
"crop_start": 0,
|
12 |
+
"crop_stop": 187,
|
13 |
+
"lpf_start": 92,
|
14 |
+
"lpf_stop": 186,
|
15 |
+
"res_type": "polyphase"
|
16 |
+
},
|
17 |
+
"2": {
|
18 |
+
"sr": 22050,
|
19 |
+
"hl": 216,
|
20 |
+
"n_fft": 768,
|
21 |
+
"crop_start": 0,
|
22 |
+
"crop_stop": 212,
|
23 |
+
"hpf_start": 68,
|
24 |
+
"hpf_stop": 34,
|
25 |
+
"lpf_start": 174,
|
26 |
+
"lpf_stop": 209,
|
27 |
+
"res_type": "polyphase"
|
28 |
+
},
|
29 |
+
"3": {
|
30 |
+
"sr": 44100,
|
31 |
+
"hl": 432,
|
32 |
+
"n_fft": 640,
|
33 |
+
"crop_start": 66,
|
34 |
+
"crop_stop": 307,
|
35 |
+
"hpf_start": 86,
|
36 |
+
"hpf_stop": 72,
|
37 |
+
"res_type": "kaiser_fast"
|
38 |
+
}
|
39 |
+
},
|
40 |
+
"sr": 44100,
|
41 |
+
"pre_filter_start": 639,
|
42 |
+
"pre_filter_stop": 640
|
43 |
+
}
|
lib_v5/vr_network/modelparams/4band_44100.json
ADDED
@@ -0,0 +1,54 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"bins": 768,
|
3 |
+
"unstable_bins": 7,
|
4 |
+
"reduction_bins": 668,
|
5 |
+
"band": {
|
6 |
+
"1": {
|
7 |
+
"sr": 11025,
|
8 |
+
"hl": 128,
|
9 |
+
"n_fft": 1024,
|
10 |
+
"crop_start": 0,
|
11 |
+
"crop_stop": 186,
|
12 |
+
"lpf_start": 37,
|
13 |
+
"lpf_stop": 73,
|
14 |
+
"res_type": "polyphase"
|
15 |
+
},
|
16 |
+
"2": {
|
17 |
+
"sr": 11025,
|
18 |
+
"hl": 128,
|
19 |
+
"n_fft": 512,
|
20 |
+
"crop_start": 4,
|
21 |
+
"crop_stop": 185,
|
22 |
+
"hpf_start": 36,
|
23 |
+
"hpf_stop": 18,
|
24 |
+
"lpf_start": 93,
|
25 |
+
"lpf_stop": 185,
|
26 |
+
"res_type": "polyphase"
|
27 |
+
},
|
28 |
+
"3": {
|
29 |
+
"sr": 22050,
|
30 |
+
"hl": 256,
|
31 |
+
"n_fft": 512,
|
32 |
+
"crop_start": 46,
|
33 |
+
"crop_stop": 186,
|
34 |
+
"hpf_start": 93,
|
35 |
+
"hpf_stop": 46,
|
36 |
+
"lpf_start": 164,
|
37 |
+
"lpf_stop": 186,
|
38 |
+
"res_type": "polyphase"
|
39 |
+
},
|
40 |
+
"4": {
|
41 |
+
"sr": 44100,
|
42 |
+
"hl": 512,
|
43 |
+
"n_fft": 768,
|
44 |
+
"crop_start": 121,
|
45 |
+
"crop_stop": 382,
|
46 |
+
"hpf_start": 138,
|
47 |
+
"hpf_stop": 123,
|
48 |
+
"res_type": "sinc_medium"
|
49 |
+
}
|
50 |
+
},
|
51 |
+
"sr": 44100,
|
52 |
+
"pre_filter_start": 740,
|
53 |
+
"pre_filter_stop": 768
|
54 |
+
}
|
lib_v5/vr_network/modelparams/4band_44100_mid.json
ADDED
@@ -0,0 +1,55 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"bins": 768,
|
3 |
+
"unstable_bins": 7,
|
4 |
+
"mid_side": true,
|
5 |
+
"reduction_bins": 668,
|
6 |
+
"band": {
|
7 |
+
"1": {
|
8 |
+
"sr": 11025,
|
9 |
+
"hl": 128,
|
10 |
+
"n_fft": 1024,
|
11 |
+
"crop_start": 0,
|
12 |
+
"crop_stop": 186,
|
13 |
+
"lpf_start": 37,
|
14 |
+
"lpf_stop": 73,
|
15 |
+
"res_type": "polyphase"
|
16 |
+
},
|
17 |
+
"2": {
|
18 |
+
"sr": 11025,
|
19 |
+
"hl": 128,
|
20 |
+
"n_fft": 512,
|
21 |
+
"crop_start": 4,
|
22 |
+
"crop_stop": 185,
|
23 |
+
"hpf_start": 36,
|
24 |
+
"hpf_stop": 18,
|
25 |
+
"lpf_start": 93,
|
26 |
+
"lpf_stop": 185,
|
27 |
+
"res_type": "polyphase"
|
28 |
+
},
|
29 |
+
"3": {
|
30 |
+
"sr": 22050,
|
31 |
+
"hl": 256,
|
32 |
+
"n_fft": 512,
|
33 |
+
"crop_start": 46,
|
34 |
+
"crop_stop": 186,
|
35 |
+
"hpf_start": 93,
|
36 |
+
"hpf_stop": 46,
|
37 |
+
"lpf_start": 164,
|
38 |
+
"lpf_stop": 186,
|
39 |
+
"res_type": "polyphase"
|
40 |
+
},
|
41 |
+
"4": {
|
42 |
+
"sr": 44100,
|
43 |
+
"hl": 512,
|
44 |
+
"n_fft": 768,
|
45 |
+
"crop_start": 121,
|
46 |
+
"crop_stop": 382,
|
47 |
+
"hpf_start": 138,
|
48 |
+
"hpf_stop": 123,
|
49 |
+
"res_type": "sinc_medium"
|
50 |
+
}
|
51 |
+
},
|
52 |
+
"sr": 44100,
|
53 |
+
"pre_filter_start": 740,
|
54 |
+
"pre_filter_stop": 768
|
55 |
+
}
|
lib_v5/vr_network/modelparams/4band_44100_msb.json
ADDED
@@ -0,0 +1,55 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"mid_side_b": true,
|
3 |
+
"bins": 768,
|
4 |
+
"unstable_bins": 7,
|
5 |
+
"reduction_bins": 668,
|
6 |
+
"band": {
|
7 |
+
"1": {
|
8 |
+
"sr": 11025,
|
9 |
+
"hl": 128,
|
10 |
+
"n_fft": 1024,
|
11 |
+
"crop_start": 0,
|
12 |
+
"crop_stop": 186,
|
13 |
+
"lpf_start": 37,
|
14 |
+
"lpf_stop": 73,
|
15 |
+
"res_type": "polyphase"
|
16 |
+
},
|
17 |
+
"2": {
|
18 |
+
"sr": 11025,
|
19 |
+
"hl": 128,
|
20 |
+
"n_fft": 512,
|
21 |
+
"crop_start": 4,
|
22 |
+
"crop_stop": 185,
|
23 |
+
"hpf_start": 36,
|
24 |
+
"hpf_stop": 18,
|
25 |
+
"lpf_start": 93,
|
26 |
+
"lpf_stop": 185,
|
27 |
+
"res_type": "polyphase"
|
28 |
+
},
|
29 |
+
"3": {
|
30 |
+
"sr": 22050,
|
31 |
+
"hl": 256,
|
32 |
+
"n_fft": 512,
|
33 |
+
"crop_start": 46,
|
34 |
+
"crop_stop": 186,
|
35 |
+
"hpf_start": 93,
|
36 |
+
"hpf_stop": 46,
|
37 |
+
"lpf_start": 164,
|
38 |
+
"lpf_stop": 186,
|
39 |
+
"res_type": "polyphase"
|
40 |
+
},
|
41 |
+
"4": {
|
42 |
+
"sr": 44100,
|
43 |
+
"hl": 512,
|
44 |
+
"n_fft": 768,
|
45 |
+
"crop_start": 121,
|
46 |
+
"crop_stop": 382,
|
47 |
+
"hpf_start": 138,
|
48 |
+
"hpf_stop": 123,
|
49 |
+
"res_type": "sinc_medium"
|
50 |
+
}
|
51 |
+
},
|
52 |
+
"sr": 44100,
|
53 |
+
"pre_filter_start": 740,
|
54 |
+
"pre_filter_stop": 768
|
55 |
+
}
|
lib_v5/vr_network/modelparams/4band_44100_msb2.json
ADDED
@@ -0,0 +1,55 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"mid_side_b": true,
|
3 |
+
"bins": 768,
|
4 |
+
"unstable_bins": 7,
|
5 |
+
"reduction_bins": 668,
|
6 |
+
"band": {
|
7 |
+
"1": {
|
8 |
+
"sr": 11025,
|
9 |
+
"hl": 128,
|
10 |
+
"n_fft": 1024,
|
11 |
+
"crop_start": 0,
|
12 |
+
"crop_stop": 186,
|
13 |
+
"lpf_start": 37,
|
14 |
+
"lpf_stop": 73,
|
15 |
+
"res_type": "polyphase"
|
16 |
+
},
|
17 |
+
"2": {
|
18 |
+
"sr": 11025,
|
19 |
+
"hl": 128,
|
20 |
+
"n_fft": 512,
|
21 |
+
"crop_start": 4,
|
22 |
+
"crop_stop": 185,
|
23 |
+
"hpf_start": 36,
|
24 |
+
"hpf_stop": 18,
|
25 |
+
"lpf_start": 93,
|
26 |
+
"lpf_stop": 185,
|
27 |
+
"res_type": "polyphase"
|
28 |
+
},
|
29 |
+
"3": {
|
30 |
+
"sr": 22050,
|
31 |
+
"hl": 256,
|
32 |
+
"n_fft": 512,
|
33 |
+
"crop_start": 46,
|
34 |
+
"crop_stop": 186,
|
35 |
+
"hpf_start": 93,
|
36 |
+
"hpf_stop": 46,
|
37 |
+
"lpf_start": 164,
|
38 |
+
"lpf_stop": 186,
|
39 |
+
"res_type": "polyphase"
|
40 |
+
},
|
41 |
+
"4": {
|
42 |
+
"sr": 44100,
|
43 |
+
"hl": 512,
|
44 |
+
"n_fft": 768,
|
45 |
+
"crop_start": 121,
|
46 |
+
"crop_stop": 382,
|
47 |
+
"hpf_start": 138,
|
48 |
+
"hpf_stop": 123,
|
49 |
+
"res_type": "sinc_medium"
|
50 |
+
}
|
51 |
+
},
|
52 |
+
"sr": 44100,
|
53 |
+
"pre_filter_start": 740,
|
54 |
+
"pre_filter_stop": 768
|
55 |
+
}
|
lib_v5/vr_network/modelparams/4band_44100_reverse.json
ADDED
@@ -0,0 +1,55 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"reverse": true,
|
3 |
+
"bins": 768,
|
4 |
+
"unstable_bins": 7,
|
5 |
+
"reduction_bins": 668,
|
6 |
+
"band": {
|
7 |
+
"1": {
|
8 |
+
"sr": 11025,
|
9 |
+
"hl": 128,
|
10 |
+
"n_fft": 1024,
|
11 |
+
"crop_start": 0,
|
12 |
+
"crop_stop": 186,
|
13 |
+
"lpf_start": 37,
|
14 |
+
"lpf_stop": 73,
|
15 |
+
"res_type": "polyphase"
|
16 |
+
},
|
17 |
+
"2": {
|
18 |
+
"sr": 11025,
|
19 |
+
"hl": 128,
|
20 |
+
"n_fft": 512,
|
21 |
+
"crop_start": 4,
|
22 |
+
"crop_stop": 185,
|
23 |
+
"hpf_start": 36,
|
24 |
+
"hpf_stop": 18,
|
25 |
+
"lpf_start": 93,
|
26 |
+
"lpf_stop": 185,
|
27 |
+
"res_type": "polyphase"
|
28 |
+
},
|
29 |
+
"3": {
|
30 |
+
"sr": 22050,
|
31 |
+
"hl": 256,
|
32 |
+
"n_fft": 512,
|
33 |
+
"crop_start": 46,
|
34 |
+
"crop_stop": 186,
|
35 |
+
"hpf_start": 93,
|
36 |
+
"hpf_stop": 46,
|
37 |
+
"lpf_start": 164,
|
38 |
+
"lpf_stop": 186,
|
39 |
+
"res_type": "polyphase"
|
40 |
+
},
|
41 |
+
"4": {
|
42 |
+
"sr": 44100,
|
43 |
+
"hl": 512,
|
44 |
+
"n_fft": 768,
|
45 |
+
"crop_start": 121,
|
46 |
+
"crop_stop": 382,
|
47 |
+
"hpf_start": 138,
|
48 |
+
"hpf_stop": 123,
|
49 |
+
"res_type": "sinc_medium"
|
50 |
+
}
|
51 |
+
},
|
52 |
+
"sr": 44100,
|
53 |
+
"pre_filter_start": 740,
|
54 |
+
"pre_filter_stop": 768
|
55 |
+
}
|
lib_v5/vr_network/modelparams/4band_44100_sw.json
ADDED
@@ -0,0 +1,55 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"stereo_w": true,
|
3 |
+
"bins": 768,
|
4 |
+
"unstable_bins": 7,
|
5 |
+
"reduction_bins": 668,
|
6 |
+
"band": {
|
7 |
+
"1": {
|
8 |
+
"sr": 11025,
|
9 |
+
"hl": 128,
|
10 |
+
"n_fft": 1024,
|
11 |
+
"crop_start": 0,
|
12 |
+
"crop_stop": 186,
|
13 |
+
"lpf_start": 37,
|
14 |
+
"lpf_stop": 73,
|
15 |
+
"res_type": "polyphase"
|
16 |
+
},
|
17 |
+
"2": {
|
18 |
+
"sr": 11025,
|
19 |
+
"hl": 128,
|
20 |
+
"n_fft": 512,
|
21 |
+
"crop_start": 4,
|
22 |
+
"crop_stop": 185,
|
23 |
+
"hpf_start": 36,
|
24 |
+
"hpf_stop": 18,
|
25 |
+
"lpf_start": 93,
|
26 |
+
"lpf_stop": 185,
|
27 |
+
"res_type": "polyphase"
|
28 |
+
},
|
29 |
+
"3": {
|
30 |
+
"sr": 22050,
|
31 |
+
"hl": 256,
|
32 |
+
"n_fft": 512,
|
33 |
+
"crop_start": 46,
|
34 |
+
"crop_stop": 186,
|
35 |
+
"hpf_start": 93,
|
36 |
+
"hpf_stop": 46,
|
37 |
+
"lpf_start": 164,
|
38 |
+
"lpf_stop": 186,
|
39 |
+
"res_type": "polyphase"
|
40 |
+
},
|
41 |
+
"4": {
|
42 |
+
"sr": 44100,
|
43 |
+
"hl": 512,
|
44 |
+
"n_fft": 768,
|
45 |
+
"crop_start": 121,
|
46 |
+
"crop_stop": 382,
|
47 |
+
"hpf_start": 138,
|
48 |
+
"hpf_stop": 123,
|
49 |
+
"res_type": "sinc_medium"
|
50 |
+
}
|
51 |
+
},
|
52 |
+
"sr": 44100,
|
53 |
+
"pre_filter_start": 740,
|
54 |
+
"pre_filter_stop": 768
|
55 |
+
}
|
lib_v5/vr_network/modelparams/4band_v2.json
ADDED
@@ -0,0 +1,54 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"bins": 672,
|
3 |
+
"unstable_bins": 8,
|
4 |
+
"reduction_bins": 637,
|
5 |
+
"band": {
|
6 |
+
"1": {
|
7 |
+
"sr": 7350,
|
8 |
+
"hl": 80,
|
9 |
+
"n_fft": 640,
|
10 |
+
"crop_start": 0,
|
11 |
+
"crop_stop": 85,
|
12 |
+
"lpf_start": 25,
|
13 |
+
"lpf_stop": 53,
|
14 |
+
"res_type": "polyphase"
|
15 |
+
},
|
16 |
+
"2": {
|
17 |
+
"sr": 7350,
|
18 |
+
"hl": 80,
|
19 |
+
"n_fft": 320,
|
20 |
+
"crop_start": 4,
|
21 |
+
"crop_stop": 87,
|
22 |
+
"hpf_start": 25,
|
23 |
+
"hpf_stop": 12,
|
24 |
+
"lpf_start": 31,
|
25 |
+
"lpf_stop": 62,
|
26 |
+
"res_type": "polyphase"
|
27 |
+
},
|
28 |
+
"3": {
|
29 |
+
"sr": 14700,
|
30 |
+
"hl": 160,
|
31 |
+
"n_fft": 512,
|
32 |
+
"crop_start": 17,
|
33 |
+
"crop_stop": 216,
|
34 |
+
"hpf_start": 48,
|
35 |
+
"hpf_stop": 24,
|
36 |
+
"lpf_start": 139,
|
37 |
+
"lpf_stop": 210,
|
38 |
+
"res_type": "polyphase"
|
39 |
+
},
|
40 |
+
"4": {
|
41 |
+
"sr": 44100,
|
42 |
+
"hl": 480,
|
43 |
+
"n_fft": 960,
|
44 |
+
"crop_start": 78,
|
45 |
+
"crop_stop": 383,
|
46 |
+
"hpf_start": 130,
|
47 |
+
"hpf_stop": 86,
|
48 |
+
"res_type": "kaiser_fast"
|
49 |
+
}
|
50 |
+
},
|
51 |
+
"sr": 44100,
|
52 |
+
"pre_filter_start": 668,
|
53 |
+
"pre_filter_stop": 672
|
54 |
+
}
|
lib_v5/vr_network/modelparams/4band_v2_sn.json
ADDED
@@ -0,0 +1,55 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"bins": 672,
|
3 |
+
"unstable_bins": 8,
|
4 |
+
"reduction_bins": 637,
|
5 |
+
"band": {
|
6 |
+
"1": {
|
7 |
+
"sr": 7350,
|
8 |
+
"hl": 80,
|
9 |
+
"n_fft": 640,
|
10 |
+
"crop_start": 0,
|
11 |
+
"crop_stop": 85,
|
12 |
+
"lpf_start": 25,
|
13 |
+
"lpf_stop": 53,
|
14 |
+
"res_type": "polyphase"
|
15 |
+
},
|
16 |
+
"2": {
|
17 |
+
"sr": 7350,
|
18 |
+
"hl": 80,
|
19 |
+
"n_fft": 320,
|
20 |
+
"crop_start": 4,
|
21 |
+
"crop_stop": 87,
|
22 |
+
"hpf_start": 25,
|
23 |
+
"hpf_stop": 12,
|
24 |
+
"lpf_start": 31,
|
25 |
+
"lpf_stop": 62,
|
26 |
+
"res_type": "polyphase"
|
27 |
+
},
|
28 |
+
"3": {
|
29 |
+
"sr": 14700,
|
30 |
+
"hl": 160,
|
31 |
+
"n_fft": 512,
|
32 |
+
"crop_start": 17,
|
33 |
+
"crop_stop": 216,
|
34 |
+
"hpf_start": 48,
|
35 |
+
"hpf_stop": 24,
|
36 |
+
"lpf_start": 139,
|
37 |
+
"lpf_stop": 210,
|
38 |
+
"res_type": "polyphase"
|
39 |
+
},
|
40 |
+
"4": {
|
41 |
+
"sr": 44100,
|
42 |
+
"hl": 480,
|
43 |
+
"n_fft": 960,
|
44 |
+
"crop_start": 78,
|
45 |
+
"crop_stop": 383,
|
46 |
+
"hpf_start": 130,
|
47 |
+
"hpf_stop": 86,
|
48 |
+
"convert_channels": "stereo_n",
|
49 |
+
"res_type": "kaiser_fast"
|
50 |
+
}
|
51 |
+
},
|
52 |
+
"sr": 44100,
|
53 |
+
"pre_filter_start": 668,
|
54 |
+
"pre_filter_stop": 672
|
55 |
+
}
|
lib_v5/vr_network/modelparams/4band_v3.json
ADDED
@@ -0,0 +1,54 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"bins": 672,
|
3 |
+
"unstable_bins": 8,
|
4 |
+
"reduction_bins": 530,
|
5 |
+
"band": {
|
6 |
+
"1": {
|
7 |
+
"sr": 7350,
|
8 |
+
"hl": 80,
|
9 |
+
"n_fft": 640,
|
10 |
+
"crop_start": 0,
|
11 |
+
"crop_stop": 85,
|
12 |
+
"lpf_start": 25,
|
13 |
+
"lpf_stop": 53,
|
14 |
+
"res_type": "polyphase"
|
15 |
+
},
|
16 |
+
"2": {
|
17 |
+
"sr": 7350,
|
18 |
+
"hl": 80,
|
19 |
+
"n_fft": 320,
|
20 |
+
"crop_start": 4,
|
21 |
+
"crop_stop": 87,
|
22 |
+
"hpf_start": 25,
|
23 |
+
"hpf_stop": 12,
|
24 |
+
"lpf_start": 31,
|
25 |
+
"lpf_stop": 62,
|
26 |
+
"res_type": "polyphase"
|
27 |
+
},
|
28 |
+
"3": {
|
29 |
+
"sr": 14700,
|
30 |
+
"hl": 160,
|
31 |
+
"n_fft": 512,
|
32 |
+
"crop_start": 17,
|
33 |
+
"crop_stop": 216,
|
34 |
+
"hpf_start": 48,
|
35 |
+
"hpf_stop": 24,
|
36 |
+
"lpf_start": 139,
|
37 |
+
"lpf_stop": 210,
|
38 |
+
"res_type": "polyphase"
|
39 |
+
},
|
40 |
+
"4": {
|
41 |
+
"sr": 44100,
|
42 |
+
"hl": 480,
|
43 |
+
"n_fft": 960,
|
44 |
+
"crop_start": 78,
|
45 |
+
"crop_stop": 383,
|
46 |
+
"hpf_start": 130,
|
47 |
+
"hpf_stop": 86,
|
48 |
+
"res_type": "kaiser_fast"
|
49 |
+
}
|
50 |
+
},
|
51 |
+
"sr": 44100,
|
52 |
+
"pre_filter_start": 668,
|
53 |
+
"pre_filter_stop": 672
|
54 |
+
}
|
lib_v5/vr_network/modelparams/ensemble.json
ADDED
@@ -0,0 +1,43 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"mid_side_b2": true,
|
3 |
+
"bins": 1280,
|
4 |
+
"unstable_bins": 7,
|
5 |
+
"reduction_bins": 565,
|
6 |
+
"band": {
|
7 |
+
"1": {
|
8 |
+
"sr": 11025,
|
9 |
+
"hl": 108,
|
10 |
+
"n_fft": 2048,
|
11 |
+
"crop_start": 0,
|
12 |
+
"crop_stop": 374,
|
13 |
+
"lpf_start": 92,
|
14 |
+
"lpf_stop": 186,
|
15 |
+
"res_type": "polyphase"
|
16 |
+
},
|
17 |
+
"2": {
|
18 |
+
"sr": 22050,
|
19 |
+
"hl": 216,
|
20 |
+
"n_fft": 1536,
|
21 |
+
"crop_start": 0,
|
22 |
+
"crop_stop": 424,
|
23 |
+
"hpf_start": 68,
|
24 |
+
"hpf_stop": 34,
|
25 |
+
"lpf_start": 348,
|
26 |
+
"lpf_stop": 418,
|
27 |
+
"res_type": "polyphase"
|
28 |
+
},
|
29 |
+
"3": {
|
30 |
+
"sr": 44100,
|
31 |
+
"hl": 432,
|
32 |
+
"n_fft": 1280,
|
33 |
+
"crop_start": 132,
|
34 |
+
"crop_stop": 614,
|
35 |
+
"hpf_start": 172,
|
36 |
+
"hpf_stop": 144,
|
37 |
+
"res_type": "polyphase"
|
38 |
+
}
|
39 |
+
},
|
40 |
+
"sr": 44100,
|
41 |
+
"pre_filter_start": 1280,
|
42 |
+
"pre_filter_stop": 1280
|
43 |
+
}
|
lib_v5/vr_network/nets.py
ADDED
@@ -0,0 +1,166 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import torch
|
2 |
+
from torch import nn
|
3 |
+
import torch.nn.functional as F
|
4 |
+
|
5 |
+
from . import layers
|
6 |
+
|
7 |
+
class BaseASPPNet(nn.Module):
|
8 |
+
|
9 |
+
def __init__(self, nn_architecture, nin, ch, dilations=(4, 8, 16)):
|
10 |
+
super(BaseASPPNet, self).__init__()
|
11 |
+
self.nn_architecture = nn_architecture
|
12 |
+
self.enc1 = layers.Encoder(nin, ch, 3, 2, 1)
|
13 |
+
self.enc2 = layers.Encoder(ch, ch * 2, 3, 2, 1)
|
14 |
+
self.enc3 = layers.Encoder(ch * 2, ch * 4, 3, 2, 1)
|
15 |
+
self.enc4 = layers.Encoder(ch * 4, ch * 8, 3, 2, 1)
|
16 |
+
|
17 |
+
if self.nn_architecture == 129605:
|
18 |
+
self.enc5 = layers.Encoder(ch * 8, ch * 16, 3, 2, 1)
|
19 |
+
self.aspp = layers.ASPPModule(nn_architecture, ch * 16, ch * 32, dilations)
|
20 |
+
self.dec5 = layers.Decoder(ch * (16 + 32), ch * 16, 3, 1, 1)
|
21 |
+
else:
|
22 |
+
self.aspp = layers.ASPPModule(nn_architecture, ch * 8, ch * 16, dilations)
|
23 |
+
|
24 |
+
self.dec4 = layers.Decoder(ch * (8 + 16), ch * 8, 3, 1, 1)
|
25 |
+
self.dec3 = layers.Decoder(ch * (4 + 8), ch * 4, 3, 1, 1)
|
26 |
+
self.dec2 = layers.Decoder(ch * (2 + 4), ch * 2, 3, 1, 1)
|
27 |
+
self.dec1 = layers.Decoder(ch * (1 + 2), ch, 3, 1, 1)
|
28 |
+
|
29 |
+
def __call__(self, x):
|
30 |
+
h, e1 = self.enc1(x)
|
31 |
+
h, e2 = self.enc2(h)
|
32 |
+
h, e3 = self.enc3(h)
|
33 |
+
h, e4 = self.enc4(h)
|
34 |
+
|
35 |
+
if self.nn_architecture == 129605:
|
36 |
+
h, e5 = self.enc5(h)
|
37 |
+
h = self.aspp(h)
|
38 |
+
h = self.dec5(h, e5)
|
39 |
+
else:
|
40 |
+
h = self.aspp(h)
|
41 |
+
|
42 |
+
h = self.dec4(h, e4)
|
43 |
+
h = self.dec3(h, e3)
|
44 |
+
h = self.dec2(h, e2)
|
45 |
+
h = self.dec1(h, e1)
|
46 |
+
|
47 |
+
return h
|
48 |
+
|
49 |
+
def determine_model_capacity(n_fft_bins, nn_architecture):
|
50 |
+
|
51 |
+
sp_model_arch = [31191, 33966, 129605]
|
52 |
+
hp_model_arch = [123821, 123812]
|
53 |
+
hp2_model_arch = [537238, 537227]
|
54 |
+
|
55 |
+
if nn_architecture in sp_model_arch:
|
56 |
+
model_capacity_data = [
|
57 |
+
(2, 16),
|
58 |
+
(2, 16),
|
59 |
+
(18, 8, 1, 1, 0),
|
60 |
+
(8, 16),
|
61 |
+
(34, 16, 1, 1, 0),
|
62 |
+
(16, 32),
|
63 |
+
(32, 2, 1),
|
64 |
+
(16, 2, 1),
|
65 |
+
(16, 2, 1),
|
66 |
+
]
|
67 |
+
|
68 |
+
if nn_architecture in hp_model_arch:
|
69 |
+
model_capacity_data = [
|
70 |
+
(2, 32),
|
71 |
+
(2, 32),
|
72 |
+
(34, 16, 1, 1, 0),
|
73 |
+
(16, 32),
|
74 |
+
(66, 32, 1, 1, 0),
|
75 |
+
(32, 64),
|
76 |
+
(64, 2, 1),
|
77 |
+
(32, 2, 1),
|
78 |
+
(32, 2, 1),
|
79 |
+
]
|
80 |
+
|
81 |
+
if nn_architecture in hp2_model_arch:
|
82 |
+
model_capacity_data = [
|
83 |
+
(2, 64),
|
84 |
+
(2, 64),
|
85 |
+
(66, 32, 1, 1, 0),
|
86 |
+
(32, 64),
|
87 |
+
(130, 64, 1, 1, 0),
|
88 |
+
(64, 128),
|
89 |
+
(128, 2, 1),
|
90 |
+
(64, 2, 1),
|
91 |
+
(64, 2, 1),
|
92 |
+
]
|
93 |
+
|
94 |
+
cascaded = CascadedASPPNet
|
95 |
+
model = cascaded(n_fft_bins, model_capacity_data, nn_architecture)
|
96 |
+
|
97 |
+
return model
|
98 |
+
|
99 |
+
class CascadedASPPNet(nn.Module):
|
100 |
+
|
101 |
+
def __init__(self, n_fft, model_capacity_data, nn_architecture):
|
102 |
+
super(CascadedASPPNet, self).__init__()
|
103 |
+
self.stg1_low_band_net = BaseASPPNet(nn_architecture, *model_capacity_data[0])
|
104 |
+
self.stg1_high_band_net = BaseASPPNet(nn_architecture, *model_capacity_data[1])
|
105 |
+
|
106 |
+
self.stg2_bridge = layers.Conv2DBNActiv(*model_capacity_data[2])
|
107 |
+
self.stg2_full_band_net = BaseASPPNet(nn_architecture, *model_capacity_data[3])
|
108 |
+
|
109 |
+
self.stg3_bridge = layers.Conv2DBNActiv(*model_capacity_data[4])
|
110 |
+
self.stg3_full_band_net = BaseASPPNet(nn_architecture, *model_capacity_data[5])
|
111 |
+
|
112 |
+
self.out = nn.Conv2d(*model_capacity_data[6], bias=False)
|
113 |
+
self.aux1_out = nn.Conv2d(*model_capacity_data[7], bias=False)
|
114 |
+
self.aux2_out = nn.Conv2d(*model_capacity_data[8], bias=False)
|
115 |
+
|
116 |
+
self.max_bin = n_fft // 2
|
117 |
+
self.output_bin = n_fft // 2 + 1
|
118 |
+
|
119 |
+
self.offset = 128
|
120 |
+
|
121 |
+
def forward(self, x):
|
122 |
+
mix = x.detach()
|
123 |
+
x = x.clone()
|
124 |
+
|
125 |
+
x = x[:, :, :self.max_bin]
|
126 |
+
|
127 |
+
bandw = x.size()[2] // 2
|
128 |
+
aux1 = torch.cat([
|
129 |
+
self.stg1_low_band_net(x[:, :, :bandw]),
|
130 |
+
self.stg1_high_band_net(x[:, :, bandw:])
|
131 |
+
], dim=2)
|
132 |
+
|
133 |
+
h = torch.cat([x, aux1], dim=1)
|
134 |
+
aux2 = self.stg2_full_band_net(self.stg2_bridge(h))
|
135 |
+
|
136 |
+
h = torch.cat([x, aux1, aux2], dim=1)
|
137 |
+
h = self.stg3_full_band_net(self.stg3_bridge(h))
|
138 |
+
|
139 |
+
mask = torch.sigmoid(self.out(h))
|
140 |
+
mask = F.pad(
|
141 |
+
input=mask,
|
142 |
+
pad=(0, 0, 0, self.output_bin - mask.size()[2]),
|
143 |
+
mode='replicate')
|
144 |
+
|
145 |
+
if self.training:
|
146 |
+
aux1 = torch.sigmoid(self.aux1_out(aux1))
|
147 |
+
aux1 = F.pad(
|
148 |
+
input=aux1,
|
149 |
+
pad=(0, 0, 0, self.output_bin - aux1.size()[2]),
|
150 |
+
mode='replicate')
|
151 |
+
aux2 = torch.sigmoid(self.aux2_out(aux2))
|
152 |
+
aux2 = F.pad(
|
153 |
+
input=aux2,
|
154 |
+
pad=(0, 0, 0, self.output_bin - aux2.size()[2]),
|
155 |
+
mode='replicate')
|
156 |
+
return mask * mix, aux1 * mix, aux2 * mix
|
157 |
+
else:
|
158 |
+
return mask# * mix
|
159 |
+
|
160 |
+
def predict_mask(self, x):
|
161 |
+
mask = self.forward(x)
|
162 |
+
|
163 |
+
if self.offset > 0:
|
164 |
+
mask = mask[:, :, :, self.offset:-self.offset]
|
165 |
+
|
166 |
+
return mask
|
lib_v5/vr_network/nets_new.py
ADDED
@@ -0,0 +1,125 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import torch
|
2 |
+
from torch import nn
|
3 |
+
import torch.nn.functional as F
|
4 |
+
from . import layers_new as layers
|
5 |
+
|
6 |
+
class BaseNet(nn.Module):
|
7 |
+
|
8 |
+
def __init__(self, nin, nout, nin_lstm, nout_lstm, dilations=((4, 2), (8, 4), (12, 6))):
|
9 |
+
super(BaseNet, self).__init__()
|
10 |
+
self.enc1 = layers.Conv2DBNActiv(nin, nout, 3, 1, 1)
|
11 |
+
self.enc2 = layers.Encoder(nout, nout * 2, 3, 2, 1)
|
12 |
+
self.enc3 = layers.Encoder(nout * 2, nout * 4, 3, 2, 1)
|
13 |
+
self.enc4 = layers.Encoder(nout * 4, nout * 6, 3, 2, 1)
|
14 |
+
self.enc5 = layers.Encoder(nout * 6, nout * 8, 3, 2, 1)
|
15 |
+
|
16 |
+
self.aspp = layers.ASPPModule(nout * 8, nout * 8, dilations, dropout=True)
|
17 |
+
|
18 |
+
self.dec4 = layers.Decoder(nout * (6 + 8), nout * 6, 3, 1, 1)
|
19 |
+
self.dec3 = layers.Decoder(nout * (4 + 6), nout * 4, 3, 1, 1)
|
20 |
+
self.dec2 = layers.Decoder(nout * (2 + 4), nout * 2, 3, 1, 1)
|
21 |
+
self.lstm_dec2 = layers.LSTMModule(nout * 2, nin_lstm, nout_lstm)
|
22 |
+
self.dec1 = layers.Decoder(nout * (1 + 2) + 1, nout * 1, 3, 1, 1)
|
23 |
+
|
24 |
+
def __call__(self, x):
|
25 |
+
e1 = self.enc1(x)
|
26 |
+
e2 = self.enc2(e1)
|
27 |
+
e3 = self.enc3(e2)
|
28 |
+
e4 = self.enc4(e3)
|
29 |
+
e5 = self.enc5(e4)
|
30 |
+
|
31 |
+
h = self.aspp(e5)
|
32 |
+
|
33 |
+
h = self.dec4(h, e4)
|
34 |
+
h = self.dec3(h, e3)
|
35 |
+
h = self.dec2(h, e2)
|
36 |
+
h = torch.cat([h, self.lstm_dec2(h)], dim=1)
|
37 |
+
h = self.dec1(h, e1)
|
38 |
+
|
39 |
+
return h
|
40 |
+
|
41 |
+
class CascadedNet(nn.Module):
|
42 |
+
|
43 |
+
def __init__(self, n_fft, nn_arch_size, nout=32, nout_lstm=128):
|
44 |
+
super(CascadedNet, self).__init__()
|
45 |
+
|
46 |
+
self.max_bin = n_fft // 2
|
47 |
+
self.output_bin = n_fft // 2 + 1
|
48 |
+
self.nin_lstm = self.max_bin // 2
|
49 |
+
self.offset = 64
|
50 |
+
nout = 64 if nn_arch_size == 218409 else nout
|
51 |
+
|
52 |
+
self.stg1_low_band_net = nn.Sequential(
|
53 |
+
BaseNet(2, nout // 2, self.nin_lstm // 2, nout_lstm),
|
54 |
+
layers.Conv2DBNActiv(nout // 2, nout // 4, 1, 1, 0)
|
55 |
+
)
|
56 |
+
|
57 |
+
self.stg1_high_band_net = BaseNet(2, nout // 4, self.nin_lstm // 2, nout_lstm // 2)
|
58 |
+
|
59 |
+
self.stg2_low_band_net = nn.Sequential(
|
60 |
+
BaseNet(nout // 4 + 2, nout, self.nin_lstm // 2, nout_lstm),
|
61 |
+
layers.Conv2DBNActiv(nout, nout // 2, 1, 1, 0)
|
62 |
+
)
|
63 |
+
self.stg2_high_band_net = BaseNet(nout // 4 + 2, nout // 2, self.nin_lstm // 2, nout_lstm // 2)
|
64 |
+
|
65 |
+
self.stg3_full_band_net = BaseNet(3 * nout // 4 + 2, nout, self.nin_lstm, nout_lstm)
|
66 |
+
|
67 |
+
self.out = nn.Conv2d(nout, 2, 1, bias=False)
|
68 |
+
self.aux_out = nn.Conv2d(3 * nout // 4, 2, 1, bias=False)
|
69 |
+
|
70 |
+
def forward(self, x):
|
71 |
+
x = x[:, :, :self.max_bin]
|
72 |
+
|
73 |
+
bandw = x.size()[2] // 2
|
74 |
+
l1_in = x[:, :, :bandw]
|
75 |
+
h1_in = x[:, :, bandw:]
|
76 |
+
l1 = self.stg1_low_band_net(l1_in)
|
77 |
+
h1 = self.stg1_high_band_net(h1_in)
|
78 |
+
aux1 = torch.cat([l1, h1], dim=2)
|
79 |
+
|
80 |
+
l2_in = torch.cat([l1_in, l1], dim=1)
|
81 |
+
h2_in = torch.cat([h1_in, h1], dim=1)
|
82 |
+
l2 = self.stg2_low_band_net(l2_in)
|
83 |
+
h2 = self.stg2_high_band_net(h2_in)
|
84 |
+
aux2 = torch.cat([l2, h2], dim=2)
|
85 |
+
|
86 |
+
f3_in = torch.cat([x, aux1, aux2], dim=1)
|
87 |
+
f3 = self.stg3_full_band_net(f3_in)
|
88 |
+
|
89 |
+
mask = torch.sigmoid(self.out(f3))
|
90 |
+
mask = F.pad(
|
91 |
+
input=mask,
|
92 |
+
pad=(0, 0, 0, self.output_bin - mask.size()[2]),
|
93 |
+
mode='replicate'
|
94 |
+
)
|
95 |
+
|
96 |
+
if self.training:
|
97 |
+
aux = torch.cat([aux1, aux2], dim=1)
|
98 |
+
aux = torch.sigmoid(self.aux_out(aux))
|
99 |
+
aux = F.pad(
|
100 |
+
input=aux,
|
101 |
+
pad=(0, 0, 0, self.output_bin - aux.size()[2]),
|
102 |
+
mode='replicate'
|
103 |
+
)
|
104 |
+
return mask, aux
|
105 |
+
else:
|
106 |
+
return mask
|
107 |
+
|
108 |
+
def predict_mask(self, x):
|
109 |
+
mask = self.forward(x)
|
110 |
+
|
111 |
+
if self.offset > 0:
|
112 |
+
mask = mask[:, :, :, self.offset:-self.offset]
|
113 |
+
assert mask.size()[3] > 0
|
114 |
+
|
115 |
+
return mask
|
116 |
+
|
117 |
+
def predict(self, x):
|
118 |
+
mask = self.forward(x)
|
119 |
+
pred_mag = x * mask
|
120 |
+
|
121 |
+
if self.offset > 0:
|
122 |
+
pred_mag = pred_mag[:, :, :, self.offset:-self.offset]
|
123 |
+
assert pred_mag.size()[3] > 0
|
124 |
+
|
125 |
+
return pred_mag
|