Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix lints by ruff scanning #197

Open
wants to merge 7 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion bins/svc/inference.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ def prepare_for_audio_file(args, cfg, num_workers=1):
acoustic_extractor.extract_utt_acoustic_features_serial(
metadata, temp_audio_dir, cfg
)
if cfg.preprocess.use_min_max_norm_mel == True:
if cfg.preprocess.use_min_max_norm_mel is True:
acoustic_extractor.cal_mel_min_max(
dataset=audio_name, output_path=preprocess_path, cfg=cfg, metadata=metadata
)
Expand Down
4 changes: 2 additions & 2 deletions bins/svc/preprocess.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ def preprocess(cfg, args):
new_datasets_list.extend(new_datasets)
cfg.dataset.extend(new_datasets_list)
print("Augmentation datasets: ", cfg.dataset)
except:
except Exception: # TODO: better exception handling
print("No Data Augmentation.")

# Dump metadata of datasets (singers, train/test durations, etc.)
Expand Down Expand Up @@ -145,7 +145,7 @@ def preprocess(cfg, args):
continue
dataset_dir = os.path.join(output_path, dataset)
metadata = []
for split in ["train", "test"] if not "eval" in dataset else ["test"]:
for split in ["train", "test"] if "eval" not in dataset else ["test"]:
metadata_file_path = os.path.join(src_dataset_dir, "{}.json".format(split))
with open(metadata_file_path, "r") as f:
metadata.extend(json.load(f))
Expand Down
2 changes: 1 addition & 1 deletion bins/svc/train.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ def main():

# Data Augmentation
if (
type(cfg.preprocess.data_augment) == list
isinstance(cfg.preprocess.data_augment, list)
and len(cfg.preprocess.data_augment) > 0
):
new_datasets_list = []
Expand Down
4 changes: 2 additions & 2 deletions bins/tta/preprocess.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ def preprocess(cfg, args):
new_datasets_list.extend(new_datasets)
cfg.dataset.extend(new_datasets_list)
print("Augmentation datasets: ", cfg.dataset)
except:
except Exception: # TODO: better exception handling
print("No Data Augmentation.")

# Dump metadata of datasets (singers, train/test durations, etc.)
Expand Down Expand Up @@ -157,7 +157,7 @@ def preprocess(cfg, args):
continue
dataset_dir = os.path.join(output_path, dataset)
metadata = []
for split in ["train", "test"] if not "eval" in dataset else ["test"]:
for split in ["train", "test"] if "eval" not in dataset else ["test"]:
metadata_file_path = os.path.join(src_dataset_dir, "{}.json".format(split))
with open(metadata_file_path, "r") as f:
metadata.extend(json.load(f))
Expand Down
4 changes: 2 additions & 2 deletions bins/tts/preprocess.py
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ def preprocess(cfg, args):
new_datasets_list.extend(new_datasets)
cfg.dataset.extend(new_datasets_list)
print("Augmentation datasets: ", cfg.dataset)
except:
except Exception: # TODO: better exception handling
print("No Data Augmentation.")

# json files
Expand Down Expand Up @@ -198,7 +198,7 @@ def preprocess(cfg, args):
continue
dataset_dir = os.path.join(output_path, dataset)
metadata = []
for split in ["train", "test"] if not "eval" in dataset else ["test"]:
for split in ["train", "test"] if "eval" not in dataset else ["test"]:
metadata_file_path = os.path.join(src_dataset_dir, "{}.json".format(split))
with open(metadata_file_path, "r") as f:
metadata.extend(json.load(f))
Expand Down
2 changes: 1 addition & 1 deletion bins/tts/train.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ def main():

# Data Augmentation
if (
type(cfg.preprocess.data_augment) == list
isinstance(cfg.preprocess.data_augment, list)
and len(cfg.preprocess.data_augment) > 0
):
new_datasets_list = []
Expand Down
4 changes: 2 additions & 2 deletions bins/vocoder/preprocess.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ def preprocess(cfg, args):
new_datasets_list.extend(new_datasets)
cfg.dataset.extend(new_datasets_list)
print("Augmentation datasets: ", cfg.dataset)
except:
except Exception: # TODO: better exception handling
print("No Data Augmentation.")

# Dump metadata of datasets (singers, train/test durations, etc.)
Expand Down Expand Up @@ -119,7 +119,7 @@ def preprocess(cfg, args):
continue
dataset_dir = os.path.join(output_path, dataset)
metadata = []
for split in ["train", "test"] if not "eval" in dataset else ["test"]:
for split in ["train", "test"] if "eval" not in dataset else ["test"]:
metadata_file_path = os.path.join(src_dataset_dir, "{}.json".format(split))
with open(metadata_file_path, "r") as f:
metadata.extend(json.load(f))
Expand Down
2 changes: 1 addition & 1 deletion evaluation/features/long_term_average_spectrum.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

def extract_ltas(audio, fs=None, n_fft=1024, hop_length=256):
"""Extract Long-Term Average Spectrum for a given audio."""
if fs != None:
if fs is not None:
y, _ = librosa.load(audio, sr=fs)
else:
y, fs = librosa.load(audio)
Expand Down
2 changes: 1 addition & 1 deletion evaluation/features/signal_to_noise_ratio.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ def getHarmonics(fund, sr, nHarmonics=6, aliased=False):

def extract_snr(audio, sr=None):
"""Extract Signal-to-Noise Ratio for a given audio."""
if sr != None:
if sr is not None:
audio, _ = librosa.load(audio, sr=sr)
else:
audio, sr = librosa.load(audio, sr=sr)
Expand Down
2 changes: 1 addition & 1 deletion evaluation/features/singing_power_ratio.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ def extract_spr(
pitch_min: lower limit for f0 quantization.
"""
# Load audio
if fs != None:
if fs is not None:
audio, _ = librosa.load(audio, sr=fs)
else:
audio, fs = librosa.load(audio)
Expand Down
2 changes: 1 addition & 1 deletion evaluation/metrics/energy/energy_pearson_coefficients.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ def extract_energy_pearson_coeffcients(
pearson = PearsonCorrCoef()

# Load audio
if fs != None:
if fs is not None:
audio_ref, _ = librosa.load(audio_ref, sr=fs)
audio_deg, _ = librosa.load(audio_deg, sr=fs)
else:
Expand Down
2 changes: 1 addition & 1 deletion evaluation/metrics/energy/energy_rmse.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ def extract_energy_rmse(
db_scale = kwargs["db_scale"]

# Load audio
if fs != None:
if fs is not None:
audio_ref, _ = librosa.load(audio_ref, sr=fs)
audio_deg, _ = librosa.load(audio_deg, sr=fs)
else:
Expand Down
2 changes: 1 addition & 1 deletion evaluation/metrics/f0/f0_pearson_coefficients.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ def extract_fpc(
pearson = PearsonCorrCoef()

# Load audio
if fs != None:
if fs is not None:
audio_ref, _ = librosa.load(audio_ref, sr=fs)
audio_deg, _ = librosa.load(audio_deg, sr=fs)
else:
Expand Down
2 changes: 1 addition & 1 deletion evaluation/metrics/f0/f0_periodicity_rmse.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ def extract_f0_periodicity_rmse(
method = kwargs["method"]

# Load audio
if fs != None:
if fs is not None:
audio_ref, _ = librosa.load(audio_ref, sr=fs)
audio_deg, _ = librosa.load(audio_deg, sr=fs)
else:
Expand Down
2 changes: 1 addition & 1 deletion evaluation/metrics/f0/f0_rmse.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ def extract_f0rmse(
need_mean = kwargs["need_mean"]

# Load audio
if fs != None:
if fs is not None:
audio_ref, _ = librosa.load(audio_ref, sr=fs)
audio_deg, _ = librosa.load(audio_deg, sr=fs)
else:
Expand Down
2 changes: 1 addition & 1 deletion evaluation/metrics/f0/v_uv_f1.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ def extract_f1_v_uv(
method = kwargs["method"]

# Load audio
if fs != None:
if fs is not None:
audio_ref, _ = librosa.load(audio_ref, sr=fs)
audio_deg, _ = librosa.load(audio_deg, sr=fs)
else:
Expand Down
2 changes: 1 addition & 1 deletion evaluation/metrics/similarity/speaker_similarity.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ def extract_similarity(path_ref, path_deg, **kwargs):
"microsoft/wavlm-base-plus-sv"
)
model = WavLMForXVector.from_pretrained("microsoft/wavlm-base-plus-sv")
except:
except Exception: # TODO: better exception handling
feature_extractor = Wav2Vec2FeatureExtractor.from_pretrained(
"pretrained/wavlm", sampling_rate=16000
)
Expand Down
2 changes: 1 addition & 1 deletion evaluation/metrics/spectrogram/mel_cepstral_distortion.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ def extract_mcd(audio_ref, audio_deg, **kwargs):
fs = kwargs["fs"]

mcd_toolbox = Calculate_MCD(MCD_mode="dtw_sl")
if fs != None:
if fs is not None:
mcd_toolbox.SAMPLING_RATE = fs
mcd_value = mcd_toolbox.calculate_mcd(audio_ref, audio_deg)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ def extract_mstft(
method = kwargs["method"]

# Load audio
if fs != None:
if fs is not None:
audio_ref, _ = librosa.load(audio_ref, sr=fs)
audio_deg, _ = librosa.load(audio_deg, sr=fs)
else:
Expand Down
2 changes: 1 addition & 1 deletion evaluation/metrics/spectrogram/pesq.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ def extract_pesq(audio_ref, audio_deg, **kwargs):
method = kwargs["method"]

# Load audio
if fs != None:
if fs is not None:
audio_ref, _ = librosa.load(audio_ref, sr=fs)
audio_deg, _ = librosa.load(audio_deg, sr=fs)
else:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ def extract_si_sdr(audio_ref, audio_deg, **kwargs):

si_sdr = ScaleInvariantSignalDistortionRatio()

if fs != None:
if fs is not None:
audio_ref, _ = librosa.load(audio_ref, sr=fs)
audio_deg, _ = librosa.load(audio_deg, sr=fs)
else:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ def extract_si_snr(audio_ref, audio_deg, **kwargs):

si_snr = ScaleInvariantSignalNoiseRatio()

if fs != None:
if fs is not None:
audio_ref, _ = librosa.load(audio_ref, sr=fs)
audio_deg, _ = librosa.load(audio_deg, sr=fs)
else:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ def extract_stoi(audio_ref, audio_deg, **kwargs):
method = kwargs["method"]

# Load audio
if fs != None:
if fs is not None:
audio_ref, _ = librosa.load(audio_ref, sr=fs)
audio_deg, _ = librosa.load(audio_deg, sr=fs)
else:
Expand Down
1 change: 0 additions & 1 deletion models/base/base_inference.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
from tqdm import tqdm

from models.vocoders.vocoder_inference import synthesis
from torch.utils.data import DataLoader
from utils.util import set_all_random_seed
from utils.util import load_config

Expand Down
2 changes: 1 addition & 1 deletion models/codec/ns3_codec/quantize/rvq.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class ResidualVQ(nn.Module):
def __init__(self, *, num_quantizers, codebook_size, **kwargs):
super().__init__()
VQ = FactorizedVectorQuantize
if type(codebook_size) == int:
if isinstance(codebook_size, int):
codebook_size = [codebook_size] * num_quantizers
self.layers = nn.ModuleList(
[VQ(codebook_size=2**size, **kwargs) for size in codebook_size]
Expand Down
4 changes: 2 additions & 2 deletions models/codec/ns3_codec/transformer.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ def forward(self, x, key_padding_mask, conditon=None):
else:
x = self.ln_1(x)

if key_padding_mask != None:
if key_padding_mask is not None:
key_padding_mask_input = ~(key_padding_mask.bool())
else:
key_padding_mask_input = None
Expand Down Expand Up @@ -186,7 +186,7 @@ def __init__(
)
self.use_cln = use_cln if use_cln is not None else cfg.use_cln

if enc_emb_tokens != None:
if enc_emb_tokens is not None:
self.use_enc_emb = True
self.enc_emb_tokens = enc_emb_tokens
else:
Expand Down
6 changes: 3 additions & 3 deletions models/svc/base/svc_dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -317,7 +317,7 @@ def __init__(self, args, cfg, infer_type):
target_singer = args.target_singer
self.cfg = cfg
self.trans_key = args.trans_key
assert type(target_singer) == str
assert isinstance(target_singer, str)

self.target_singer = target_singer.split("_")[-1]
self.target_dataset = target_singer.replace(
Expand Down Expand Up @@ -481,9 +481,9 @@ def __getitem__(self, index):
if self.trans_key:
try:
self.trans_key = int(self.trans_key)
except:
except Exception: # TODO: better exception handling
pass
if type(self.trans_key) == int:
if isinstance(self.trans_key, int):
frame_pitch = transpose_key(frame_pitch, self.trans_key)
elif self.trans_key:
assert self.target_singer
Expand Down
3 changes: 0 additions & 3 deletions models/tta/autoencoder/autoencoder_dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,9 +77,6 @@ def __getitem__(self, index):
def __len__(self):
return len(self.metadata)

def __len__(self):
return len(self.metadata)


class AutoencoderKLCollator(BaseOfflineCollator):
def __init__(self, cfg):
Expand Down
4 changes: 2 additions & 2 deletions models/tta/autoencoder/autoencoder_trainer.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ def build_criterion(self):
return AutoencoderLossWithDiscriminator(self.cfg.model.loss)

def get_state_dict(self):
if self.scheduler != None:
if self.scheduler is not None:
state_dict = {
"model": self.model.state_dict(),
"optimizer_ae": self.optimizer["opt_ae"].state_dict(),
Expand Down Expand Up @@ -119,7 +119,7 @@ def load_model(self, checkpoint):
self.model.load_state_dict(checkpoint["model"])
self.optimizer["opt_ae"].load_state_dict(checkpoint["optimizer_ae"])
self.optimizer["opt_disc"].load_state_dict(checkpoint["optimizer_disc"])
if self.scheduler != None:
if self.scheduler is not None:
self.scheduler.load_state_dict(checkpoint["scheduler"])

def build_model(self):
Expand Down
5 changes: 2 additions & 3 deletions models/tta/ldm/audioldm_trainer.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
from torch.utils.data import ConcatDataset, DataLoader

from transformers import T5EncoderModel
from diffusers import DDPMScheduler


class AudioLDMTrainer(BaseTrainer):
Expand Down Expand Up @@ -122,7 +121,7 @@ def build_criterion(self):
return criterion

def get_state_dict(self):
if self.scheduler != None:
if self.scheduler is not None:
state_dict = {
"model": self.model.state_dict(),
"optimizer": self.optimizer.state_dict(),
Expand All @@ -147,7 +146,7 @@ def load_model(self, checkpoint):

self.model.load_state_dict(checkpoint["model"])
self.optimizer.load_state_dict(checkpoint["optimizer"])
if self.scheduler != None:
if self.scheduler is not None:
self.scheduler.load_state_dict(checkpoint["scheduler"])

def build_model(self):
Expand Down
4 changes: 2 additions & 2 deletions models/tta/ldm/inference_utils/vocoder.py
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ class DiscriminatorP(torch.nn.Module):
def __init__(self, period, kernel_size=5, stride=3, use_spectral_norm=False):
super(DiscriminatorP, self).__init__()
self.period = period
norm_f = weight_norm if use_spectral_norm == False else spectral_norm
norm_f = weight_norm if use_spectral_norm is False else spectral_norm
self.convs = nn.ModuleList(
[
norm_f(
Expand Down Expand Up @@ -314,7 +314,7 @@ def forward(self, y, y_hat):
class DiscriminatorS(torch.nn.Module):
def __init__(self, use_spectral_norm=False):
super(DiscriminatorS, self).__init__()
norm_f = weight_norm if use_spectral_norm == False else spectral_norm
norm_f = weight_norm if use_spectral_norm is False else spectral_norm
self.convs = nn.ModuleList(
[
norm_f(Conv1d(1, 128, 15, 1, padding=7)),
Expand Down
2 changes: 1 addition & 1 deletion models/tts/base/tts_inferece.py
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ def _load_model(
assert checkpoint_dir is not None
# Load the latest accelerator state dicts
ls = [
str(i) for i in Path(checkpoint_dir).glob("*") if not "audio" in str(i)
str(i) for i in Path(checkpoint_dir).glob("*") if "audio" not in str(i)
]
ls.sort(key=lambda x: int(x.split("_")[-3].split("-")[-1]), reverse=True)
checkpoint_path = ls[0]
Expand Down
3 changes: 1 addition & 2 deletions models/tts/base/tts_trainer.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
import torch
import time
from pathlib import Path
import torch
from tqdm import tqdm
import re
import logging
Expand Down Expand Up @@ -175,7 +174,7 @@ def _check_resume(self):
self.args.resume_type = "finetune"
checkpoint_dir = self.args.ar_model_ckpt_dir
self.logger.info(
f"Training NAR model at stage 2 using the checkpoint of AR model at stage 1."
"Training NAR model at stage 2 using the checkpoint of AR model at stage 1."
)

self.logger.info(f"Resuming from checkpoint: {checkpoint_dir}")
Expand Down
Loading