lightning/examples/fabric/kfold_cv
Adrian Wälchli 9ff7d7120b
Add `rank_zero_first` utility (#17784)
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
2023-06-12 10:32:32 +00:00
..
README.md docs: update broken links & latest/stable (#16994) 2023-03-15 20:19:41 +01:00
train_fabric.py Add `rank_zero_first` utility (#17784) 2023-06-12 10:32:32 +00:00

README.md

K-Fold Cross Validation

This is an example of performing K-Fold cross validation supported with Lightning Fabric. To learn more about cross validation, check out this article.

We use the MNIST dataset to train a simple CNN model. We create the k-fold cross validation splits using the ModelSelection.KFold class in the scikit-learn library. Ensure that you have the scikit-learn library installed;

pip install scikit-learn

Run K-Fold Image Classification with Lightning Fabric

This script shows you how to scale the pure PyTorch code to enable GPU and multi-GPU training using Lightning Fabric.

# CPU
lightning run model train_fabric.py

# GPU (CUDA or M1 Mac)
lightning run model train_fabric.py --accelerator=gpu

# Multiple GPUs
lightning run model train_fabric.py --accelerator=gpu --devices=4

References