Project requirements: https://docs.google.com/document/d/1ZUdQ7c2X7y_KWobwZG0y0uFpwe__K1Hs1I_rv5jR3ws/edit?usp=sharing
- Python 3.8 or later
- You may remove
typing.Final
type hints to use this project with earlier Python versions
- You may remove
- Install all requirements in
requirements.txt
- Using
pip
:pip install -r requirements.txt
- Using
constant.py
: Constantsdataset.py
: The CIFAR_SFU dataset, copied from the handout notebook, unmodifieddensenet.py
: The DenseNet modelepoch_logger.py
: Logs the train/validation losses/accuracies into 2 files:train_log.csv
andvalidation_log.csv
epoch_visualizer.py
: Generates the training loss & validation plot- Copied from the handout notebook
- Slightly modified to show fewer x labels (showing 400 x labels for 400 epochs is unfeasible)
infer.py
: Generates the Kaggle submission csv using the test settrain.py
: The training script- Files with filenames ending with
_test
are Python unit tests
Most scripts are using the argparse
module to parse their command line arguments.
Use -h
on a script to view all available arguments.
Run the train.py
script with arguments specifying where to save the checkpoints and logs.
python train.py --checkpoint_save_dir=checkpoints --train_log_filename=checkpoints/train_log.csv --validation_log_filename=checkpoints/validation_log.csv
- Network weights are saved in
checkpoint_save_dir
- Training and validation logs (accuracies, losses, etc.) are saved in
train_log_filename
andvalidation_log_filename
respectively
Training takes about 4 hours on a machine with i7-9700K and RTX 2080.
The epoch_visualizer.py
script reads checkpoints/train_log.csv
and checkpoints/validation_log.csv
to generate a plot of training losses and validation accuracies.
It then saves it as checkpoints/plot.png
.
Run the infer.py
script with arguments specifying the checkpoint location and prediction csv location.
python infer.py --checkpoint_filename=../0.4-128batch/400.pth --csv_filename=predictions.csv
- Loads network weights from
checkpoint_filename
- Saves test set predictions in
csv_filename
Pre-trained network weights are available at: https://github.com/MacJim/CMPT-762-Assignment-2-Checkpoints
The 0.4-128batch/400.pth
weights have the best test accuracy 0.76500 (runner-up in our Kaggle competition).
- SFU CMPT 762 home page: https://www2.cs.sfu.ca/~furukawa/cmpt762-2021-spring/
- CIFAR-100 dataset: https://www.cs.toronto.edu/~kriz/cifar.html
- DenseNet: https://arxiv.org/abs/1608.06993