Files
audio-driven-face-animation/README.md
T
2020-11-28 01:14:17 +01:00

4.6 KiB

Hackathon template

A convenient starting template for most deep learning projects. Built with PyTorch Lightning and Weights&Biases.

Setup

Read SETUP.md for more info or just do this quick setup:

    git clone https://github.com/kinoai/hackathon-template
    cd hackathon-template
    conda update conda
    conda env create -f conda_env.yml -n hack_env
    conda activate hack_env
    pip install -r requirements.txt
    wandb login
    cd project
    python train.py

Project structure

The directory structure of new project looks like this:

├── project
│   ├── data                    <- Data from third party sources
│   │
│   ├── logs                    <- Logs generated by Weights&Biases and PyTorch Lightning
│   │
│   ├── notebooks               <- Jupyter notebooks
│   │
│   ├── utils                   <- Different utilities
│   │   ├── callbacks.py            <- Useful training callbacks
│   │   ├── execute_sweep.py        <- Special file for executing Weights&Biases sweeps
│   │   ├── init_utils.py           <- Useful initializers
│   │   └── predict_example.py      <- Example of inference with trained model 
│   │
│   ├── data_modules            <- All your data modules should be located here!
│   │   ├── example_datamodule      <- Each datamodule should be located in separate folder!
│   │   │   ├── datamodule.py           <- Contains 'DataModule' class
│   │   │   ├── datasets.py             <- Contains pytorch 'Dataset' classes
│   │   │   └── transforms.py           <- Contains data transformations
│   │   ├── ...
│   │   └── ...
│   │
│   ├── models                  <- All your models should be located here!
│   │   ├── example_model           <- Each model should be located in separate folder!
│   │   │   ├── lightning_module.py     <- Contains 'LitModel' class with train/val/test step methods
│   │   │   └── models.py               <- Model architectures used by lightning_module.py
│   │   ├── ...
│   │   └── ...
│   │
│   ├── project_config.yaml     <- Project configuration
│   ├── run_configs.yaml        <- Configurations of different runs/experiments
│   └── train.py                <- Train model with chosen run configuration
│
├── .gitignore
├── LICENSE
├── README.md
├── SETUP.md
└── requirements.txt

Project config parameters (project_config.yaml)

num_of_gpus: -1

resume_training:
    lightning_ckpt:
        resume_from_ckpt: False
        ckpt_path: "logs/checkpoints/epoch=2.ckpt"
    wandb:
        resume_wandb_run: False
        wandb_run_id: "8uuomodb"

loggers:
    wandb:
        project: "hackathon_template_test"
        team: "kino"
        group: None
        job_type: "train"
        tags: []
        log_model: True
        offline: False

callbacks:
    checkpoint:
        monitor: "val_acc"
        save_top_k: 1
        save_last: True
        mode: "max"
    early_stop:
        monitor: "val_acc"
        patience: 100
        mode: "max"

printing:
    progress_bar_refresh_rate: 5
    weights_summary: "top"  # "full"
    profiler: False

Run config parameters (run_configs.yaml)

You can store many run configurations in this file.
Example run configuration:

MNIST_CLASSIFIER_V1:
    trainer:
        min_epochs: 1
        max_epochs: 5
        gradient_clip_val: 0.5
        accumulate_grad_batches: 1
        limit_train_batches: 1.0
    model:
        model_folder: "simple_mnist_classifier"
        lr: 0.001
        weight_decay: 0.000001
        input_size: 784  # img size is 1*28*28
        output_size: 10  # there are 10 digit classes
        lin1_size: 256
        lin2_size: 256
        lin3_size: 128
    dataset:
        datamodule_folder: "mnist_digits_datamodule"
        batch_size: 256
        train_val_split_ratio: 0.9
        num_workers: 4
        pin_memory: True

To run training pass run config name as an argument:

    python train.py -c MNIST_CLASSIFIER_V1
    python train.py --conf_name MNIST_CLASSIFIER_V1

Or modify default run config name in train.py:

if __name__ == "__main__":
    parser = ArgumentParser()
    parser.add_argument("-c", "--conf_name", type=str, default="MNIST_CLASSIFIER_V1")
    args = parser.parse_args()

    main(run_config_name=args.conf_name)