Skip to content

Commit

Permalink
chore: code cleanup by ruff fix
Browse files Browse the repository at this point in the history
  • Loading branch information
magic-akari committed Jun 26, 2023
1 parent 88be209 commit a5f0e91
Show file tree
Hide file tree
Showing 78 changed files with 300 additions and 217 deletions.
3 changes: 3 additions & 0 deletions .ruff.toml
Original file line number Diff line number Diff line change
@@ -1 +1,4 @@
select = ["E", "F", "I"]

# Never enforce `E501` (line length violations).
ignore = ["E501"]
1 change: 1 addition & 0 deletions cluster/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import torch
from sklearn.cluster import KMeans


def get_cluster_model(ckpt_path):
checkpoint = torch.load(ckpt_path)
kmeans_dict = {}
Expand Down
8 changes: 6 additions & 2 deletions cluster/kmeans.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
import torch,pynvml
from torch.nn.functional import normalize
from time import time

import numpy as np
import pynvml
import torch
from torch.nn.functional import normalize


# device=torch.device("cuda:0")
def _kpp(data: torch.Tensor, k: int, sample_size: int = -1):
""" Picks k points in the data based on the kmeans++ method.
Expand Down
16 changes: 8 additions & 8 deletions cluster/train_cluster.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
import time
import tqdm
import argparse
import logging
import os
import time
from pathlib import Path
import logging
import argparse
from kmeans import KMeansGPU
import torch

import numpy as np
from sklearn.cluster import KMeans,MiniBatchKMeans
import torch
import tqdm
from kmeans import KMeansGPU
from sklearn.cluster import KMeans, MiniBatchKMeans

logging.basicConfig(level=logging.INFO)
logger = logging.getLogger(__name__)
import torch

def train_cluster(in_dir, n_clusters, use_minibatch=True, verbose=False,use_gpu=False):#gpu_minibatch真拉,虽然库支持但是也不考虑
logger.info(f"Loading features from {in_dir}")
Expand Down
5 changes: 3 additions & 2 deletions data_utils.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
import os
import random

import numpy as np
import torch
import torch.utils.data

import utils
from modules.mel_processing import spectrogram_torch, spectrogram_torch
from utils import load_wav_to_torch, load_filepaths_and_text
from modules.mel_processing import spectrogram_torch
from utils import load_filepaths_and_text, load_wav_to_torch

# import h5py

Expand Down
10 changes: 6 additions & 4 deletions diffusion/data_loaders.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
import os
import random
import numpy as np

import librosa
import numpy as np
import torch
import random
from utils import repeat_expand_2d
from tqdm import tqdm
from torch.utils.data import Dataset
from tqdm import tqdm

from utils import repeat_expand_2d


def traverse_dir(
root_dir,
Expand Down
11 changes: 8 additions & 3 deletions diffusion/diffusion.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
from collections import deque
from functools import partial
from inspect import isfunction
import torch.nn.functional as F

import numpy as np
import torch
import torch.nn.functional as F
from torch import nn
from tqdm import tqdm

Expand Down Expand Up @@ -254,7 +255,11 @@ def forward(self,

if method is not None and infer_speedup > 1:
if method == 'dpm-solver' or method == 'dpm-solver++':
from .dpm_solver_pytorch import NoiseScheduleVP, model_wrapper, DPM_Solver
from .dpm_solver_pytorch import (
DPM_Solver,
NoiseScheduleVP,
model_wrapper,
)
# 1. Define the noise schedule.
noise_schedule = NoiseScheduleVP(schedule='discrete', betas=self.betas[:t])

Expand Down Expand Up @@ -332,7 +337,7 @@ def wrapped(x, t, **kwargs):
infer_speedup, cond=cond
)
elif method == 'unipc':
from .uni_pc import NoiseScheduleVP, model_wrapper, UniPC
from .uni_pc import NoiseScheduleVP, UniPC, model_wrapper
# 1. Define the noise schedule.
noise_schedule = NoiseScheduleVP(schedule='discrete', betas=self.betas[:t])

Expand Down
14 changes: 9 additions & 5 deletions diffusion/diffusion_onnx.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import math
from collections import deque
from functools import partial
from inspect import isfunction
import torch.nn.functional as F

import numpy as np
from torch.nn import Conv1d
from torch.nn import Mish
import torch
import torch.nn.functional as F
from torch import nn
from torch.nn import Conv1d, Mish
from tqdm import tqdm
import math


def exists(x):
Expand Down Expand Up @@ -390,7 +390,11 @@ def org_forward(self,

if method is not None and infer_speedup > 1:
if method == 'dpm-solver':
from .dpm_solver_pytorch import NoiseScheduleVP, model_wrapper, DPM_Solver
from .dpm_solver_pytorch import (
DPM_Solver,
NoiseScheduleVP,
model_wrapper,
)
# 1. Define the noise schedule.
noise_schedule = NoiseScheduleVP(schedule='discrete', betas=self.betas[:t])

Expand Down
1 change: 1 addition & 0 deletions diffusion/infer_gt_mel.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import torch
import torch.nn.functional as F

from diffusion.unit2mel import load_model_vocoder


Expand Down
8 changes: 5 additions & 3 deletions diffusion/logger/saver.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,16 @@
author: wayn391@mastertones
'''

import datetime
import os
import time
import yaml
import datetime
import torch

import matplotlib.pyplot as plt
import torch
import yaml
from torch.utils.tensorboard import SummaryWriter


class Saver(object):
def __init__(
self,
Expand Down
6 changes: 4 additions & 2 deletions diffusion/logger/utils.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import os
import yaml
import json
import os

import torch
import yaml


def traverse_dir(
root_dir,
Expand Down
8 changes: 5 additions & 3 deletions diffusion/onnx_export.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
from diffusion_onnx import GaussianDiffusion
import os
import yaml

import numpy as np
import torch
import torch.nn as nn
import numpy as np
import torch.nn.functional as F
import yaml
from diffusion_onnx import GaussianDiffusion


class DotDict(dict):
def __getattr__(*args):
Expand Down
9 changes: 6 additions & 3 deletions diffusion/solver.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
import time

import librosa
import numpy as np
import torch
import librosa
from diffusion.logger.saver import Saver
from diffusion.logger import utils
from torch import autocast
from torch.cuda.amp import GradScaler

from diffusion.logger import utils
from diffusion.logger.saver import Saver


def test(args, model, vocoder, loader_test, saver):
print(' [*] testing...')
model.eval()
Expand Down
3 changes: 2 additions & 1 deletion diffusion/uni_pc.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import torch
import math

import torch


class NoiseScheduleVP:
def __init__(
Expand Down
9 changes: 6 additions & 3 deletions diffusion/unit2mel.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
import os
import yaml

import numpy as np
import torch
import torch.nn as nn
import numpy as np
import yaml

from .diffusion import GaussianDiffusion
from .wavenet import WaveNet
from .vocoder import Vocoder
from .wavenet import WaveNet


class DotDict(dict):
def __getattr__(*args):
Expand Down
7 changes: 4 additions & 3 deletions diffusion/vocoder.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import torch
from vdecoder.nsf_hifigan.nvSTFT import STFT
from vdecoder.nsf_hifigan.models import load_model,load_config
from torchaudio.transforms import Resample


from vdecoder.nsf_hifigan.models import load_config, load_model
from vdecoder.nsf_hifigan.nvSTFT import STFT


class Vocoder:
def __init__(self, vocoder_type, vocoder_ckpt, device = None):
if device is None:
Expand Down
2 changes: 1 addition & 1 deletion flask_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from flask import Flask, request, send_file
from flask_cors import CORS

from inference.infer_tool import Svc, RealTimeVC
from inference.infer_tool import RealTimeVC, Svc

app = Flask(__name__)

Expand Down
4 changes: 2 additions & 2 deletions flask_api_full_song.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import io

import numpy as np
import soundfile
from flask import Flask, request, send_file

from inference import infer_tool
from inference import slicer
from inference import infer_tool, slicer

app = Flask(__name__)

Expand Down
10 changes: 5 additions & 5 deletions inference/infer_tool.py
Original file line number Diff line number Diff line change
@@ -1,26 +1,26 @@
import gc
import hashlib
import io
import json
import logging
import os
import pickle
import time
from pathlib import Path
from inference import slicer
import gc

import librosa
import numpy as np

# import onnxruntime
import soundfile
import torch
import torchaudio

import cluster
import utils
from models import SynthesizerTrn
import pickle

from diffusion.unit2mel import load_model_vocoder
from inference import slicer
from models import SynthesizerTrn

logging.getLogger('matplotlib').setLevel(logging.WARNING)

Expand Down
6 changes: 4 additions & 2 deletions inference/infer_tool_grad.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,18 @@
import io
import logging
import os
import io

import librosa
import numpy as np
from inference import slicer
import parselmouth
import soundfile
import torch
import torchaudio

import utils
from inference import slicer
from models import SynthesizerTrn

logging.getLogger('numba').setLevel(logging.WARNING)
logging.getLogger('matplotlib').setLevel(logging.WARNING)

Expand Down
4 changes: 3 additions & 1 deletion inference_main.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import logging
from spkmix import spk_mix_map

import soundfile

from inference import infer_tool
from inference.infer_tool import Svc
from spkmix import spk_mix_map

logging.getLogger('numba').setLevel(logging.WARNING)
chunks_dict = infer_tool.read_temp("inference/chunks_temp.json")
Expand Down
7 changes: 3 additions & 4 deletions models.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,17 @@
import torch
from torch import nn
from torch.nn import Conv1d, Conv2d
from torch.nn import functional as F
from torch.nn.utils import spectral_norm, weight_norm

import modules.attentions as attentions
import modules.commons as commons
import modules.modules as modules

from torch.nn import Conv1d, Conv2d
from torch.nn.utils import weight_norm, spectral_norm

import utils
from modules.commons import get_padding
from utils import f0_to_coarse


class ResidualCouplingBlock(nn.Module):
def __init__(self,
channels,
Expand Down
6 changes: 4 additions & 2 deletions modules/F0Predictor/CrepeF0Predictor.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
from modules.F0Predictor.F0Predictor import F0Predictor
from modules.F0Predictor.crepe import CrepePitchExtractor
import torch

from modules.F0Predictor.crepe import CrepePitchExtractor
from modules.F0Predictor.F0Predictor import F0Predictor


class CrepeF0Predictor(F0Predictor):
def __init__(self,hop_length=512,f0_min=50,f0_max=1100,device=None,sampling_rate=44100,threshold=0.05,model="full"):
self.F0Creper = CrepePitchExtractor(hop_length=hop_length,f0_min=f0_min,f0_max=f0_max,device=device,threshold=threshold,model=model)
Expand Down
Loading

0 comments on commit a5f0e91

Please sign in to comment.