minor fixes

1. changed the naming scheme from `speed-perturb` to `perturb-speed` to align with the librispeech recipe

>> 00256a7669/egs/librispeech/ASR/local/compute_fbank_librispeech.py (L65)

2. changed arg type for `perturb-speed` to str2bool
This commit is contained in:
jinzr 2023-08-10 20:47:59 +08:00
parent 53aa106180
commit e0b16e09aa
16 changed files with 67 additions and 57 deletions

View File

@ -32,7 +32,7 @@ import torch
from lhotse import CutSet, Fbank, FbankConfig, LilcomChunkyWriter
from lhotse.recipes.utils import read_manifests_if_cached
from icefall.utils import get_executor
from icefall.utils import get_executor, str2bool
# Torch's multithreaded behavior needs to be disabled or
# it wastes a lot of CPU and slow things down.
@ -42,7 +42,7 @@ torch.set_num_threads(1)
torch.set_num_interop_threads(1)
def compute_fbank_aidatatang_200zh(num_mel_bins: int = 80, speed_perturb: bool = False):
def compute_fbank_aidatatang_200zh(num_mel_bins: int = 80, perturb_speed: bool = False):
src_dir = Path("data/manifests/aidatatang_200zh")
output_dir = Path("data/fbank")
num_jobs = min(15, os.cpu_count())
@ -85,7 +85,8 @@ def compute_fbank_aidatatang_200zh(num_mel_bins: int = 80, speed_perturb: bool =
recordings=m["recordings"],
supervisions=m["supervisions"],
)
if "train" in partition and speed_perturb:
if "train" in partition and perturb_speed:
logging.info(f"Doing speed perturb")
cut_set = (
cut_set + cut_set.perturb_speed(0.9) + cut_set.perturb_speed(1.1)
)
@ -110,8 +111,8 @@ def get_args():
help="""The number of mel bins for Fbank""",
)
parser.add_argument(
"--speed-perturb",
type=bool,
"--perturb-speed",
type=str2bool,
default=False,
help="Enable 0.9 and 1.1 speed perturbation for data augmentation. Default: False.",
)
@ -125,5 +126,5 @@ if __name__ == "__main__":
args = get_args()
compute_fbank_aidatatang_200zh(
num_mel_bins=args.num_mel_bins, speed_perturb=args.speed_perturb
num_mel_bins=args.num_mel_bins, perturb_speed=args.perturb_speed
)

View File

@ -77,7 +77,7 @@ if [ $stage -le 4 ] && [ $stop_stage -ge 4 ]; then
log "Stage 4: Compute fbank for aidatatang_200zh"
if [ ! -f data/fbank/.aidatatang_200zh.done ]; then
mkdir -p data/fbank
./local/compute_fbank_aidatatang_200zh.py --speed-perturb True
./local/compute_fbank_aidatatang_200zh.py --perturb-speed True
touch data/fbank/.aidatatang_200zh.done
fi
fi

View File

@ -32,7 +32,7 @@ import torch
from lhotse import CutSet, Fbank, FbankConfig, LilcomChunkyWriter
from lhotse.recipes.utils import read_manifests_if_cached
from icefall.utils import get_executor
from icefall.utils import get_executor, str2bool
# Torch's multithreaded behavior needs to be disabled or
# it wastes a lot of CPU and slow things down.
@ -42,7 +42,7 @@ torch.set_num_threads(1)
torch.set_num_interop_threads(1)
def compute_fbank_aidatatang_200zh(num_mel_bins: int = 80, speed_perturb: bool = False):
def compute_fbank_aidatatang_200zh(num_mel_bins: int = 80, perturb_speed: bool = False):
src_dir = Path("data/manifests")
output_dir = Path("data/fbank")
num_jobs = min(15, os.cpu_count())
@ -85,7 +85,8 @@ def compute_fbank_aidatatang_200zh(num_mel_bins: int = 80, speed_perturb: bool =
recordings=m["recordings"],
supervisions=m["supervisions"],
)
if "train" in partition and speed_perturb:
if "train" in partition and perturb_speed:
logging.info(f"Doing speed perturb")
cut_set = (
cut_set + cut_set.perturb_speed(0.9) + cut_set.perturb_speed(1.1)
)
@ -110,8 +111,8 @@ def get_args():
help="""The number of mel bins for Fbank""",
)
parser.add_argument(
"--speed-perturb",
type=bool,
"--perturb-speed",
type=str2bool,
default=False,
help="Enable 0.9 and 1.1 speed perturbation for data augmentation. Default: False.",
)
@ -125,5 +126,5 @@ if __name__ == "__main__":
args = get_args()
compute_fbank_aidatatang_200zh(
num_mel_bins=args.num_mel_bins, speed_perturb=args.speed_perturb
num_mel_bins=args.num_mel_bins, perturb_speed=args.perturb_speed
)

View File

@ -32,7 +32,7 @@ import torch
from lhotse import CutSet, Fbank, FbankConfig, LilcomChunkyWriter
from lhotse.recipes.utils import read_manifests_if_cached
from icefall.utils import get_executor
from icefall.utils import get_executor, str2bool
# Torch's multithreaded behavior needs to be disabled or
# it wastes a lot of CPU and slow things down.
@ -42,7 +42,7 @@ torch.set_num_threads(1)
torch.set_num_interop_threads(1)
def compute_fbank_aishell(num_mel_bins: int = 80, speed_perturb: bool = False):
def compute_fbank_aishell(num_mel_bins: int = 80, perturb_speed: bool = False):
src_dir = Path("data/manifests")
output_dir = Path("data/fbank")
num_jobs = min(15, os.cpu_count())
@ -81,7 +81,8 @@ def compute_fbank_aishell(num_mel_bins: int = 80, speed_perturb: bool = False):
recordings=m["recordings"],
supervisions=m["supervisions"],
)
if "train" in partition and speed_perturb:
if "train" in partition and perturb_speed:
logging.info(f"Doing speed perturb")
cut_set = (
cut_set + cut_set.perturb_speed(0.9) + cut_set.perturb_speed(1.1)
)
@ -105,8 +106,8 @@ def get_args():
help="""The number of mel bins for Fbank""",
)
parser.add_argument(
"--speed-perturb",
type=bool,
"--perturb-speed",
type=str2bool,
default=False,
help="Enable 0.9 and 1.1 speed perturbation for data augmentation. Default: False.",
)
@ -120,5 +121,5 @@ if __name__ == "__main__":
args = get_args()
compute_fbank_aishell(
num_mel_bins=args.num_mel_bins, speed_perturb=args.speed_perturb
num_mel_bins=args.num_mel_bins, perturb_speed=args.perturb_speed
)

View File

@ -114,7 +114,7 @@ if [ $stage -le 3 ] && [ $stop_stage -ge 3 ]; then
log "Stage 3: Compute fbank for aishell"
if [ ! -f data/fbank/.aishell.done ]; then
mkdir -p data/fbank
./local/compute_fbank_aishell.py --speed-perturb True
./local/compute_fbank_aishell.py --perturb-speed True
touch data/fbank/.aishell.done
fi
fi

View File

@ -53,7 +53,7 @@ if [ $stage -le 2 ] && [ $stop_stage -ge 2 ]; then
log "Stage 2: Process aidatatang_200zh"
if [ ! -f data/fbank/.aidatatang_200zh_fbank.done ]; then
mkdir -p data/fbank
./local/compute_fbank_aidatatang_200zh.py --speed-perturb True
./local/compute_fbank_aidatatang_200zh.py --perturb-speed True
touch data/fbank/.aidatatang_200zh_fbank.done
fi
fi

View File

@ -32,7 +32,7 @@ import torch
from lhotse import CutSet, Fbank, FbankConfig, LilcomChunkyWriter
from lhotse.recipes.utils import read_manifests_if_cached
from icefall.utils import get_executor
from icefall.utils import get_executor, str2bool
# Torch's multithreaded behavior needs to be disabled or
# it wastes a lot of CPU and slow things down.
@ -42,7 +42,7 @@ torch.set_num_threads(1)
torch.set_num_interop_threads(1)
def compute_fbank_aishell2(num_mel_bins: int = 80, speed_perturb: bool = False):
def compute_fbank_aishell2(num_mel_bins: int = 80, perturb_speed: bool = False):
src_dir = Path("data/manifests")
output_dir = Path("data/fbank")
num_jobs = min(15, os.cpu_count())
@ -81,7 +81,8 @@ def compute_fbank_aishell2(num_mel_bins: int = 80, speed_perturb: bool = False):
recordings=m["recordings"],
supervisions=m["supervisions"],
)
if "train" in partition and speed_perturb:
if "train" in partition and perturb_speed:
logging.info(f"Doing speed perturb")
cut_set = (
cut_set + cut_set.perturb_speed(0.9) + cut_set.perturb_speed(1.1)
)
@ -105,8 +106,8 @@ def get_args():
help="""The number of mel bins for Fbank""",
)
parser.add_argument(
"--speed-perturb",
type=bool,
"--perturb-speed",
type=str2bool,
default=False,
help="Enable 0.9 and 1.1 speed perturbation for data augmentation. Default: False.",
)
@ -121,5 +122,5 @@ if __name__ == "__main__":
args = get_args()
compute_fbank_aishell2(
num_mel_bins=args.num_mel_bins, speed_perturb=args.speed_perturb
num_mel_bins=args.num_mel_bins, perturb_speed=args.perturb_speed
)

View File

@ -101,7 +101,7 @@ if [ $stage -le 3 ] && [ $stop_stage -ge 3 ]; then
log "Stage 3: Compute fbank for aishell2"
if [ ! -f data/fbank/.aishell2.done ]; then
mkdir -p data/fbank
./local/compute_fbank_aishell2.py --speed-perturb True
./local/compute_fbank_aishell2.py --perturb-speed True
touch data/fbank/.aishell2.done
fi
fi

View File

@ -32,7 +32,7 @@ import torch
from lhotse import ChunkedLilcomHdf5Writer, CutSet, Fbank, FbankConfig
from lhotse.recipes.utils import read_manifests_if_cached
from icefall.utils import get_executor
from icefall.utils import get_executor, str2bool
# Torch's multithreaded behavior needs to be disabled or
# it wastes a lot of CPU and slow things down.
@ -42,7 +42,7 @@ torch.set_num_threads(1)
torch.set_num_interop_threads(1)
def compute_fbank_aishell4(num_mel_bins: int = 80, speed_perturb: bool = False):
def compute_fbank_aishell4(num_mel_bins: int = 80, perturb_speed: bool = False):
src_dir = Path("data/manifests/aishell4")
output_dir = Path("data/fbank")
num_jobs = min(15, os.cpu_count())
@ -83,7 +83,8 @@ def compute_fbank_aishell4(num_mel_bins: int = 80, speed_perturb: bool = False):
recordings=m["recordings"],
supervisions=m["supervisions"],
)
if "train" in partition and speed_perturb:
if "train" in partition and perturb_speed:
logging.info(f"Doing speed perturb")
cut_set = (
cut_set + cut_set.perturb_speed(0.9) + cut_set.perturb_speed(1.1)
)
@ -115,8 +116,8 @@ def get_args():
help="""The number of mel bins for Fbank""",
)
parser.add_argument(
"--speed-perturb",
type=bool,
"--perturb-speed",
type=str2bool,
default=False,
help="Enable 0.9 and 1.1 speed perturbation for data augmentation. Default: False.",
)
@ -131,5 +132,5 @@ if __name__ == "__main__":
args = get_args()
compute_fbank_aishell4(
num_mel_bins=args.num_mel_bins, speed_perturb=args.speed_perturb
num_mel_bins=args.num_mel_bins, perturb_speed=args.perturb_speed
)

View File

@ -107,7 +107,7 @@ if [ $stage -le 5 ] && [ $stop_stage -ge 5 ]; then
log "Stage 5: Compute fbank for aishell4"
if [ ! -f data/fbank/.aishell4.done ]; then
mkdir -p data/fbank
./local/compute_fbank_aishell4.py --speed-perturb True
./local/compute_fbank_aishell4.py --perturb-speed True
touch data/fbank/.aishell4.done
fi
fi

View File

@ -32,7 +32,7 @@ import torch
from lhotse import CutSet, Fbank, FbankConfig, LilcomChunkyWriter
from lhotse.recipes.utils import read_manifests_if_cached
from icefall.utils import get_executor
from icefall.utils import get_executor, str2bool
# Torch's multithreaded behavior needs to be disabled or
# it wastes a lot of CPU and slow things down.
@ -42,7 +42,7 @@ torch.set_num_threads(1)
torch.set_num_interop_threads(1)
def compute_fbank_alimeeting(num_mel_bins: int = 80, speed_perturb: bool = False):
def compute_fbank_alimeeting(num_mel_bins: int = 80, perturb_speed: bool = False):
src_dir = Path("data/manifests/alimeeting")
output_dir = Path("data/fbank")
num_jobs = min(15, os.cpu_count())
@ -82,7 +82,8 @@ def compute_fbank_alimeeting(num_mel_bins: int = 80, speed_perturb: bool = False
recordings=m["recordings"],
supervisions=m["supervisions"],
)
if "train" in partition and speed_perturb:
if "train" in partition and perturb_speed:
logging.info(f"Doing speed perturb")
cut_set = (
cut_set + cut_set.perturb_speed(0.9) + cut_set.perturb_speed(1.1)
)
@ -115,8 +116,8 @@ def get_args():
help="""The number of mel bins for Fbank""",
)
parser.add_argument(
"--speed-perturb",
type=bool,
"--perturb-speed",
type=str2bool,
default=False,
help="Enable 0.9 and 1.1 speed perturbation for data augmentation. Default: False.",
)
@ -131,5 +132,5 @@ if __name__ == "__main__":
args = get_args()
compute_fbank_alimeeting(
num_mel_bins=args.num_mel_bins, speed_perturb=args.speed_perturb
num_mel_bins=args.num_mel_bins, perturb_speed=args.perturb_speed
)

View File

@ -97,7 +97,7 @@ if [ $stage -le 5 ] && [ $stop_stage -ge 5 ]; then
log "Stage 5: Compute fbank for alimeeting"
if [ ! -f data/fbank/.alimeeting.done ]; then
mkdir -p data/fbank
./local/compute_fbank_alimeeting.py --speed-perturb True
./local/compute_fbank_alimeeting.py --perturb-speed True
touch data/fbank/.alimeeting.done
fi
fi

View File

@ -40,6 +40,8 @@ from lhotse.features.kaldifeat import (
)
from lhotse.recipes.utils import read_manifests_if_cached
from icefall.utils import str2bool
# Torch's multithreaded behavior needs to be disabled or
# it wastes a lot of CPU and slow things down.
# Do this outside of main() in case it needs to take effect
@ -49,7 +51,7 @@ torch.set_num_interop_threads(1)
torch.multiprocessing.set_sharing_strategy("file_system")
def compute_fbank_ami(speed_perturb: bool = False):
def compute_fbank_ami(perturb_speed: bool = False):
src_dir = Path("data/manifests")
output_dir = Path("data/fbank")
@ -89,6 +91,7 @@ def compute_fbank_ami(speed_perturb: bool = False):
cuts: CutSet, storage_path: Path, manifest_path: Path, speed_perturb: bool
) -> None:
if speed_perturb:
logging.info(f"Doing speed perturb")
cuts = cuts + cuts.perturb_speed(0.9) + cuts.perturb_speed(1.1)
_ = cuts.compute_and_store_features_batch(
extractor=extractor,
@ -113,7 +116,7 @@ def compute_fbank_ami(speed_perturb: bool = False):
cuts_ihm,
output_dir / "feats_train_ihm",
src_dir / "cuts_train_ihm.jsonl.gz",
speed_perturb,
perturb_speed,
)
logging.info("Processing train split IHM + reverberated IHM")
@ -122,7 +125,7 @@ def compute_fbank_ami(speed_perturb: bool = False):
cuts_ihm_rvb,
output_dir / "feats_train_ihm_rvb",
src_dir / "cuts_train_ihm_rvb.jsonl.gz",
speed_perturb,
perturb_speed,
)
logging.info("Processing train split SDM")
@ -135,7 +138,7 @@ def compute_fbank_ami(speed_perturb: bool = False):
cuts_sdm,
output_dir / "feats_train_sdm",
src_dir / "cuts_train_sdm.jsonl.gz",
speed_perturb,
perturb_speed,
)
logging.info("Processing train split GSS")
@ -148,7 +151,7 @@ def compute_fbank_ami(speed_perturb: bool = False):
cuts_gss,
output_dir / "feats_train_gss",
src_dir / "cuts_train_gss.jsonl.gz",
speed_perturb,
perturb_speed,
)
logging.info("Preparing test cuts: IHM, SDM, GSS (optional)")
@ -197,8 +200,8 @@ def compute_fbank_ami(speed_perturb: bool = False):
def get_args():
parser = argparse.ArgumentParser()
parser.add_argument(
"--speed-perturb",
type=bool,
"--perturb-speed",
type=str2bool,
default=False,
help="Enable 0.9 and 1.1 speed perturbation for data augmentation. Default: False.",
)
@ -211,4 +214,4 @@ if __name__ == "__main__":
args = get_args()
compute_fbank_ami(speed_perturb=args.speed_perturb)
compute_fbank_ami(perturb_speed=args.perturb_speed)

View File

@ -85,7 +85,7 @@ fi
if [ $stage -le 5 ] && [ $stop_stage -ge 5 ]; then
log "Stage 5: Compute fbank for alimeeting"
mkdir -p data/fbank
python local/compute_fbank_alimeeting.py --speed-perturb True
python local/compute_fbank_alimeeting.py --perturb-speed True
log "Combine features from train splits"
lhotse combine data/manifests/cuts_train_{ihm,ihm_rvb,sdm,gss}.jsonl.gz - | shuf |\
gzip -c > data/manifests/cuts_train_all.jsonl.gz

View File

@ -25,6 +25,7 @@ from lhotse import CutSet, SupervisionSegment
from lhotse.recipes.utils import read_manifests_if_cached
from icefall import setup_logger
from icefall.utils import str2bool
# Similar text filtering and normalization procedure as in:
# https://github.com/SpeechColab/WenetSpeech/blob/main/toolkits/kaldi/wenetspeech_data_prep.sh
@ -46,7 +47,7 @@ def has_no_oov(
return oov_pattern.search(sup.text) is None
def preprocess_wenet_speech(speed_perturb: bool = False):
def preprocess_wenet_speech(perturb_speed: bool = False):
src_dir = Path("data/manifests")
output_dir = Path("data/fbank")
output_dir.mkdir(exist_ok=True)
@ -111,7 +112,7 @@ def preprocess_wenet_speech(speed_perturb: bool = False):
)
# Run data augmentation that needs to be done in the
# time domain.
if partition not in ["DEV", "TEST_NET", "TEST_MEETING"] and speed_perturb:
if partition not in ["DEV", "TEST_NET", "TEST_MEETING"] and perturb_speed:
logging.info(
f"Speed perturb for {partition} with factors 0.9 and 1.1 "
"(Perturbing may take 8 minutes and saving may take 20 minutes)"
@ -124,8 +125,8 @@ def preprocess_wenet_speech(speed_perturb: bool = False):
def get_args():
parser = argparse.ArgumentParser()
parser.add_argument(
"--speed-perturb",
type=bool,
"--perturb-speed",
type=str2bool,
default=False,
help="Enable 0.9 and 1.1 speed perturbation for data augmentation. Default: False.",
)
@ -136,7 +137,7 @@ def main():
setup_logger(log_filename="./log-preprocess-wenetspeech")
args = get_args()
preprocess_wenet_speech(speed_perturb=args.speed_perturb)
preprocess_wenet_speech(perturb_speed=args.perturb_speed)
logging.info("Done")

View File

@ -91,7 +91,7 @@ fi
if [ $stage -le 3 ] && [ $stop_stage -ge 3 ]; then
log "Stage 3: Preprocess WenetSpeech manifest"
if [ ! -f data/fbank/.preprocess_complete ]; then
python3 ./local/preprocess_wenetspeech.py --speed-perturb True
python3 ./local/preprocess_wenetspeech.py --perturb-speed True
touch data/fbank/.preprocess_complete
fi
fi