From 7572c4491175aeb9648e20cda1ecfa0811c452bf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=BA=90=E6=96=87=E9=9B=A8?= <41315874+fumiama@users.noreply.github.com> Date: Mon, 10 Jun 2024 22:22:58 +0900 Subject: [PATCH] optimize(rvc): move . into layers --- infer/lib/infer_pack/models_onnx.py | 6 +++--- infer/lib/jit/synthesizer.py | 2 +- infer/modules/train/train.py | 8 ++++---- rvc/layers/__init__.py | 0 rvc/{ => layers}/attentions.py | 0 rvc/{ => layers}/discriminators.py | 0 rvc/{ => layers}/encoders.py | 0 rvc/{ => layers}/generators.py | 0 rvc/{ => layers}/norms.py | 0 rvc/{ => layers}/nsf.py | 0 rvc/{ => layers}/residuals.py | 0 rvc/{ => layers}/synthesizers.py | 11 ++++++----- rvc/{ => layers}/transforms.py | 0 rvc/{ => layers}/utils.py | 0 rvc/onnx/infer.py | 6 +++--- tools/cmd/infer-pm-index256.py | 2 +- tools/onnx/infer.py | 2 +- 17 files changed, 19 insertions(+), 18 deletions(-) create mode 100644 rvc/layers/__init__.py rename rvc/{ => layers}/attentions.py (100%) rename rvc/{ => layers}/discriminators.py (100%) rename rvc/{ => layers}/encoders.py (100%) rename rvc/{ => layers}/generators.py (100%) rename rvc/{ => layers}/norms.py (100%) rename rvc/{ => layers}/nsf.py (100%) rename rvc/{ => layers}/residuals.py (100%) rename rvc/{ => layers}/synthesizers.py (98%) rename rvc/{ => layers}/transforms.py (100%) rename rvc/{ => layers}/utils.py (100%) diff --git a/infer/lib/infer_pack/models_onnx.py b/infer/lib/infer_pack/models_onnx.py index cad9e24..e5778e6 100644 --- a/infer/lib/infer_pack/models_onnx.py +++ b/infer/lib/infer_pack/models_onnx.py @@ -1,9 +1,9 @@ import torch from torch import nn -from rvc.nsf import NSFGenerator -from rvc.encoders import TextEncoder, PosteriorEncoder -from rvc.residuals import ResidualCouplingBlock +from rvc.layers.nsf import NSFGenerator +from rvc.layers.encoders import TextEncoder, PosteriorEncoder +from rvc.layers.residuals import ResidualCouplingBlock class SynthesizerTrnMsNSFsidM(nn.Module): diff --git a/infer/lib/jit/synthesizer.py b/infer/lib/jit/synthesizer.py index 02e90bb..9a8bab1 100644 --- a/infer/lib/jit/synthesizer.py +++ b/infer/lib/jit/synthesizer.py @@ -1,6 +1,6 @@ import torch -from rvc.synthesizers import SynthesizerTrnMsNSFsid +from rvc.layers.synthesizers import SynthesizerTrnMsNSFsid def get_synthesizer_ckpt(cpt, device=torch.device("cpu")): diff --git a/infer/modules/train/train.py b/infer/modules/train/train.py index 85abb25..d16e40e 100644 --- a/infer/modules/train/train.py +++ b/infer/modules/train/train.py @@ -56,15 +56,15 @@ from infer.lib.train.data_utils import ( TextAudioLoaderMultiNSFsid, ) -from rvc.discriminators import MultiPeriodDiscriminator +from rvc.layers.discriminators import MultiPeriodDiscriminator if hps.version == "v1": - from rvc.synthesizers import SynthesizerTrnMs256NSFsid as RVC_Model_f0 - from rvc.synthesizers import ( + from rvc.layers.synthesizers import SynthesizerTrnMs256NSFsid as RVC_Model_f0 + from rvc.layers.synthesizers import ( SynthesizerTrnMs256NSFsid_nono as RVC_Model_nof0, ) else: - from rvc.synthesizers import ( + from rvc.layers.synthesizers import ( SynthesizerTrnMs768NSFsid as RVC_Model_f0, SynthesizerTrnMs768NSFsid_nono as RVC_Model_nof0, ) diff --git a/rvc/layers/__init__.py b/rvc/layers/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/rvc/attentions.py b/rvc/layers/attentions.py similarity index 100% rename from rvc/attentions.py rename to rvc/layers/attentions.py diff --git a/rvc/discriminators.py b/rvc/layers/discriminators.py similarity index 100% rename from rvc/discriminators.py rename to rvc/layers/discriminators.py diff --git a/rvc/encoders.py b/rvc/layers/encoders.py similarity index 100% rename from rvc/encoders.py rename to rvc/layers/encoders.py diff --git a/rvc/generators.py b/rvc/layers/generators.py similarity index 100% rename from rvc/generators.py rename to rvc/layers/generators.py diff --git a/rvc/norms.py b/rvc/layers/norms.py similarity index 100% rename from rvc/norms.py rename to rvc/layers/norms.py diff --git a/rvc/nsf.py b/rvc/layers/nsf.py similarity index 100% rename from rvc/nsf.py rename to rvc/layers/nsf.py diff --git a/rvc/residuals.py b/rvc/layers/residuals.py similarity index 100% rename from rvc/residuals.py rename to rvc/layers/residuals.py diff --git a/rvc/synthesizers.py b/rvc/layers/synthesizers.py similarity index 98% rename from rvc/synthesizers.py rename to rvc/layers/synthesizers.py index 7024813..e4a178e 100644 --- a/rvc/synthesizers.py +++ b/rvc/layers/synthesizers.py @@ -3,14 +3,15 @@ from typing import Optional, List, Union import torch from torch import nn -from rvc.residuals import ResidualCouplingBlock -from rvc.utils import ( + +from .encoders import TextEncoder, PosteriorEncoder +from .generators import Generator +from .nsf import NSFGenerator +from .residuals import ResidualCouplingBlock +from .utils import ( slice_on_last_dim, rand_slice_segments_on_last_dim, ) -from rvc.encoders import TextEncoder, PosteriorEncoder -from rvc.generators import Generator -from rvc.nsf import NSFGenerator class SynthesizerTrnMsNSFsid(nn.Module): diff --git a/rvc/transforms.py b/rvc/layers/transforms.py similarity index 100% rename from rvc/transforms.py rename to rvc/layers/transforms.py diff --git a/rvc/utils.py b/rvc/layers/utils.py similarity index 100% rename from rvc/utils.py rename to rvc/layers/utils.py diff --git a/rvc/onnx/infer.py b/rvc/onnx/infer.py index c9576a9..52de675 100644 --- a/rvc/onnx/infer.py +++ b/rvc/onnx/infer.py @@ -75,7 +75,7 @@ class RVC(Model): self.vec_model = ContentVec(vec_path, device) self.hop_len = hop_len - def inference( + def infer( self, wav: np.ndarray[typing.Any, np.dtype], wav_sr: int, @@ -119,7 +119,7 @@ class RVC(Model): rnd = np.random.randn(1, 192, hubert_length).astype(np.float32) hubert_length = np.array([hubert_length]).astype(np.int64) - out_wav = self.__forward( + out_wav = self.forward( hubert, hubert_length, pitch, pitchf, ds, rnd ).squeeze() @@ -127,7 +127,7 @@ class RVC(Model): return out_wav[0:org_length] - def __forward( + def forward( self, hubert: np.ndarray[typing.Any, np.dtype[np.float32]], hubert_length: int, diff --git a/tools/cmd/infer-pm-index256.py b/tools/cmd/infer-pm-index256.py index 5a56cb5..a990554 100644 --- a/tools/cmd/infer-pm-index256.py +++ b/tools/cmd/infer-pm-index256.py @@ -24,7 +24,7 @@ from fairseq import checkpoint_utils # from models import SynthesizerTrn256#hifigan_nonsf # from lib.infer_pack.models import SynthesizerTrn256NSF as SynthesizerTrn256#hifigan_nsf -from rvc.synthesizers import ( +from rvc.layers.synthesizers import ( SynthesizerTrnMs256NSFsid as SynthesizerTrn256, ) # hifigan_nsf from scipy.io import wavfile diff --git a/tools/onnx/infer.py b/tools/onnx/infer.py index bf23b5c..b982d63 100644 --- a/tools/onnx/infer.py +++ b/tools/onnx/infer.py @@ -19,6 +19,6 @@ model = RVC( wav, sr = librosa.load(wav_path, sr=sampling_rate) -audio = model.inference(wav, sr, sid, f0_method=f0_method, f0_up_key=f0_up_key) +audio = model.infer(wav, sr, sid, f0_method=f0_method, f0_up_key=f0_up_key) soundfile.write(out_path, audio, sampling_rate)