mirror of
https://github.com/RVC-Project/Retrieval-based-Voice-Conversion-WebUI.git
synced 2026-01-19 18:41:52 +00:00
Format code (#366)
Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
This commit is contained in:
committed by
GitHub
parent
e569477457
commit
e435b3bb8a
@@ -4,27 +4,29 @@ import torch.nn.functional as F
|
||||
|
||||
from uvr5_pack.lib_v5 import spec_utils
|
||||
|
||||
class Conv2DBNActiv(nn.Module):
|
||||
|
||||
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,
|
||||
nin,
|
||||
nout,
|
||||
kernel_size=ksize,
|
||||
stride=stride,
|
||||
padding=pad,
|
||||
dilation=dilation,
|
||||
bias=False),
|
||||
bias=False,
|
||||
),
|
||||
nn.BatchNorm2d(nout),
|
||||
activ()
|
||||
activ(),
|
||||
)
|
||||
|
||||
def __call__(self, x):
|
||||
return self.conv(x)
|
||||
|
||||
class Encoder(nn.Module):
|
||||
|
||||
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, stride, pad, activ=activ)
|
||||
@@ -38,15 +40,16 @@ class Encoder(nn.Module):
|
||||
|
||||
|
||||
class Decoder(nn.Module):
|
||||
|
||||
def __init__(self, nin, nout, ksize=3, stride=1, pad=1, activ=nn.ReLU, dropout=False):
|
||||
def __init__(
|
||||
self, nin, nout, ksize=3, stride=1, pad=1, activ=nn.ReLU, dropout=False
|
||||
):
|
||||
super(Decoder, self).__init__()
|
||||
self.conv1 = Conv2DBNActiv(nin, nout, ksize, 1, pad, activ=activ)
|
||||
# self.conv2 = Conv2DBNActiv(nout, 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)
|
||||
x = F.interpolate(x, scale_factor=2, mode="bilinear", align_corners=True)
|
||||
|
||||
if skip is not None:
|
||||
skip = spec_utils.crop_center(skip, x)
|
||||
@@ -62,12 +65,11 @@ class Decoder(nn.Module):
|
||||
|
||||
|
||||
class ASPPModule(nn.Module):
|
||||
|
||||
def __init__(self, nin, nout, dilations=(4, 8, 12), activ=nn.ReLU, dropout=False):
|
||||
super(ASPPModule, self).__init__()
|
||||
self.conv1 = nn.Sequential(
|
||||
nn.AdaptiveAvgPool2d((1, None)),
|
||||
Conv2DBNActiv(nin, nout, 1, 1, 0, activ=activ)
|
||||
Conv2DBNActiv(nin, nout, 1, 1, 0, activ=activ),
|
||||
)
|
||||
self.conv2 = Conv2DBNActiv(nin, nout, 1, 1, 0, activ=activ)
|
||||
self.conv3 = Conv2DBNActiv(
|
||||
@@ -84,7 +86,9 @@ class ASPPModule(nn.Module):
|
||||
|
||||
def forward(self, x):
|
||||
_, _, h, w = x.size()
|
||||
feat1 = F.interpolate(self.conv1(x), size=(h, w), mode='bilinear', align_corners=True)
|
||||
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)
|
||||
@@ -99,19 +103,14 @@ class ASPPModule(nn.Module):
|
||||
|
||||
|
||||
class LSTMModule(nn.Module):
|
||||
|
||||
def __init__(self, nin_conv, nin_lstm, nout_lstm):
|
||||
super(LSTMModule, self).__init__()
|
||||
self.conv = Conv2DBNActiv(nin_conv, 1, 1, 1, 0)
|
||||
self.lstm = nn.LSTM(
|
||||
input_size=nin_lstm,
|
||||
hidden_size=nout_lstm // 2,
|
||||
bidirectional=True
|
||||
input_size=nin_lstm, hidden_size=nout_lstm // 2, bidirectional=True
|
||||
)
|
||||
self.dense = nn.Sequential(
|
||||
nn.Linear(nout_lstm, nin_lstm),
|
||||
nn.BatchNorm1d(nin_lstm),
|
||||
nn.ReLU()
|
||||
nn.Linear(nout_lstm, nin_lstm), nn.BatchNorm1d(nin_lstm), nn.ReLU()
|
||||
)
|
||||
|
||||
def forward(self, x):
|
||||
|
||||
@@ -3,9 +3,11 @@ from torch import nn
|
||||
import torch.nn.functional as F
|
||||
from uvr5_pack.lib_v5 import layers_new as layers
|
||||
|
||||
class BaseNet(nn.Module):
|
||||
|
||||
def __init__(self, nin, nout, nin_lstm, nout_lstm, dilations=((4, 2), (8, 4), (12, 6))):
|
||||
class BaseNet(nn.Module):
|
||||
def __init__(
|
||||
self, nin, nout, nin_lstm, nout_lstm, dilations=((4, 2), (8, 4), (12, 6))
|
||||
):
|
||||
super(BaseNet, self).__init__()
|
||||
self.enc1 = layers.Conv2DBNActiv(nin, nout, 3, 1, 1)
|
||||
self.enc2 = layers.Encoder(nout, nout * 2, 3, 2, 1)
|
||||
@@ -38,8 +40,8 @@ class BaseNet(nn.Module):
|
||||
|
||||
return h
|
||||
|
||||
class CascadedNet(nn.Module):
|
||||
|
||||
class CascadedNet(nn.Module):
|
||||
def __init__(self, n_fft, nout=32, nout_lstm=128):
|
||||
super(CascadedNet, self).__init__()
|
||||
|
||||
@@ -50,24 +52,30 @@ class CascadedNet(nn.Module):
|
||||
|
||||
self.stg1_low_band_net = nn.Sequential(
|
||||
BaseNet(2, nout // 2, self.nin_lstm // 2, nout_lstm),
|
||||
layers.Conv2DBNActiv(nout // 2, nout // 4, 1, 1, 0)
|
||||
)
|
||||
|
||||
self.stg1_high_band_net = BaseNet(2, nout // 4, self.nin_lstm // 2, nout_lstm // 2)
|
||||
layers.Conv2DBNActiv(nout // 2, nout // 4, 1, 1, 0),
|
||||
)
|
||||
|
||||
self.stg1_high_band_net = BaseNet(
|
||||
2, nout // 4, self.nin_lstm // 2, nout_lstm // 2
|
||||
)
|
||||
|
||||
self.stg2_low_band_net = nn.Sequential(
|
||||
BaseNet(nout // 4 + 2, nout, self.nin_lstm // 2, nout_lstm),
|
||||
layers.Conv2DBNActiv(nout, nout // 2, 1, 1, 0)
|
||||
)
|
||||
self.stg2_high_band_net = BaseNet(nout // 4 + 2, nout // 2, self.nin_lstm // 2, nout_lstm // 2)
|
||||
layers.Conv2DBNActiv(nout, nout // 2, 1, 1, 0),
|
||||
)
|
||||
self.stg2_high_band_net = BaseNet(
|
||||
nout // 4 + 2, nout // 2, self.nin_lstm // 2, nout_lstm // 2
|
||||
)
|
||||
|
||||
self.stg3_full_band_net = BaseNet(3 * nout // 4 + 2, nout, self.nin_lstm, nout_lstm)
|
||||
self.stg3_full_band_net = BaseNet(
|
||||
3 * nout // 4 + 2, nout, self.nin_lstm, nout_lstm
|
||||
)
|
||||
|
||||
self.out = nn.Conv2d(nout, 2, 1, bias=False)
|
||||
self.aux_out = nn.Conv2d(3 * nout // 4, 2, 1, bias=False)
|
||||
|
||||
def forward(self, x):
|
||||
x = x[:, :, :self.max_bin]
|
||||
x = x[:, :, : self.max_bin]
|
||||
|
||||
bandw = x.size()[2] // 2
|
||||
l1_in = x[:, :, :bandw]
|
||||
@@ -89,7 +97,7 @@ class CascadedNet(nn.Module):
|
||||
mask = F.pad(
|
||||
input=mask,
|
||||
pad=(0, 0, 0, self.output_bin - mask.size()[2]),
|
||||
mode='replicate'
|
||||
mode="replicate",
|
||||
)
|
||||
|
||||
if self.training:
|
||||
@@ -98,7 +106,7 @@ class CascadedNet(nn.Module):
|
||||
aux = F.pad(
|
||||
input=aux,
|
||||
pad=(0, 0, 0, self.output_bin - aux.size()[2]),
|
||||
mode='replicate'
|
||||
mode="replicate",
|
||||
)
|
||||
return mask, aux
|
||||
else:
|
||||
@@ -108,17 +116,17 @@ class CascadedNet(nn.Module):
|
||||
mask = self.forward(x)
|
||||
|
||||
if self.offset > 0:
|
||||
mask = mask[:, :, :, self.offset:-self.offset]
|
||||
mask = mask[:, :, :, self.offset : -self.offset]
|
||||
assert mask.size()[3] > 0
|
||||
|
||||
return mask
|
||||
|
||||
def predict(self, x,aggressiveness=None):
|
||||
def predict(self, x, aggressiveness=None):
|
||||
mask = self.forward(x)
|
||||
pred_mag = x * mask
|
||||
|
||||
if self.offset > 0:
|
||||
pred_mag = pred_mag[:, :, :, self.offset:-self.offset]
|
||||
pred_mag = pred_mag[:, :, :, self.offset : -self.offset]
|
||||
assert pred_mag.size()[3] > 0
|
||||
|
||||
return pred_mag
|
||||
|
||||
Reference in New Issue
Block a user