Skip to content

Commit

Permalink
Refactor Project to 3 parts: Models, Control, Data
Browse files Browse the repository at this point in the history
Need readme
  • Loading branch information
babysor committed Dec 3, 2022
1 parent b402f9d commit 74a3fc9
Show file tree
Hide file tree
Showing 179 changed files with 196 additions and 27,923 deletions.
6 changes: 3 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@
*.bcf
*.toc
*.sh
*/saved_models
!vocoder/saved_models/pretrained/**
!encoder/saved_models/pretrained.pt
data/ckpt
!data/ckpt/vocoder/pretrained/**
!data/ckpt/encoder/pretrained.pt
wavs
log
8 changes: 4 additions & 4 deletions archived_untest_files/demo_cli.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
from encoder.params_model import model_embedding_size as speaker_embedding_size
from models.encoder.params_model import model_embedding_size as speaker_embedding_size
from utils.argutils import print_args
from utils.modelutils import check_model_paths
from synthesizer.inference import Synthesizer
from encoder import inference as encoder
from vocoder import inference as vocoder
from models.synthesizer.inference import Synthesizer
from models.encoder import inference as encoder
from models.vocoder import inference as vocoder
from pathlib import Path
import numpy as np
import soundfile as sf
Expand Down
File renamed without changes.
9 changes: 6 additions & 3 deletions encoder_preprocess.py → control/cli/encoder_preprocess.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
from encoder.preprocess import preprocess_librispeech, preprocess_voxceleb1, preprocess_voxceleb2, preprocess_aidatatang_200zh
from utils.argutils import print_args
from pathlib import Path
import argparse
from pathlib import Path

from models.encoder.preprocess import (preprocess_aidatatang_200zh,
preprocess_librispeech, preprocess_voxceleb1,
preprocess_voxceleb2)
from utils.argutils import print_args

if __name__ == "__main__":
class MyFormatter(argparse.ArgumentDefaultsHelpFormatter, argparse.RawDescriptionHelpFormatter):
Expand Down
2 changes: 1 addition & 1 deletion encoder_train.py → control/cli/encoder_train.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from utils.argutils import print_args
from encoder.train import train
from models.encoder.train import train
from pathlib import Path
import argparse

Expand Down
2 changes: 1 addition & 1 deletion ppg2mel_train.py → control/cli/ppg2mel_train.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import argparse
import numpy as np
from utils.load_yaml import HpsYaml
from ppg2mel.train.train_linglf02mel_seq2seq_oneshotvc import Solver
from models.ppg2mel.train.train_linglf02mel_seq2seq_oneshotvc import Solver

# For reproducibility, comment these may speed up training
torch.backends.cudnn.deterministic = True
Expand Down
2 changes: 1 addition & 1 deletion pre4ppg.py → control/cli/pre4ppg.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from pathlib import Path
import argparse

from ppg2mel.preprocess import preprocess_dataset
from models.ppg2mel.preprocess import preprocess_dataset
from pathlib import Path
import argparse

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from synthesizer.preprocess import preprocess_dataset
from synthesizer.hparams import hparams
from models.synthesizer.preprocess import preprocess_dataset
from models.synthesizer.hparams import hparams
from utils.argutils import print_args
from pathlib import Path
import argparse
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from synthesizer.preprocess import create_embeddings
from models.synthesizer.preprocess import create_embeddings
from utils.argutils import print_args
from pathlib import Path
import argparse
Expand Down
4 changes: 2 additions & 2 deletions synthesizer_train.py → control/cli/synthesizer_train.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from synthesizer.hparams import hparams
from synthesizer.train import train
from models.synthesizer.hparams import hparams
from models.synthesizer.train import train
from utils.argutils import print_args
import argparse

Expand Down
4 changes: 2 additions & 2 deletions vocoder_preprocess.py → control/cli/vocoder_preprocess.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from synthesizer.synthesize import run_synthesis
from synthesizer.hparams import hparams
from models.synthesizer.synthesize import run_synthesis
from models.synthesizer.hparams import hparams
from utils.argutils import print_args
import argparse
import os
Expand Down
6 changes: 3 additions & 3 deletions vocoder_train.py → control/cli/vocoder_train.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from utils.argutils import print_args
from vocoder.wavernn.train import train
from vocoder.hifigan.train import train as train_hifigan
from vocoder.fregan.train import train as train_fregan
from models.vocoder.wavernn.train import train
from models.vocoder.hifigan.train import train as train_hifigan
from models.vocoder.fregan.train import train as train_fregan
from utils.util import AttrDict
from pathlib import Path
import argparse
Expand Down
File renamed without changes.
18 changes: 9 additions & 9 deletions mkgui/app.py → control/mkgui/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,22 @@
import os
from pathlib import Path
from enum import Enum
from encoder import inference as encoder
from models.encoder import inference as encoder
import librosa
from scipy.io.wavfile import write
import re
import numpy as np
from mkgui.base.components.types import FileContent
from vocoder.hifigan import inference as gan_vocoder
from synthesizer.inference import Synthesizer
from control.mkgui.base.components.types import FileContent
from models.vocoder.hifigan import inference as gan_vocoder
from models.synthesizer.inference import Synthesizer
from typing import Any, Tuple
import matplotlib.pyplot as plt

# Constants
AUDIO_SAMPLES_DIR = f"samples{os.sep}"
SYN_MODELS_DIRT = f"synthesizer{os.sep}saved_models"
ENC_MODELS_DIRT = f"encoder{os.sep}saved_models"
VOC_MODELS_DIRT = f"vocoder{os.sep}saved_models"
AUDIO_SAMPLES_DIR = f"data{os.sep}samples{os.sep}"
SYN_MODELS_DIRT = f"data{os.sep}ckpt{os.sep}synthesizer"
ENC_MODELS_DIRT = f"data{os.sep}ckpt{os.sep}encoder"
VOC_MODELS_DIRT = f"data{os.sep}ckpt{os.sep}vocoder"
TEMP_SOURCE_AUDIO = f"wavs{os.sep}temp_source.wav"
TEMP_RESULT_AUDIO = f"wavs{os.sep}temp_result.wav"
if not os.path.isdir("wavs"):
Expand All @@ -31,7 +31,7 @@
synthesizers = Enum('synthesizers', list((file.name, file) for file in Path(SYN_MODELS_DIRT).glob("**/*.pt")))
print("Loaded synthesizer models: " + str(len(synthesizers)))
else:
raise Exception(f"Model folder {SYN_MODELS_DIRT} doesn't exist.")
raise Exception(f"Model folder {SYN_MODELS_DIRT} doesn't exist. 请将模型文件位置移动到上述位置中进行重试!")

if os.path.isdir(ENC_MODELS_DIRT):
encoders = Enum('encoders', list((file.name, file) for file in Path(ENC_MODELS_DIRT).glob("**/*.pt")))
Expand Down
38 changes: 19 additions & 19 deletions mkgui/app_vc.py → control/mkgui/app_vc.py
Original file line number Diff line number Diff line change
@@ -1,27 +1,26 @@
from synthesizer.inference import Synthesizer
from pydantic import BaseModel, Field
from encoder import inference as speacker_encoder
import torch
import os
from pathlib import Path
from enum import Enum
import ppg_extractor as Extractor
import ppg2mel as Convertor
import librosa
from scipy.io.wavfile import write
import re
import numpy as np
from mkgui.base.components.types import FileContent
from vocoder.hifigan import inference as gan_vocoder
from pathlib import Path
from typing import Any, Tuple

import librosa
import matplotlib.pyplot as plt
import torch
from pydantic import BaseModel, Field
from scipy.io.wavfile import write

import models.ppg2mel as Convertor
import models.ppg_extractor as Extractor
from control.mkgui.base.components.types import FileContent
from models.encoder import inference as speacker_encoder
from models.synthesizer.inference import Synthesizer
from models.vocoder.hifigan import inference as gan_vocoder

# Constants
AUDIO_SAMPLES_DIR = f'samples{os.sep}'
EXT_MODELS_DIRT = f'ppg_extractor{os.sep}saved_models'
CONV_MODELS_DIRT = f'ppg2mel{os.sep}saved_models'
VOC_MODELS_DIRT = f'vocoder{os.sep}saved_models'
AUDIO_SAMPLES_DIR = f'data{os.sep}samples{os.sep}'
EXT_MODELS_DIRT = f'data{os.sep}ckpt{os.sep}ppg_extractor'
CONV_MODELS_DIRT = f'data{os.sep}ckpt{os.sep}ppg2mel'
VOC_MODELS_DIRT = f'data{os.sep}ckpt{os.sep}vocoder'
TEMP_SOURCE_AUDIO = f'wavs{os.sep}temp_source.wav'
TEMP_TARGET_AUDIO = f'wavs{os.sep}temp_target.wav'
TEMP_RESULT_AUDIO = f'wavs{os.sep}temp_result.wav'
Expand Down Expand Up @@ -132,9 +131,10 @@ def convert(input: Input) -> Output:

ppg = extractor.extract_from_wav(src_wav)
# Import necessary dependency of Voice Conversion
from utils.f0_utils import compute_f0, f02lf0, compute_mean_std, get_converted_lf0uv
from utils.f0_utils import (compute_f0, compute_mean_std, f02lf0,
get_converted_lf0uv)
ref_lf0_mean, ref_lf0_std = compute_mean_std(f02lf0(compute_f0(ref_wav)))
speacker_encoder.load_model(Path(f"encoder{os.sep}saved_models{os.sep}pretrained_bak_5805000.pt"))
speacker_encoder.load_model(Path(f"data{os.sep}ckpt{os.sep}encoder{os.sep}pretrained_bak_5805000.pt"))
embed = speacker_encoder.embed_utterance(ref_wav)
lf0_uv = get_converted_lf0uv(src_wav, ref_lf0_mean, ref_lf0_std, convert=True)
min_len = min(ppg.shape[1], len(lf0_uv))
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,13 @@
from loguru import logger
from pydantic import BaseModel, ValidationError, parse_obj_as

from mkgui.base import Opyrator
from mkgui.base.core import name_to_title
from mkgui.base.ui import schema_utils
from mkgui.base.ui.streamlit_utils import CUSTOM_STREAMLIT_CSS
from control.mkgui.base import Opyrator
from control.mkgui.base.core import name_to_title
from . import schema_utils
from .streamlit_utils import CUSTOM_STREAMLIT_CSS

STREAMLIT_RUNNER_SNIPPET = """
from mkgui.base.ui import render_streamlit_ui
from mkgui.base import Opyrator
from control.mkgui.base.ui import render_streamlit_ui
import streamlit as st
Expand Down Expand Up @@ -807,18 +806,18 @@ def _render_list_output(self, streamlit: st, output_data: List) -> None:

def getOpyrator(mode: str) -> Opyrator:
if mode == None or mode.startswith('VC'):
from mkgui.app_vc import convert
from control.mkgui.app_vc import convert
return Opyrator(convert)
if mode == None or mode.startswith('预处理'):
from mkgui.preprocess import preprocess
from control.mkgui.preprocess import preprocess
return Opyrator(preprocess)
if mode == None or mode.startswith('模型训练'):
from mkgui.train import train
from control.mkgui.train import train
return Opyrator(train)
if mode == None or mode.startswith('模型训练(VC)'):
from mkgui.train_vc import train_vc
from control.mkgui.train_vc import train_vc
return Opyrator(train_vc)
from mkgui.app import synthesize
from control.mkgui.app import synthesize
return Opyrator(synthesize)


Expand All @@ -845,7 +844,7 @@ def render_streamlit_ui() -> None:
col2.title(title)
col2.markdown("欢迎使用MockingBird Web 2")

image = Image.open(path.join('mkgui', 'static', 'mb.png'))
image = Image.open(path.join('control','mkgui', 'static', 'mb.png'))
col1.image(image)

st.markdown("---")
Expand Down
File renamed without changes.
6 changes: 3 additions & 3 deletions mkgui/preprocess.py → control/mkgui/preprocess.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@


# Constants
EXT_MODELS_DIRT = f"ppg_extractor{os.sep}saved_models"
ENC_MODELS_DIRT = f"encoder{os.sep}saved_models"
EXT_MODELS_DIRT = f"data{os.sep}ckpt{os.sep}ppg_extractor"
ENC_MODELS_DIRT = f"data{os.sep}ckpt{os.sep}encoder"


if os.path.isdir(EXT_MODELS_DIRT):
Expand Down Expand Up @@ -83,7 +83,7 @@ def preprocess(input: Input) -> Output:
"""Preprocess(预处理)"""
finished = 0
if input.model == Model.VC_PPG2MEL:
from ppg2mel.preprocess import preprocess_dataset
from models.ppg2mel.preprocess import preprocess_dataset
finished = preprocess_dataset(
datasets_root=Path(input.datasets_root),
dataset=input.dataset,
Expand Down
File renamed without changes
16 changes: 8 additions & 8 deletions mkgui/train.py → control/mkgui/train.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,17 @@
from pathlib import Path
from enum import Enum
from typing import Any
from synthesizer.hparams import hparams
from synthesizer.train import train as synt_train
from models.synthesizer.hparams import hparams
from models.synthesizer.train import train as synt_train

# Constants
SYN_MODELS_DIRT = f"synthesizer{os.sep}saved_models"
ENC_MODELS_DIRT = f"encoder{os.sep}saved_models"
SYN_MODELS_DIRT = f"data{os.sep}ckpt{os.sep}synthesizer"
ENC_MODELS_DIRT = f"data{os.sep}ckpt{os.sep}encoder"


# EXT_MODELS_DIRT = f"ppg_extractor{os.sep}saved_models"
# CONV_MODELS_DIRT = f"ppg2mel{os.sep}saved_models"
# ENC_MODELS_DIRT = f"encoder{os.sep}saved_models"
# EXT_MODELS_DIRT = f"data{os.sep}ckpt{os.sep}ppg_extractor"
# CONV_MODELS_DIRT = f"data{os.sep}ckpt{os.sep}ppg2mel"
# ENC_MODELS_DIRT = f"data{os.sep}ckpt{os.sep}encoder"

# Pre-Load models
if os.path.isdir(SYN_MODELS_DIRT):
Expand Down Expand Up @@ -96,7 +96,7 @@ def train(input: Input) -> Output:
synt_train(
input.run_id,
input.input_root,
f"synthesizer{os.sep}saved_models",
f"data{os.sep}ckpt{os.sep}synthesizer",
input.save_every,
input.backup_every,
input.log_every,
Expand Down
8 changes: 4 additions & 4 deletions mkgui/train_vc.py → control/mkgui/train_vc.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@
import torch

# Constants
EXT_MODELS_DIRT = f"ppg_extractor{os.sep}saved_models"
CONV_MODELS_DIRT = f"ppg2mel{os.sep}saved_models"
ENC_MODELS_DIRT = f"encoder{os.sep}saved_models"
EXT_MODELS_DIRT = f"data{os.sep}ckpt{os.sep}ppg_extractor"
CONV_MODELS_DIRT = f"data{os.sep}ckpt{os.sep}ppg2mel"
ENC_MODELS_DIRT = f"data{os.sep}ckpt{os.sep}encoder"


if os.path.isdir(EXT_MODELS_DIRT):
Expand Down Expand Up @@ -144,7 +144,7 @@ def train_vc(input: Input) -> Output:
if torch.cuda.is_available():
torch.cuda.manual_seed_all(input.seed)
mode = "train"
from ppg2mel.train.train_linglf02mel_seq2seq_oneshotvc import Solver
from models.ppg2mel.train.train_linglf02mel_seq2seq_oneshotvc import Solver
solver = Solver(config, params, mode)
solver.load_data()
solver.set_model()
Expand Down
18 changes: 9 additions & 9 deletions toolbox/__init__.py → control/toolbox/__init__.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
from toolbox.ui import UI
from encoder import inference as encoder
from synthesizer.inference import Synthesizer
from vocoder.wavernn import inference as rnn_vocoder
from vocoder.hifigan import inference as gan_vocoder
from vocoder.fregan import inference as fgan_vocoder
from control.toolbox.ui import UI
from models.encoder import inference as encoder
from models.synthesizer.inference import Synthesizer
from models.vocoder.wavernn import inference as rnn_vocoder
from models.vocoder.hifigan import inference as gan_vocoder
from models.vocoder.fregan import inference as fgan_vocoder
from pathlib import Path
from time import perf_counter as timer
from toolbox.utterance import Utterance
from control.toolbox.utterance import Utterance
import numpy as np
import traceback
import sys
Expand Down Expand Up @@ -396,7 +396,7 @@ def init_extractor(self):
self.ui.log("Loading the extractor %s... " % model_fpath)
self.ui.set_loading(1)
start = timer()
import ppg_extractor as extractor
import models.ppg_extractor as extractor
self.extractor = extractor.load_model(model_fpath)
self.ui.log("Done (%dms)." % int(1000 * (timer() - start)), "append")
self.ui.set_loading(0)
Expand All @@ -408,7 +408,7 @@ def init_convertor(self):
self.ui.log("Loading the convertor %s... " % model_fpath)
self.ui.set_loading(1)
start = timer()
import ppg2mel as convertor
import models.ppg2mel as convertor
self.convertor = convertor.load_model( model_fpath)
self.ui.log("Done (%dms)." % int(1000 * (timer() - start)), "append")
self.ui.set_loading(0)
Expand Down
File renamed without changes
4 changes: 2 additions & 2 deletions toolbox/ui.py → control/toolbox/ui.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
import matplotlib.pyplot as plt
from matplotlib.backends.backend_qt5agg import FigureCanvasQTAgg as FigureCanvas
from matplotlib.figure import Figure
from encoder.inference import plot_embedding_as_heatmap
from toolbox.utterance import Utterance
from models.encoder.inference import plot_embedding_as_heatmap
from control.toolbox.utterance import Utterance
from pathlib import Path
from typing import List, Set
import sounddevice as sd
Expand Down
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion demo_toolbox.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from pathlib import Path
from toolbox import Toolbox
from control.toolbox import Toolbox
from utils.argutils import print_args
from utils.modelutils import check_model_paths
import argparse
Expand Down
2 changes: 0 additions & 2 deletions encoder/data_objects/__init__.py

This file was deleted.

Binary file removed encoder/saved_models/pretrained.pt
Binary file not shown.
Loading

0 comments on commit 74a3fc9

Please sign in to comment.