예제 #1
0
import os
import pandas as pd

import shutil

from timit_prepare import prepare_timit

data_folder = "TIMIT"  # /path/to/TIMIT
splits = ["train", "dev", "test"]
save_folder = "TIMIT_prepared"
prepare_timit(data_folder, splits, save_folder)

train_df = pd.read_csv("TIMIT_prepared/train.csv")
train_df["wav"] = train_df["wav"].apply(
    lambda x: x.replace("TIMIT", "TIMIT_4_channels/TIMIT_LA2"))
train_df.to_csv("TIMIT_prepared/train.csv", index=False)

dev_df = pd.read_csv("TIMIT_prepared/dev.csv")
dev_df["wav"] = dev_df["wav"].apply(
    lambda x: x.replace("TIMIT", "TIMIT_4_channels/TIMIT_LA2"))
dev_df.to_csv("TIMIT_prepared/dev.csv", index=False)

test_df = pd.read_csv("TIMIT_prepared/test.csv")
test_df["wav"] = test_df["wav"].apply(
    lambda x: x.replace("TIMIT", "TIMIT_4_channels/TIMIT_LA2"))
test_df.to_csv("TIMIT_prepared/test.csv", index=False)

shutil.copy("TIMIT_prepared/train.csv", "TIMIT_4_channels/TIMIT_LA2")
shutil.copy("TIMIT_prepared/dev.csv", "TIMIT_4_channels/TIMIT_LA2")
shutil.copy("TIMIT_prepared/test.csv", "TIMIT_4_channels/TIMIT_LA2")
예제 #2
0
    def on_epoch_end(self, epoch, train_stats, valid_stats=None):
        per = summarize_error_rate(valid_stats["PER"])
        old_lr, new_lr = params.lr_annealing([params.optimizer], epoch, per)
        epoch_stats = {"epoch": epoch, "lr": old_lr}
        params.train_logger.log_stats(epoch_stats, train_stats, valid_stats)

        checkpointer.save_and_keep_only(
            meta={"PER": per},
            importance_keys=[ckpt_recency, lambda c: -c.meta["PER"]],
        )


# Prepare data
prepare_timit(
    data_folder=params.data_folder,
    splits=["train", "dev", "test"],
    save_folder=params.data_folder,
)
train_set = params.train_loader()
valid_set = params.valid_loader()
first_x, first_y = next(iter(train_set))

if hasattr(params, "augmentation"):
    modules.append(params.augmentation)
asr_brain = ASR(
    modules=modules,
    optimizer=params.optimizer,
    first_inputs=[first_x, first_y],
)

# Load latest checkpoint to resume training