Template code for audio model, using Pytorch Lightning and wandb.
First, excecute following line, in terminal. It ensures pyton to recognize its packages and modules.
export PYTHONPATH="${PYTHONPATH}:/path/of/the/project/src/directory"
- All the sound file data (
'*.wav') should be located in one directory, each for train and test. - CSV file with two columns,
'file_path'and'label'should be prepared, each for train and test.'file_path'should be a path after the train(or test) directory. For example, a soundfile 'dataset/train/data1.wav's path on CSV is 'data1.wav'.'label'should be an integer. - In
src/ml/script/main.py, type the path of data directory and csv file, each for train and test.
- To use
wandblogger, Type yourwandbapi-key insideconfig/wandb-api-key.txt. - Modify
config/config.yamlfile as you want. - Modify
DATA_DIRvariable insrc/ml/util/constants.pywith the path of data for training. All the data should be inside that directory. - Run following line in a terminal.
python scripts/main.py --train
python scripts/main.py --train -n 'wandb-run-name'
python scripts/main.py --train -c 'model checkpoint file path' --run-id 'run-id of previous wandb run --last-epoch 'last epoch number'
Can omit '--run-id' if not using wandb.
Can omit '--last-epoch' if not using learning rate scheduler.
python scripts/main.py --train --tune
It will automatically find the best lr and start training with it. Graph image of lr_finder is saved in lr_finder.png.
python scripts/main.py --test -c 'model checkpoint file path'
It saves submission.csv file in a root directory.
python utils/EDA.py
If you encounter an error while using a Hugging Face model, in most cases, reducing the batch size resolves the issue.