mirror of
https://github.com/Anjok07/ultimatevocalremovergui.git
synced 2025-02-17 19:19:15 +01:00
Add files via upload
This commit is contained in:
parent
8ea414b35f
commit
14a82e5e9f
87
lib/diffext.py
Normal file
87
lib/diffext.py
Normal file
@ -0,0 +1,87 @@
|
||||
import os
|
||||
import sys
|
||||
import random
|
||||
import glob
|
||||
import soundfile as sf
|
||||
import librosa
|
||||
import numpy as np
|
||||
|
||||
def align(file1, file2, file2_aligned, file_subtracted):
|
||||
def get_diff(a, b):
|
||||
corr = np.correlate(a, b, "full")
|
||||
diff = corr.argmax() - (b.shape[0] - 1)
|
||||
return diff
|
||||
|
||||
def get_diff_val(a, b):
|
||||
d = np.abs(a - b)
|
||||
return np.mean(d) / max(min(np.max(d), 0.1), 1e-6)
|
||||
|
||||
|
||||
if os.path.splitext(file1)[1] == '.mp3':
|
||||
wav1, sr1 = librosa.load(file1, sr=None, mono=False)
|
||||
wav2, sr2 = librosa.load(file2, sr=None, mono=False)
|
||||
wav1 = wav1.transpose()
|
||||
wav2 = wav2.transpose()
|
||||
else:
|
||||
wav1, sr1 = sf.read(file1, dtype='float32')
|
||||
wav2, sr2 = sf.read(file2, dtype='float32')
|
||||
assert(sr1 == sr2)
|
||||
wav2_org = wav2.copy()
|
||||
|
||||
|
||||
counts = {}
|
||||
for i in range(64):
|
||||
index = int(random.uniform(44100 * 2, min(wav1.shape[0], wav2.shape[0]) - 44100 * 2))
|
||||
shift = int(random.uniform(-22050,+22050))
|
||||
samp1 = wav1[index :index +44100, 0]
|
||||
samp2 = wav2[index+shift:index+shift+44100, 0]
|
||||
diff = get_diff(samp1, samp2)
|
||||
diff -= shift
|
||||
if abs(diff) < 22050:
|
||||
if not diff in counts:
|
||||
counts[diff] = 0
|
||||
counts[diff] += 1
|
||||
|
||||
max_count = 0
|
||||
est_diff = 0
|
||||
for diff in counts.keys():
|
||||
if counts[diff] > max_count:
|
||||
max_count = counts[diff]
|
||||
est_diff = diff
|
||||
|
||||
if est_diff > 0:
|
||||
wav2_aligned = np.append(np.zeros((est_diff, 2)), wav2_org, axis=0)
|
||||
elif est_diff < 0:
|
||||
wav2_aligned = wav2_org[-est_diff:]
|
||||
elif est_diff == 0:
|
||||
wav2_aligned = wav2_org[-est_diff:]
|
||||
|
||||
min_len = min(wav1.shape[0], wav2_aligned.shape[0])
|
||||
wav_sub = wav1[:min_len] - wav2_aligned[:min_len]
|
||||
wav_sub = np.clip(wav_sub, -1, +1)
|
||||
sf.write(file_subtracted, wav_sub, sr2, subtype='PCM_16')
|
||||
|
||||
def align_files(pat1, pat2):
|
||||
files1 = glob.glob(pat1)
|
||||
files2 = glob.glob(pat2)
|
||||
files1.sort()
|
||||
files2.sort()
|
||||
for file1, file2 in zip(files1, files2):
|
||||
base_name = os.path.basename(os.path.splitext(file2)[0])
|
||||
aligned_file = base_name + '_aligned.wav'
|
||||
subtracted_file = base_name + '_sub.wav'
|
||||
align(file1, file2, aligned_file, subtracted_file)
|
||||
|
||||
if __name__ == '__main__':
|
||||
args = sys.argv
|
||||
|
||||
if len(args) == 3:
|
||||
align_files(args[1], args[2])
|
||||
elif len(args) == 5:
|
||||
align(args[1], args[2], args[3], args[4])
|
||||
else:
|
||||
print("align two tracks\n:" +
|
||||
" python align_tracks.py file-1 file-2 aligned-file-2-to-save subtracted-file-to-save" +
|
||||
"align all track\n:" +
|
||||
" python align_tracks.py pattern-1 pattern-2\n" +
|
||||
" saved to '*_aligned.wav' and '*_sub.wav' in the current dir.")
|
116
lib/layers_123821KB.py
Normal file
116
lib/layers_123821KB.py
Normal file
@ -0,0 +1,116 @@
|
||||
import torch
|
||||
from torch import nn
|
||||
import torch.nn.functional as F
|
||||
|
||||
from lib import spec_utils
|
||||
|
||||
|
||||
class Conv2DBNActiv(nn.Module):
|
||||
|
||||
def __init__(self, nin, nout, ksize=3, stride=1, pad=1, dilation=1, activ=nn.ReLU):
|
||||
super(Conv2DBNActiv, self).__init__()
|
||||
self.conv = nn.Sequential(
|
||||
nn.Conv2d(
|
||||
nin, nout,
|
||||
kernel_size=ksize,
|
||||
stride=stride,
|
||||
padding=pad,
|
||||
dilation=dilation,
|
||||
bias=False),
|
||||
nn.BatchNorm2d(nout),
|
||||
activ()
|
||||
)
|
||||
|
||||
def __call__(self, x):
|
||||
return self.conv(x)
|
||||
|
||||
|
||||
class SeperableConv2DBNActiv(nn.Module):
|
||||
|
||||
def __init__(self, nin, nout, ksize=3, stride=1, pad=1, dilation=1, activ=nn.ReLU):
|
||||
super(SeperableConv2DBNActiv, self).__init__()
|
||||
self.conv = nn.Sequential(
|
||||
nn.Conv2d(
|
||||
nin, nin,
|
||||
kernel_size=ksize,
|
||||
stride=stride,
|
||||
padding=pad,
|
||||
dilation=dilation,
|
||||
groups=nin,
|
||||
bias=False),
|
||||
nn.Conv2d(
|
||||
nin, nout,
|
||||
kernel_size=1,
|
||||
bias=False),
|
||||
nn.BatchNorm2d(nout),
|
||||
activ()
|
||||
)
|
||||
|
||||
def __call__(self, x):
|
||||
return self.conv(x)
|
||||
|
||||
|
||||
class Encoder(nn.Module):
|
||||
|
||||
def __init__(self, nin, nout, ksize=3, stride=1, pad=1, activ=nn.LeakyReLU):
|
||||
super(Encoder, self).__init__()
|
||||
self.conv1 = Conv2DBNActiv(nin, nout, ksize, 1, pad, activ=activ)
|
||||
self.conv2 = Conv2DBNActiv(nout, nout, ksize, stride, pad, activ=activ)
|
||||
|
||||
def __call__(self, x):
|
||||
skip = self.conv1(x)
|
||||
h = self.conv2(skip)
|
||||
|
||||
return h, skip
|
||||
|
||||
|
||||
class Decoder(nn.Module):
|
||||
|
||||
def __init__(self, nin, nout, ksize=3, stride=1, pad=1, activ=nn.ReLU, dropout=False):
|
||||
super(Decoder, self).__init__()
|
||||
self.conv = Conv2DBNActiv(nin, nout, ksize, 1, pad, activ=activ)
|
||||
self.dropout = nn.Dropout2d(0.1) if dropout else None
|
||||
|
||||
def __call__(self, x, skip=None):
|
||||
x = F.interpolate(x, scale_factor=2, mode='bilinear', align_corners=True)
|
||||
if skip is not None:
|
||||
skip = spec_utils.crop_center(skip, x)
|
||||
x = torch.cat([x, skip], dim=1)
|
||||
h = self.conv(x)
|
||||
|
||||
if self.dropout is not None:
|
||||
h = self.dropout(h)
|
||||
|
||||
return h
|
||||
|
||||
|
||||
class ASPPModule(nn.Module):
|
||||
|
||||
def __init__(self, nin, nout, dilations=(4, 8, 16), activ=nn.ReLU):
|
||||
super(ASPPModule, self).__init__()
|
||||
self.conv1 = nn.Sequential(
|
||||
nn.AdaptiveAvgPool2d((1, None)),
|
||||
Conv2DBNActiv(nin, nin, 1, 1, 0, activ=activ)
|
||||
)
|
||||
self.conv2 = Conv2DBNActiv(nin, nin, 1, 1, 0, activ=activ)
|
||||
self.conv3 = SeperableConv2DBNActiv(
|
||||
nin, nin, 3, 1, dilations[0], dilations[0], activ=activ)
|
||||
self.conv4 = SeperableConv2DBNActiv(
|
||||
nin, nin, 3, 1, dilations[1], dilations[1], activ=activ)
|
||||
self.conv5 = SeperableConv2DBNActiv(
|
||||
nin, nin, 3, 1, dilations[2], dilations[2], activ=activ)
|
||||
self.bottleneck = nn.Sequential(
|
||||
Conv2DBNActiv(nin * 5, nout, 1, 1, 0, activ=activ),
|
||||
nn.Dropout2d(0.1)
|
||||
)
|
||||
|
||||
def forward(self, x):
|
||||
_, _, h, w = x.size()
|
||||
feat1 = F.interpolate(self.conv1(x), size=(h, w), mode='bilinear', align_corners=True)
|
||||
feat2 = self.conv2(x)
|
||||
feat3 = self.conv3(x)
|
||||
feat4 = self.conv4(x)
|
||||
feat5 = self.conv5(x)
|
||||
out = torch.cat((feat1, feat2, feat3, feat4, feat5), dim=1)
|
||||
bottle = self.bottleneck(out)
|
||||
return bottle
|
119
lib/layers_129605KB.py
Normal file
119
lib/layers_129605KB.py
Normal file
@ -0,0 +1,119 @@
|
||||
import torch
|
||||
from torch import nn
|
||||
import torch.nn.functional as F
|
||||
|
||||
from lib import spec_utils
|
||||
|
||||
|
||||
class Conv2DBNActiv(nn.Module):
|
||||
|
||||
def __init__(self, nin, nout, ksize=3, stride=1, pad=1, dilation=1, activ=nn.ReLU):
|
||||
super(Conv2DBNActiv, self).__init__()
|
||||
self.conv = nn.Sequential(
|
||||
nn.Conv2d(
|
||||
nin, nout,
|
||||
kernel_size=ksize,
|
||||
stride=stride,
|
||||
padding=pad,
|
||||
dilation=dilation,
|
||||
bias=False),
|
||||
nn.BatchNorm2d(nout),
|
||||
activ()
|
||||
)
|
||||
|
||||
def __call__(self, x):
|
||||
return self.conv(x)
|
||||
|
||||
|
||||
class SeperableConv2DBNActiv(nn.Module):
|
||||
|
||||
def __init__(self, nin, nout, ksize=3, stride=1, pad=1, dilation=1, activ=nn.ReLU):
|
||||
super(SeperableConv2DBNActiv, self).__init__()
|
||||
self.conv = nn.Sequential(
|
||||
nn.Conv2d(
|
||||
nin, nin,
|
||||
kernel_size=ksize,
|
||||
stride=stride,
|
||||
padding=pad,
|
||||
dilation=dilation,
|
||||
groups=nin,
|
||||
bias=False),
|
||||
nn.Conv2d(
|
||||
nin, nout,
|
||||
kernel_size=1,
|
||||
bias=False),
|
||||
nn.BatchNorm2d(nout),
|
||||
activ()
|
||||
)
|
||||
|
||||
def __call__(self, x):
|
||||
return self.conv(x)
|
||||
|
||||
|
||||
class Encoder(nn.Module):
|
||||
|
||||
def __init__(self, nin, nout, ksize=3, stride=1, pad=1, activ=nn.LeakyReLU):
|
||||
super(Encoder, self).__init__()
|
||||
self.conv1 = Conv2DBNActiv(nin, nout, ksize, 1, pad, activ=activ)
|
||||
self.conv2 = Conv2DBNActiv(nout, nout, ksize, stride, pad, activ=activ)
|
||||
|
||||
def __call__(self, x):
|
||||
skip = self.conv1(x)
|
||||
h = self.conv2(skip)
|
||||
|
||||
return h, skip
|
||||
|
||||
|
||||
class Decoder(nn.Module):
|
||||
|
||||
def __init__(self, nin, nout, ksize=3, stride=1, pad=1, activ=nn.ReLU, dropout=False):
|
||||
super(Decoder, self).__init__()
|
||||
self.conv = Conv2DBNActiv(nin, nout, ksize, 1, pad, activ=activ)
|
||||
self.dropout = nn.Dropout2d(0.1) if dropout else None
|
||||
|
||||
def __call__(self, x, skip=None):
|
||||
x = F.interpolate(x, scale_factor=2, mode='bilinear', align_corners=True)
|
||||
if skip is not None:
|
||||
skip = spec_utils.crop_center(skip, x)
|
||||
x = torch.cat([x, skip], dim=1)
|
||||
h = self.conv(x)
|
||||
|
||||
if self.dropout is not None:
|
||||
h = self.dropout(h)
|
||||
|
||||
return h
|
||||
|
||||
|
||||
class ASPPModule(nn.Module):
|
||||
|
||||
def __init__(self, nin, nout, dilations=(4, 8, 16, 32), activ=nn.ReLU):
|
||||
super(ASPPModule, self).__init__()
|
||||
self.conv1 = nn.Sequential(
|
||||
nn.AdaptiveAvgPool2d((1, None)),
|
||||
Conv2DBNActiv(nin, nin, 1, 1, 0, activ=activ)
|
||||
)
|
||||
self.conv2 = Conv2DBNActiv(nin, nin, 1, 1, 0, activ=activ)
|
||||
self.conv3 = SeperableConv2DBNActiv(
|
||||
nin, nin, 3, 1, dilations[0], dilations[0], activ=activ)
|
||||
self.conv4 = SeperableConv2DBNActiv(
|
||||
nin, nin, 3, 1, dilations[1], dilations[1], activ=activ)
|
||||
self.conv5 = SeperableConv2DBNActiv(
|
||||
nin, nin, 3, 1, dilations[2], dilations[2], activ=activ)
|
||||
self.conv6 = SeperableConv2DBNActiv(
|
||||
nin, nin, 3, 1, dilations[2], dilations[2], activ=activ)
|
||||
self.bottleneck = nn.Sequential(
|
||||
Conv2DBNActiv(nin * 6, nout, 1, 1, 0, activ=activ),
|
||||
nn.Dropout2d(0.1)
|
||||
)
|
||||
|
||||
def forward(self, x):
|
||||
_, _, h, w = x.size()
|
||||
feat1 = F.interpolate(self.conv1(x), size=(h, w), mode='bilinear', align_corners=True)
|
||||
feat2 = self.conv2(x)
|
||||
feat3 = self.conv3(x)
|
||||
feat4 = self.conv4(x)
|
||||
feat5 = self.conv5(x)
|
||||
feat6 = self.conv6(x)
|
||||
out = torch.cat((feat1, feat2, feat3, feat4, feat5, feat6), dim=1)
|
||||
bottle = self.bottleneck(out)
|
||||
return bottle
|
122
lib/layers_33966KB.py
Normal file
122
lib/layers_33966KB.py
Normal file
@ -0,0 +1,122 @@
|
||||
import torch
|
||||
from torch import nn
|
||||
import torch.nn.functional as F
|
||||
|
||||
from lib import spec_utils
|
||||
|
||||
|
||||
class Conv2DBNActiv(nn.Module):
|
||||
|
||||
def __init__(self, nin, nout, ksize=3, stride=1, pad=1, dilation=1, activ=nn.ReLU):
|
||||
super(Conv2DBNActiv, self).__init__()
|
||||
self.conv = nn.Sequential(
|
||||
nn.Conv2d(
|
||||
nin, nout,
|
||||
kernel_size=ksize,
|
||||
stride=stride,
|
||||
padding=pad,
|
||||
dilation=dilation,
|
||||
bias=False),
|
||||
nn.BatchNorm2d(nout),
|
||||
activ()
|
||||
)
|
||||
|
||||
def __call__(self, x):
|
||||
return self.conv(x)
|
||||
|
||||
|
||||
class SeperableConv2DBNActiv(nn.Module):
|
||||
|
||||
def __init__(self, nin, nout, ksize=3, stride=1, pad=1, dilation=1, activ=nn.ReLU):
|
||||
super(SeperableConv2DBNActiv, self).__init__()
|
||||
self.conv = nn.Sequential(
|
||||
nn.Conv2d(
|
||||
nin, nin,
|
||||
kernel_size=ksize,
|
||||
stride=stride,
|
||||
padding=pad,
|
||||
dilation=dilation,
|
||||
groups=nin,
|
||||
bias=False),
|
||||
nn.Conv2d(
|
||||
nin, nout,
|
||||
kernel_size=1,
|
||||
bias=False),
|
||||
nn.BatchNorm2d(nout),
|
||||
activ()
|
||||
)
|
||||
|
||||
def __call__(self, x):
|
||||
return self.conv(x)
|
||||
|
||||
|
||||
class Encoder(nn.Module):
|
||||
|
||||
def __init__(self, nin, nout, ksize=3, stride=1, pad=1, activ=nn.LeakyReLU):
|
||||
super(Encoder, self).__init__()
|
||||
self.conv1 = Conv2DBNActiv(nin, nout, ksize, 1, pad, activ=activ)
|
||||
self.conv2 = Conv2DBNActiv(nout, nout, ksize, stride, pad, activ=activ)
|
||||
|
||||
def __call__(self, x):
|
||||
skip = self.conv1(x)
|
||||
h = self.conv2(skip)
|
||||
|
||||
return h, skip
|
||||
|
||||
|
||||
class Decoder(nn.Module):
|
||||
|
||||
def __init__(self, nin, nout, ksize=3, stride=1, pad=1, activ=nn.ReLU, dropout=False):
|
||||
super(Decoder, self).__init__()
|
||||
self.conv = Conv2DBNActiv(nin, nout, ksize, 1, pad, activ=activ)
|
||||
self.dropout = nn.Dropout2d(0.1) if dropout else None
|
||||
|
||||
def __call__(self, x, skip=None):
|
||||
x = F.interpolate(x, scale_factor=2, mode='bilinear', align_corners=True)
|
||||
if skip is not None:
|
||||
skip = spec_utils.crop_center(skip, x)
|
||||
x = torch.cat([x, skip], dim=1)
|
||||
h = self.conv(x)
|
||||
|
||||
if self.dropout is not None:
|
||||
h = self.dropout(h)
|
||||
|
||||
return h
|
||||
|
||||
|
||||
class ASPPModule(nn.Module):
|
||||
|
||||
def __init__(self, nin, nout, dilations=(4, 8, 16, 32, 64), activ=nn.ReLU):
|
||||
super(ASPPModule, self).__init__()
|
||||
self.conv1 = nn.Sequential(
|
||||
nn.AdaptiveAvgPool2d((1, None)),
|
||||
Conv2DBNActiv(nin, nin, 1, 1, 0, activ=activ)
|
||||
)
|
||||
self.conv2 = Conv2DBNActiv(nin, nin, 1, 1, 0, activ=activ)
|
||||
self.conv3 = SeperableConv2DBNActiv(
|
||||
nin, nin, 3, 1, dilations[0], dilations[0], activ=activ)
|
||||
self.conv4 = SeperableConv2DBNActiv(
|
||||
nin, nin, 3, 1, dilations[1], dilations[1], activ=activ)
|
||||
self.conv5 = SeperableConv2DBNActiv(
|
||||
nin, nin, 3, 1, dilations[2], dilations[2], activ=activ)
|
||||
self.conv6 = SeperableConv2DBNActiv(
|
||||
nin, nin, 3, 1, dilations[2], dilations[2], activ=activ)
|
||||
self.conv7 = SeperableConv2DBNActiv(
|
||||
nin, nin, 3, 1, dilations[2], dilations[2], activ=activ)
|
||||
self.bottleneck = nn.Sequential(
|
||||
Conv2DBNActiv(nin * 7, nout, 1, 1, 0, activ=activ),
|
||||
nn.Dropout2d(0.1)
|
||||
)
|
||||
|
||||
def forward(self, x):
|
||||
_, _, h, w = x.size()
|
||||
feat1 = F.interpolate(self.conv1(x), size=(h, w), mode='bilinear', align_corners=True)
|
||||
feat2 = self.conv2(x)
|
||||
feat3 = self.conv3(x)
|
||||
feat4 = self.conv4(x)
|
||||
feat5 = self.conv5(x)
|
||||
feat6 = self.conv6(x)
|
||||
feat7 = self.conv7(x)
|
||||
out = torch.cat((feat1, feat2, feat3, feat4, feat5, feat6, feat7), dim=1)
|
||||
bottle = self.bottleneck(out)
|
||||
return bottle
|
@ -60,4 +60,4 @@ class ModelParameters(object):
|
||||
|
||||
if not 'reverse' in self.param:
|
||||
self.param['reverse'] = False
|
||||
|
||||
|
112
lib/nets_123821KB.py
Normal file
112
lib/nets_123821KB.py
Normal file
@ -0,0 +1,112 @@
|
||||
import torch
|
||||
from torch import nn
|
||||
import torch.nn.functional as F
|
||||
|
||||
from lib import layers_123821KB as layers
|
||||
|
||||
|
||||
class BaseASPPNet(nn.Module):
|
||||
|
||||
def __init__(self, nin, ch, dilations=(4, 8, 16)):
|
||||
super(BaseASPPNet, self).__init__()
|
||||
self.enc1 = layers.Encoder(nin, ch, 3, 2, 1)
|
||||
self.enc2 = layers.Encoder(ch, ch * 2, 3, 2, 1)
|
||||
self.enc3 = layers.Encoder(ch * 2, ch * 4, 3, 2, 1)
|
||||
self.enc4 = layers.Encoder(ch * 4, ch * 8, 3, 2, 1)
|
||||
|
||||
self.aspp = layers.ASPPModule(ch * 8, ch * 16, dilations)
|
||||
|
||||
self.dec4 = layers.Decoder(ch * (8 + 16), ch * 8, 3, 1, 1)
|
||||
self.dec3 = layers.Decoder(ch * (4 + 8), ch * 4, 3, 1, 1)
|
||||
self.dec2 = layers.Decoder(ch * (2 + 4), ch * 2, 3, 1, 1)
|
||||
self.dec1 = layers.Decoder(ch * (1 + 2), ch, 3, 1, 1)
|
||||
|
||||
def __call__(self, x):
|
||||
h, e1 = self.enc1(x)
|
||||
h, e2 = self.enc2(h)
|
||||
h, e3 = self.enc3(h)
|
||||
h, e4 = self.enc4(h)
|
||||
|
||||
h = self.aspp(h)
|
||||
|
||||
h = self.dec4(h, e4)
|
||||
h = self.dec3(h, e3)
|
||||
h = self.dec2(h, e2)
|
||||
h = self.dec1(h, e1)
|
||||
|
||||
return h
|
||||
|
||||
|
||||
class CascadedASPPNet(nn.Module):
|
||||
|
||||
def __init__(self, n_fft):
|
||||
super(CascadedASPPNet, self).__init__()
|
||||
self.stg1_low_band_net = BaseASPPNet(2, 32)
|
||||
self.stg1_high_band_net = BaseASPPNet(2, 32)
|
||||
|
||||
self.stg2_bridge = layers.Conv2DBNActiv(34, 16, 1, 1, 0)
|
||||
self.stg2_full_band_net = BaseASPPNet(16, 32)
|
||||
|
||||
self.stg3_bridge = layers.Conv2DBNActiv(66, 32, 1, 1, 0)
|
||||
self.stg3_full_band_net = BaseASPPNet(32, 64)
|
||||
|
||||
self.out = nn.Conv2d(64, 2, 1, bias=False)
|
||||
self.aux1_out = nn.Conv2d(32, 2, 1, bias=False)
|
||||
self.aux2_out = nn.Conv2d(32, 2, 1, bias=False)
|
||||
|
||||
self.max_bin = n_fft // 2
|
||||
self.output_bin = n_fft // 2 + 1
|
||||
|
||||
self.offset = 128
|
||||
|
||||
def forward(self, x, aggressiveness=None):
|
||||
mix = x.detach()
|
||||
x = x.clone()
|
||||
|
||||
x = x[:, :, :self.max_bin]
|
||||
|
||||
bandw = x.size()[2] // 2
|
||||
aux1 = torch.cat([
|
||||
self.stg1_low_band_net(x[:, :, :bandw]),
|
||||
self.stg1_high_band_net(x[:, :, bandw:])
|
||||
], dim=2)
|
||||
|
||||
h = torch.cat([x, aux1], dim=1)
|
||||
aux2 = self.stg2_full_band_net(self.stg2_bridge(h))
|
||||
|
||||
h = torch.cat([x, aux1, aux2], dim=1)
|
||||
h = self.stg3_full_band_net(self.stg3_bridge(h))
|
||||
|
||||
mask = torch.sigmoid(self.out(h))
|
||||
mask = F.pad(
|
||||
input=mask,
|
||||
pad=(0, 0, 0, self.output_bin - mask.size()[2]),
|
||||
mode='replicate')
|
||||
|
||||
if self.training:
|
||||
aux1 = torch.sigmoid(self.aux1_out(aux1))
|
||||
aux1 = F.pad(
|
||||
input=aux1,
|
||||
pad=(0, 0, 0, self.output_bin - aux1.size()[2]),
|
||||
mode='replicate')
|
||||
aux2 = torch.sigmoid(self.aux2_out(aux2))
|
||||
aux2 = F.pad(
|
||||
input=aux2,
|
||||
pad=(0, 0, 0, self.output_bin - aux2.size()[2]),
|
||||
mode='replicate')
|
||||
return mask * mix, aux1 * mix, aux2 * mix
|
||||
else:
|
||||
if aggressiveness:
|
||||
mask[:, :, :aggressiveness['split_bin']] = torch.pow(mask[:, :, :aggressiveness['split_bin']], 1 + aggressiveness['value'] / 3)
|
||||
mask[:, :, aggressiveness['split_bin']:] = torch.pow(mask[:, :, aggressiveness['split_bin']:], 1 + aggressiveness['value'])
|
||||
|
||||
return mask * mix
|
||||
|
||||
def predict(self, x_mag, aggressiveness=None):
|
||||
h = self.forward(x_mag, aggressiveness)
|
||||
|
||||
if self.offset > 0:
|
||||
h = h[:, :, :, self.offset:-self.offset]
|
||||
assert h.size()[3] > 0
|
||||
|
||||
return h
|
116
lib/nets_129605KB.py
Normal file
116
lib/nets_129605KB.py
Normal file
@ -0,0 +1,116 @@
|
||||
import torch
|
||||
from torch import nn
|
||||
import torch.nn.functional as F
|
||||
|
||||
from lib import layers_129605KB as layers
|
||||
|
||||
|
||||
class BaseASPPNet(nn.Module):
|
||||
|
||||
def __init__(self, nin, ch, dilations=(4, 8, 16, 32)):
|
||||
super(BaseASPPNet, self).__init__()
|
||||
self.enc1 = layers.Encoder(nin, ch, 3, 2, 1)
|
||||
self.enc2 = layers.Encoder(ch, ch * 2, 3, 2, 1)
|
||||
self.enc3 = layers.Encoder(ch * 2, ch * 4, 3, 2, 1)
|
||||
self.enc4 = layers.Encoder(ch * 4, ch * 8, 3, 2, 1)
|
||||
self.enc5 = layers.Encoder(ch * 8, ch * 16, 3, 2, 1)
|
||||
|
||||
self.aspp = layers.ASPPModule(ch * 16, ch * 32, dilations)
|
||||
|
||||
self.dec5 = layers.Decoder(ch * (16 + 32), ch * 16, 3, 1, 1)
|
||||
self.dec4 = layers.Decoder(ch * (8 + 16), ch * 8, 3, 1, 1)
|
||||
self.dec3 = layers.Decoder(ch * (4 + 8), ch * 4, 3, 1, 1)
|
||||
self.dec2 = layers.Decoder(ch * (2 + 4), ch * 2, 3, 1, 1)
|
||||
self.dec1 = layers.Decoder(ch * (1 + 2), ch, 3, 1, 1)
|
||||
|
||||
def __call__(self, x):
|
||||
h, e1 = self.enc1(x)
|
||||
h, e2 = self.enc2(h)
|
||||
h, e3 = self.enc3(h)
|
||||
h, e4 = self.enc4(h)
|
||||
h, e5 = self.enc5(h)
|
||||
|
||||
h = self.aspp(h)
|
||||
|
||||
h = self.dec5(h, e5)
|
||||
h = self.dec4(h, e4)
|
||||
h = self.dec3(h, e3)
|
||||
h = self.dec2(h, e2)
|
||||
h = self.dec1(h, e1)
|
||||
|
||||
return h
|
||||
|
||||
|
||||
class CascadedASPPNet(nn.Module):
|
||||
|
||||
def __init__(self, n_fft):
|
||||
super(CascadedASPPNet, self).__init__()
|
||||
self.stg1_low_band_net = BaseASPPNet(2, 16)
|
||||
self.stg1_high_band_net = BaseASPPNet(2, 16)
|
||||
|
||||
self.stg2_bridge = layers.Conv2DBNActiv(18, 8, 1, 1, 0)
|
||||
self.stg2_full_band_net = BaseASPPNet(8, 16)
|
||||
|
||||
self.stg3_bridge = layers.Conv2DBNActiv(34, 16, 1, 1, 0)
|
||||
self.stg3_full_band_net = BaseASPPNet(16, 32)
|
||||
|
||||
self.out = nn.Conv2d(32, 2, 1, bias=False)
|
||||
self.aux1_out = nn.Conv2d(16, 2, 1, bias=False)
|
||||
self.aux2_out = nn.Conv2d(16, 2, 1, bias=False)
|
||||
|
||||
self.max_bin = n_fft // 2
|
||||
self.output_bin = n_fft // 2 + 1
|
||||
|
||||
self.offset = 128
|
||||
|
||||
def forward(self, x, aggressiveness=None):
|
||||
mix = x.detach()
|
||||
x = x.clone()
|
||||
|
||||
x = x[:, :, :self.max_bin]
|
||||
|
||||
bandw = x.size()[2] // 2
|
||||
aux1 = torch.cat([
|
||||
self.stg1_low_band_net(x[:, :, :bandw]),
|
||||
self.stg1_high_band_net(x[:, :, bandw:])
|
||||
], dim=2)
|
||||
|
||||
h = torch.cat([x, aux1], dim=1)
|
||||
aux2 = self.stg2_full_band_net(self.stg2_bridge(h))
|
||||
|
||||
h = torch.cat([x, aux1, aux2], dim=1)
|
||||
h = self.stg3_full_band_net(self.stg3_bridge(h))
|
||||
|
||||
mask = torch.sigmoid(self.out(h))
|
||||
mask = F.pad(
|
||||
input=mask,
|
||||
pad=(0, 0, 0, self.output_bin - mask.size()[2]),
|
||||
mode='replicate')
|
||||
|
||||
if self.training:
|
||||
aux1 = torch.sigmoid(self.aux1_out(aux1))
|
||||
aux1 = F.pad(
|
||||
input=aux1,
|
||||
pad=(0, 0, 0, self.output_bin - aux1.size()[2]),
|
||||
mode='replicate')
|
||||
aux2 = torch.sigmoid(self.aux2_out(aux2))
|
||||
aux2 = F.pad(
|
||||
input=aux2,
|
||||
pad=(0, 0, 0, self.output_bin - aux2.size()[2]),
|
||||
mode='replicate')
|
||||
return mask * mix, aux1 * mix, aux2 * mix
|
||||
else:
|
||||
if aggressiveness:
|
||||
mask[:, :, :aggressiveness['split_bin']] = torch.pow(mask[:, :, :aggressiveness['split_bin']], 1 + aggressiveness['value'] / 3)
|
||||
mask[:, :, aggressiveness['split_bin']:] = torch.pow(mask[:, :, aggressiveness['split_bin']:], 1 + aggressiveness['value'])
|
||||
|
||||
return mask * mix
|
||||
|
||||
def predict(self, x_mag, aggressiveness=None):
|
||||
h = self.forward(x_mag, aggressiveness)
|
||||
|
||||
if self.offset > 0:
|
||||
h = h[:, :, :, self.offset:-self.offset]
|
||||
assert h.size()[3] > 0
|
||||
|
||||
return h
|
112
lib/nets_33966KB.py
Normal file
112
lib/nets_33966KB.py
Normal file
@ -0,0 +1,112 @@
|
||||
import torch
|
||||
from torch import nn
|
||||
import torch.nn.functional as F
|
||||
|
||||
from lib import layers_33966KB as layers
|
||||
|
||||
|
||||
class BaseASPPNet(nn.Module):
|
||||
|
||||
def __init__(self, nin, ch, dilations=(4, 8, 16, 32)):
|
||||
super(BaseASPPNet, self).__init__()
|
||||
self.enc1 = layers.Encoder(nin, ch, 3, 2, 1)
|
||||
self.enc2 = layers.Encoder(ch, ch * 2, 3, 2, 1)
|
||||
self.enc3 = layers.Encoder(ch * 2, ch * 4, 3, 2, 1)
|
||||
self.enc4 = layers.Encoder(ch * 4, ch * 8, 3, 2, 1)
|
||||
|
||||
self.aspp = layers.ASPPModule(ch * 8, ch * 16, dilations)
|
||||
|
||||
self.dec4 = layers.Decoder(ch * (8 + 16), ch * 8, 3, 1, 1)
|
||||
self.dec3 = layers.Decoder(ch * (4 + 8), ch * 4, 3, 1, 1)
|
||||
self.dec2 = layers.Decoder(ch * (2 + 4), ch * 2, 3, 1, 1)
|
||||
self.dec1 = layers.Decoder(ch * (1 + 2), ch, 3, 1, 1)
|
||||
|
||||
def __call__(self, x):
|
||||
h, e1 = self.enc1(x)
|
||||
h, e2 = self.enc2(h)
|
||||
h, e3 = self.enc3(h)
|
||||
h, e4 = self.enc4(h)
|
||||
|
||||
h = self.aspp(h)
|
||||
|
||||
h = self.dec4(h, e4)
|
||||
h = self.dec3(h, e3)
|
||||
h = self.dec2(h, e2)
|
||||
h = self.dec1(h, e1)
|
||||
|
||||
return h
|
||||
|
||||
|
||||
class CascadedASPPNet(nn.Module):
|
||||
|
||||
def __init__(self, n_fft):
|
||||
super(CascadedASPPNet, self).__init__()
|
||||
self.stg1_low_band_net = BaseASPPNet(2, 16)
|
||||
self.stg1_high_band_net = BaseASPPNet(2, 16)
|
||||
|
||||
self.stg2_bridge = layers.Conv2DBNActiv(18, 8, 1, 1, 0)
|
||||
self.stg2_full_band_net = BaseASPPNet(8, 16)
|
||||
|
||||
self.stg3_bridge = layers.Conv2DBNActiv(34, 16, 1, 1, 0)
|
||||
self.stg3_full_band_net = BaseASPPNet(16, 32)
|
||||
|
||||
self.out = nn.Conv2d(32, 2, 1, bias=False)
|
||||
self.aux1_out = nn.Conv2d(16, 2, 1, bias=False)
|
||||
self.aux2_out = nn.Conv2d(16, 2, 1, bias=False)
|
||||
|
||||
self.max_bin = n_fft // 2
|
||||
self.output_bin = n_fft // 2 + 1
|
||||
|
||||
self.offset = 128
|
||||
|
||||
def forward(self, x, aggressiveness=None):
|
||||
mix = x.detach()
|
||||
x = x.clone()
|
||||
|
||||
x = x[:, :, :self.max_bin]
|
||||
|
||||
bandw = x.size()[2] // 2
|
||||
aux1 = torch.cat([
|
||||
self.stg1_low_band_net(x[:, :, :bandw]),
|
||||
self.stg1_high_band_net(x[:, :, bandw:])
|
||||
], dim=2)
|
||||
|
||||
h = torch.cat([x, aux1], dim=1)
|
||||
aux2 = self.stg2_full_band_net(self.stg2_bridge(h))
|
||||
|
||||
h = torch.cat([x, aux1, aux2], dim=1)
|
||||
h = self.stg3_full_band_net(self.stg3_bridge(h))
|
||||
|
||||
mask = torch.sigmoid(self.out(h))
|
||||
mask = F.pad(
|
||||
input=mask,
|
||||
pad=(0, 0, 0, self.output_bin - mask.size()[2]),
|
||||
mode='replicate')
|
||||
|
||||
if self.training:
|
||||
aux1 = torch.sigmoid(self.aux1_out(aux1))
|
||||
aux1 = F.pad(
|
||||
input=aux1,
|
||||
pad=(0, 0, 0, self.output_bin - aux1.size()[2]),
|
||||
mode='replicate')
|
||||
aux2 = torch.sigmoid(self.aux2_out(aux2))
|
||||
aux2 = F.pad(
|
||||
input=aux2,
|
||||
pad=(0, 0, 0, self.output_bin - aux2.size()[2]),
|
||||
mode='replicate')
|
||||
return mask * mix, aux1 * mix, aux2 * mix
|
||||
else:
|
||||
if aggressiveness:
|
||||
mask[:, :, :aggressiveness['split_bin']] = torch.pow(mask[:, :, :aggressiveness['split_bin']], 1 + aggressiveness['value'] / 3)
|
||||
mask[:, :, aggressiveness['split_bin']:] = torch.pow(mask[:, :, aggressiveness['split_bin']:], 1 + aggressiveness['value'])
|
||||
|
||||
return mask * mix
|
||||
|
||||
def predict(self, x_mag, aggressiveness=None):
|
||||
h = self.forward(x_mag, aggressiveness)
|
||||
|
||||
if self.offset > 0:
|
||||
h = h[:, :, :, self.offset:-self.offset]
|
||||
assert h.size()[3] > 0
|
||||
|
||||
return h
|
@ -350,7 +350,7 @@ if __name__ == "__main__":
|
||||
mp = ModelParameters(args.model_params)
|
||||
|
||||
for d in range(len(mp.param['band']), 0, -1):
|
||||
print('band {}'.format(d), end=' ')
|
||||
print('Band(s) {}'.format(d), end=' ')
|
||||
|
||||
bp = mp.param['band'][d]
|
||||
|
||||
@ -368,7 +368,7 @@ if __name__ == "__main__":
|
||||
X_spec_s[d] = wave_to_spectrogram(X_wave[d], bp['hl'], bp['n_fft'], mp.param['mid_side'], mp.param['reverse'])
|
||||
y_spec_s[d] = wave_to_spectrogram(y_wave[d], bp['hl'], bp['n_fft'], mp.param['mid_side'], mp.param['reverse'])
|
||||
|
||||
print('ok')
|
||||
print('loaded!')
|
||||
|
||||
del X_wave, y_wave
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user