Spaces:
Sleeping
Sleeping
update: delete monotonic_align
Browse files- Dockerfile +0 -4
- Dockerfile_GPU +0 -4
- bert_vits2/models.py +2 -47
- bert_vits2/monotonic_align/__init__.py +0 -19
- bert_vits2/monotonic_align/core.c +0 -0
- bert_vits2/monotonic_align/core.pyx +0 -42
- bert_vits2/monotonic_align/monotonic_align/monotonic_align +0 -0
- bert_vits2/monotonic_align/setup.py +0 -9
Dockerfile
CHANGED
|
@@ -29,10 +29,6 @@ RUN pip install torch --index-url https://download.pytorch.org/whl/cpu --no-cach
|
|
| 29 |
|
| 30 |
RUN pip install -r requirements.txt --no-cache-dir
|
| 31 |
|
| 32 |
-
RUN cd /app/bert_vits2/monotonic_align && \
|
| 33 |
-
python setup.py build_ext --inplace && \
|
| 34 |
-
cd /app
|
| 35 |
-
|
| 36 |
RUN pip install gunicorn --no-cache-dir
|
| 37 |
|
| 38 |
EXPOSE 23456
|
|
|
|
| 29 |
|
| 30 |
RUN pip install -r requirements.txt --no-cache-dir
|
| 31 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 32 |
RUN pip install gunicorn --no-cache-dir
|
| 33 |
|
| 34 |
EXPOSE 23456
|
Dockerfile_GPU
CHANGED
|
@@ -29,10 +29,6 @@ RUN pip install torch --index-url https://download.pytorch.org/whl/cu117 --no-ca
|
|
| 29 |
|
| 30 |
RUN pip install -r requirements.txt --no-cache-dir
|
| 31 |
|
| 32 |
-
RUN cd /app/bert_vits2/monotonic_align && \
|
| 33 |
-
python setup.py build_ext --inplace && \
|
| 34 |
-
cd /app
|
| 35 |
-
|
| 36 |
RUN pip install gunicorn --no-cache-dir
|
| 37 |
|
| 38 |
EXPOSE 23456
|
|
|
|
| 29 |
|
| 30 |
RUN pip install -r requirements.txt --no-cache-dir
|
| 31 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 32 |
RUN pip install gunicorn --no-cache-dir
|
| 33 |
|
| 34 |
EXPOSE 23456
|
bert_vits2/models.py
CHANGED
|
@@ -6,7 +6,6 @@ from torch.nn import functional as F
|
|
| 6 |
from bert_vits2 import commons
|
| 7 |
from bert_vits2 import modules
|
| 8 |
from bert_vits2 import attentions
|
| 9 |
-
from bert_vits2 import monotonic_align
|
| 10 |
|
| 11 |
from torch.nn import Conv1d, ConvTranspose1d, AvgPool1d, Conv2d
|
| 12 |
from torch.nn.utils import weight_norm, remove_weight_norm, spectral_norm
|
|
@@ -564,8 +563,8 @@ class ReferenceEncoder(nn.Module):
|
|
| 564 |
|
| 565 |
class SynthesizerTrn(nn.Module):
|
| 566 |
"""
|
| 567 |
-
|
| 568 |
-
|
| 569 |
|
| 570 |
def __init__(self,
|
| 571 |
n_vocab,
|
|
@@ -649,50 +648,6 @@ class SynthesizerTrn(nn.Module):
|
|
| 649 |
else:
|
| 650 |
self.ref_enc = ReferenceEncoder(spec_channels, gin_channels)
|
| 651 |
|
| 652 |
-
def forward(self, x, x_lengths, y, y_lengths, sid, tone, language, bert):
|
| 653 |
-
if self.n_speakers > 0:
|
| 654 |
-
g = self.emb_g(sid).unsqueeze(-1) # [b, h, 1]
|
| 655 |
-
else:
|
| 656 |
-
g = self.ref_enc(y.transpose(1, 2)).unsqueeze(-1)
|
| 657 |
-
x, m_p, logs_p, x_mask = self.enc_p(x, x_lengths, tone, language, bert, g=g)
|
| 658 |
-
z, m_q, logs_q, y_mask = self.enc_q(y, y_lengths, g=g)
|
| 659 |
-
z_p = self.flow(z, y_mask, g=g)
|
| 660 |
-
|
| 661 |
-
with torch.no_grad():
|
| 662 |
-
# negative cross-entropy
|
| 663 |
-
s_p_sq_r = torch.exp(-2 * logs_p) # [b, d, t]
|
| 664 |
-
neg_cent1 = torch.sum(-0.5 * math.log(2 * math.pi) - logs_p, [1], keepdim=True) # [b, 1, t_s]
|
| 665 |
-
neg_cent2 = torch.matmul(-0.5 * (z_p ** 2).transpose(1, 2),
|
| 666 |
-
s_p_sq_r) # [b, t_t, d] x [b, d, t_s] = [b, t_t, t_s]
|
| 667 |
-
neg_cent3 = torch.matmul(z_p.transpose(1, 2), (m_p * s_p_sq_r)) # [b, t_t, d] x [b, d, t_s] = [b, t_t, t_s]
|
| 668 |
-
neg_cent4 = torch.sum(-0.5 * (m_p ** 2) * s_p_sq_r, [1], keepdim=True) # [b, 1, t_s]
|
| 669 |
-
neg_cent = neg_cent1 + neg_cent2 + neg_cent3 + neg_cent4
|
| 670 |
-
if self.use_noise_scaled_mas:
|
| 671 |
-
epsilon = torch.std(neg_cent) * torch.randn_like(neg_cent) * self.current_mas_noise_scale
|
| 672 |
-
neg_cent = neg_cent + epsilon
|
| 673 |
-
|
| 674 |
-
attn_mask = torch.unsqueeze(x_mask, 2) * torch.unsqueeze(y_mask, -1)
|
| 675 |
-
attn = monotonic_align.maximum_path(neg_cent, attn_mask.squeeze(1)).unsqueeze(1).detach()
|
| 676 |
-
|
| 677 |
-
w = attn.sum(2)
|
| 678 |
-
|
| 679 |
-
l_length_sdp = self.sdp(x, x_mask, w, g=g)
|
| 680 |
-
l_length_sdp = l_length_sdp / torch.sum(x_mask)
|
| 681 |
-
|
| 682 |
-
logw_ = torch.log(w + 1e-6) * x_mask
|
| 683 |
-
logw = self.dp(x, x_mask, g=g)
|
| 684 |
-
l_length_dp = torch.sum((logw - logw_) ** 2, [1, 2]) / torch.sum(x_mask) # for averaging
|
| 685 |
-
|
| 686 |
-
l_length = l_length_dp + l_length_sdp
|
| 687 |
-
|
| 688 |
-
# expand prior
|
| 689 |
-
m_p = torch.matmul(attn.squeeze(1), m_p.transpose(1, 2)).transpose(1, 2)
|
| 690 |
-
logs_p = torch.matmul(attn.squeeze(1), logs_p.transpose(1, 2)).transpose(1, 2)
|
| 691 |
-
|
| 692 |
-
z_slice, ids_slice = commons.rand_slice_segments(z, y_lengths, self.segment_size)
|
| 693 |
-
o = self.dec(z_slice, g=g)
|
| 694 |
-
return o, l_length, attn, ids_slice, x_mask, y_mask, (z, z_p, m_p, logs_p, m_q, logs_q), (x, logw, logw_)
|
| 695 |
-
|
| 696 |
def infer(self, x, x_lengths, sid, tone, language, bert, noise_scale=.667, length_scale=1, noise_scale_w=0.8,
|
| 697 |
max_len=None, sdp_ratio=0, y=None):
|
| 698 |
# x, m_p, logs_p, x_mask = self.enc_p(x, x_lengths, tone, language, bert)
|
|
|
|
| 6 |
from bert_vits2 import commons
|
| 7 |
from bert_vits2 import modules
|
| 8 |
from bert_vits2 import attentions
|
|
|
|
| 9 |
|
| 10 |
from torch.nn import Conv1d, ConvTranspose1d, AvgPool1d, Conv2d
|
| 11 |
from torch.nn.utils import weight_norm, remove_weight_norm, spectral_norm
|
|
|
|
| 563 |
|
| 564 |
class SynthesizerTrn(nn.Module):
|
| 565 |
"""
|
| 566 |
+
Synthesizer for Training
|
| 567 |
+
"""
|
| 568 |
|
| 569 |
def __init__(self,
|
| 570 |
n_vocab,
|
|
|
|
| 648 |
else:
|
| 649 |
self.ref_enc = ReferenceEncoder(spec_channels, gin_channels)
|
| 650 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 651 |
def infer(self, x, x_lengths, sid, tone, language, bert, noise_scale=.667, length_scale=1, noise_scale_w=0.8,
|
| 652 |
max_len=None, sdp_ratio=0, y=None):
|
| 653 |
# x, m_p, logs_p, x_mask = self.enc_p(x, x_lengths, tone, language, bert)
|
bert_vits2/monotonic_align/__init__.py
DELETED
|
@@ -1,19 +0,0 @@
|
|
| 1 |
-
import numpy as np
|
| 2 |
-
import torch
|
| 3 |
-
from .monotonic_align.core import maximum_path_c
|
| 4 |
-
|
| 5 |
-
|
| 6 |
-
def maximum_path(neg_cent, mask):
|
| 7 |
-
""" Cython optimized version.
|
| 8 |
-
neg_cent: [b, t_t, t_s]
|
| 9 |
-
mask: [b, t_t, t_s]
|
| 10 |
-
"""
|
| 11 |
-
device = neg_cent.device
|
| 12 |
-
dtype = neg_cent.dtype
|
| 13 |
-
neg_cent = neg_cent.data.cpu().numpy().astype(np.float32)
|
| 14 |
-
path = np.zeros(neg_cent.shape, dtype=np.int32)
|
| 15 |
-
|
| 16 |
-
t_t_max = mask.sum(1)[:, 0].data.cpu().numpy().astype(np.int32)
|
| 17 |
-
t_s_max = mask.sum(2)[:, 0].data.cpu().numpy().astype(np.int32)
|
| 18 |
-
maximum_path_c(path, neg_cent, t_t_max, t_s_max)
|
| 19 |
-
return torch.from_numpy(path).to(device=device, dtype=dtype)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
bert_vits2/monotonic_align/core.c
DELETED
|
The diff for this file is too large to render.
See raw diff
|
|
|
bert_vits2/monotonic_align/core.pyx
DELETED
|
@@ -1,42 +0,0 @@
|
|
| 1 |
-
cimport cython
|
| 2 |
-
from cython.parallel import prange
|
| 3 |
-
|
| 4 |
-
|
| 5 |
-
@cython.boundscheck(False)
|
| 6 |
-
@cython.wraparound(False)
|
| 7 |
-
cdef void maximum_path_each(int[:,::1] path, float[:,::1] value, int t_y, int t_x, float max_neg_val=-1e9) nogil:
|
| 8 |
-
cdef int x
|
| 9 |
-
cdef int y
|
| 10 |
-
cdef float v_prev
|
| 11 |
-
cdef float v_cur
|
| 12 |
-
cdef float tmp
|
| 13 |
-
cdef int index = t_x - 1
|
| 14 |
-
|
| 15 |
-
for y in range(t_y):
|
| 16 |
-
for x in range(max(0, t_x + y - t_y), min(t_x, y + 1)):
|
| 17 |
-
if x == y:
|
| 18 |
-
v_cur = max_neg_val
|
| 19 |
-
else:
|
| 20 |
-
v_cur = value[y-1, x]
|
| 21 |
-
if x == 0:
|
| 22 |
-
if y == 0:
|
| 23 |
-
v_prev = 0.
|
| 24 |
-
else:
|
| 25 |
-
v_prev = max_neg_val
|
| 26 |
-
else:
|
| 27 |
-
v_prev = value[y-1, x-1]
|
| 28 |
-
value[y, x] += max(v_prev, v_cur)
|
| 29 |
-
|
| 30 |
-
for y in range(t_y - 1, -1, -1):
|
| 31 |
-
path[y, index] = 1
|
| 32 |
-
if index != 0 and (index == y or value[y-1, index] < value[y-1, index-1]):
|
| 33 |
-
index = index - 1
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
@cython.boundscheck(False)
|
| 37 |
-
@cython.wraparound(False)
|
| 38 |
-
cpdef void maximum_path_c(int[:,:,::1] paths, float[:,:,::1] values, int[::1] t_ys, int[::1] t_xs) nogil:
|
| 39 |
-
cdef int b = paths.shape[0]
|
| 40 |
-
cdef int i
|
| 41 |
-
for i in prange(b, nogil=True):
|
| 42 |
-
maximum_path_each(paths[i], values[i], t_ys[i], t_xs[i])
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
bert_vits2/monotonic_align/monotonic_align/monotonic_align
DELETED
|
File without changes
|
bert_vits2/monotonic_align/setup.py
DELETED
|
@@ -1,9 +0,0 @@
|
|
| 1 |
-
from distutils.core import setup
|
| 2 |
-
from Cython.Build import cythonize
|
| 3 |
-
import numpy
|
| 4 |
-
|
| 5 |
-
setup(
|
| 6 |
-
name = 'monotonic_align',
|
| 7 |
-
ext_modules = cythonize("core.pyx"),
|
| 8 |
-
include_dirs=[numpy.get_include()]
|
| 9 |
-
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|