|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
""" |
|
# Training the model |
|
|
|
Basic run (on CPU for 50 epochs): |
|
python examples/asr/experimental/audio_to_audio/speech_enhancement.py \ |
|
# (Optional: --config-path=<path to dir of configs> --config-name=<name of config without .yaml>) \ |
|
model.train_ds.manifest_filepath="<path to manifest file>" \ |
|
model.validation_ds.manifest_filepath="<path to manifest file>" \ |
|
trainer.devices=1 \ |
|
trainer.accelerator='cpu' \ |
|
trainer.max_epochs=50 |
|
|
|
PyTorch Lightning Trainer arguments and args of the model and the optimizer can be added or overriden from CLI |
|
""" |
|
import pytorch_lightning as pl |
|
import torch |
|
from omegaconf import OmegaConf |
|
|
|
from nemo.collections.asr.models import EncMaskDecAudioToAudioModel |
|
from nemo.core.config import hydra_runner |
|
from nemo.utils import logging |
|
from nemo.utils.exp_manager import exp_manager |
|
|
|
|
|
@hydra_runner(config_path="./conf", config_name="multichannel_enhancement") |
|
def main(cfg): |
|
logging.info(f'Hydra config: {OmegaConf.to_yaml(cfg, resolve=True)}') |
|
|
|
trainer = pl.Trainer(**cfg.trainer) |
|
exp_manager(trainer, cfg.get("exp_manager", None)) |
|
model = EncMaskDecAudioToAudioModel(cfg=cfg.model, trainer=trainer) |
|
|
|
|
|
model.maybe_init_from_pretrained_checkpoint(cfg) |
|
|
|
|
|
trainer.fit(model) |
|
|
|
|
|
if hasattr(cfg.model, 'test_ds') and cfg.model.test_ds.manifest_filepath is not None: |
|
if trainer.is_global_zero: |
|
|
|
if torch.distributed.is_initialized(): |
|
torch.distributed.destroy_process_group() |
|
|
|
|
|
trainer = pl.Trainer(devices=1, accelerator=cfg.trainer.accelerator) |
|
if model.prepare_test(trainer): |
|
trainer.test(model) |
|
|
|
|
|
if __name__ == '__main__': |
|
main() |
|
|