CIFAR10-style image loader tutorial (NPY, offline) #
This tutorial mirrors a classic PyTorch recipe:
- Load a labeled image dataset from disk (
.npyexported from NumPy/PyTorch). - Split into train/test.
- Build a small CNN by explicitly stacking layers.
- Train for multiple epochs over shuffled minibatches through the public
TrainerAPI.
To keep this runnable without network downloads, generate a small deterministic "CIFAR10-shaped" dataset locally:
NN/Examples/Data/small_cifar10like_X.npy: shape(200, 3, 32, 32), dtypefloat32NN/Examples/Data/small_cifar10like_y.npy: shape(200,), dtypefloat32labels0..9
Generate it with:
python3 NN/Examples/Data/generate_small_data.py
Build:
lake build NN.Examples.Data.Loaders.Cifar10Images
For command-line CIFAR training, use torchlean cnn or torchlean vit with
--x, --y, and --n-total.
Optional flags (tutorial-specific):
--data-dir PATH(default:NN/Examples/Data)--real-cifar10(usedata/real/cifar10/cifar10_train_*.npy, as prepared byscripts/datasets/download_example_data.py --cifar10)--x PATH,--y PATH(override the.npyfiles)--n-total N(number of rows in the selected.npyfiles; default200)--seed S(controls split + shuffling + model initialization)--batch N--epochs E--lr LR(default:0.001)--train-size N(default: 160)--check-only(validate paths, tensor shapes, and dataset splitting without training)
Why this tutorial matters:
- it shows the public
Datafile-loading path rather than only in-memory tensors; - it keeps the model architecture familiar (Conv/ReLU/Pool stack + classifier head);
- it shows the "offline artifact" workflow many PyTorch users already have, where arrays
have been pre-exported to
.npyand training happens without any dataset download step. - it stays on the same public
Trainersurface as the model examples instead of dropping to the callback runner API. - it shows that the trained result is still usable for immediate inference, not only for a terminal loss summary.
Small CNN (no BatchNorm): Conv -> ReLU -> Pool -> Conv -> ReLU -> Pool -> Linear(10).
Instances For
Shared offline CIFAR10-like tensor source used by this tutorial.
Instances For
def
NN.Examples.Data.Loaders.Cifar10Images.trainDataset
(xPath yPath : System.FilePath)
(nRows trainSize seed : ℕ)
:
Instances For
def
NN.Examples.Data.Loaders.Cifar10Images.testDataset
(xPath yPath : System.FilePath)
(nRows trainSize seed : ℕ)
:
Runtime-polymorphic test split used for --check-only reporting.
Instances For
Command-line help for the CIFAR10-style NPY loader tutorial.