Model development
Training
You can run training from the repository root with the CLI. All arguments are entirely optional; running the command without any flags will automatically train on the default mnist dataset:
# Run with absolute defaults (MNIST, 1 epoch, batch size 64, automatic device selection)
python -m src.training
# Run with custom configuration overrides
python -m src.training --dataset mnist --epochs 5 --batch-size 32 --device cuda
The checkpoint is written to src/weights/<dataset>.pth by default. Training supports mnist, usps, and svhn out of the box; additional datasets can be registered in src/training.py.
Using a config file
Instead of passing all flags on the command line, you can use a config file with --config (-c). The configs/ directory contains ready-made configs for each dataset:
python -m src.training --config configs/mnist.cfg
python -m src.training --config configs/svhn.cfg
python -m src.training --config configs/usps.cfg
A config file is a plain key=value text file (lines starting with # are comments):
# configs/mnist.cfg
dataset=mnist
epochs=50
batch_size=32
Any CLI flag you pass explicitly will override the corresponding value in the config file — the priority order is CLI flag > config file > built-in default:
# Use the config but run only 5 epochs instead of 50
python -m src.training --config configs/mnist.cfg --epochs 5
Evaluation
After training, evaluate a model on its test set from the repository root:
# Evaluate the default MNIST model on CPU
python -m src.evaluation --dataset mnist
# Evaluate with a custom checkpoint on NVIDIA GPU
python -m src.evaluation --dataset svhn --checkpoint-path weights/svhn.pth --device cuda
# Evaluate on Apple Silicon
python -m src.evaluation --dataset svhn --checkpoint-path weights/svhn.pth --device mps
The command prints macro-averaged precision, macro-averaged recall, and average
inference time per sample. The test data is downloaded automatically on the first
run to the directory given by --data-dir (default: datasets/).
Argument |
Default |
Description |
|---|---|---|
|
|
Dataset to evaluate on: |
|
(registered default) |
Path to a |
|
|
Number of samples per batch. |
|
|
Root directory for dataset downloads. |
|
|
Number of DataLoader worker processes. |
|
|
PyTorch device: |
|
|
Logging verbosity: |
Testing
Run the basic tests with:
pytest -q
The tests are lightweight and only validate the training CLI, argument parsing, and factory wiring.
Contributing to the code
We use a branch → pull request → review workflow. All changes to main require at least one approved review — direct pushes are not allowed.
If you have write access to the repository:
Open an issue describing your change
Create a branch and commit your work (reference the issue, e.g.
fixes #5)Open a pull request towards
mainGet a review, address feedback, then merge
If you do not have write access (external contributors):
Fork the repository on GitHub
Clone your fork locally:
git clone https://github.com/<your-username>/Collaborative-Coding-Exam.gitCreate a branch in your fork and commit your work
Open a pull request from your fork towards
mainof this repositoryGet a review, address feedback, then merge
See CONTRIBUTION.md for the full guide.