The baseline folder of this repo contains code for running the "baseline" models that provide a point of comparison for the three state-of-the-art models deployed during the Autumn 2023 quarter of the Data Science Clinic. This guide explains how to run the baseline model for classifying architectural styles using ResNet18, ResNet34, or a custom CNN.
- Python 3
- Access to a Unix-like terminal (bash)
- Conda environment (with dependencies installed)
To re-create the environment used for the baseline model and UNICOM, use the command conda env create -f env.yml
baseline_reproduce.py
: Python script for training and evaluating the model.train.sh
: Shell script for setting up the environment and running the Python script.baseline_config.json
: Configuration file with parameters for training.
Create a new folder in your desired location: mkdir <folder name>
. This folder will be used to store output files and error logs.
Edit the train.sh
file to update the following:
- REQUIRED: Replace both instances of the folder path for output and error logs with the path of the folder you just created.
- REQUIRED: Update the
OUT_DIR
variable with the path of the newly created folder. - OPTIONAL: Include the
--transfer
tag if you want to implement transfer learning instead of the custom CNN. - OPTIONAL: If you want to read in a saved model, update the
CHECKPOINT
variable to the path of the model you want to use and include the--checkpoint ${CHECKPOINT}
tag.
Edit the baseline_config.json
file:
- Change the
where_to_save_checkpoint_path
to the path where you want to save the model checkpoint. Give the file name a descriptive name so you can distinguish between your different models. - Update the parameters for the model you want to run. A couple of notes about the limitations on these parameters: (1) The
resnet
variable takes values 18 or 34. (2) The custom CNN only takes an image size and batch size of 32.
If you are using a pre-trained checkpoint:
- Update the
CHECKPOINT
variable intrain.sh
with the path to your checkpoint file.
If you are not using a pre-trained checkpoint:
- Comment out or remove the
--checkpoint ${CHECKPOINT}
part intrain.sh
.
In the terminal, navigate to the directory containing train.sh
and run:
sbatch train.sh
In the terminal, activate the virtual environment:
conda activate unicom_env
Define the variables CONFIG-PATH
, CHECKPOINT
, and OUT_DIR
:
CONFIG_PATH="baseline_config.json"
CHECKPOINT="/net/projects/amfam/baseline/<INSERT CHECKPOINT FILE NAME>.pth"
OUT_DIR="<INSERT OUT DIR FILE NAME>"
Run:
python3 baseline_reproduce.py --config ${CONFIG_PATH} --out_dir ${OUT_DIR} --transfer --checkpoint ${CHECKPOINT}
conda activate unicom_env
CONFIG_PATH="baseline_config.json"
CHECKPOINT="/net/projects/amfam/baseline/customCNN_e80_is32.pth"
OUT_DIR="output_customCNN_e80_is32"
python3 baseline_reproduce.py --config ${CONFIG_PATH} --out_dir ${OUT_DIR} --transfer --checkpoint ${CHECKPOINT}
Model | Accuracy | Download Link |
---|---|---|
Baseline@32px | 25% | Download |
Baseline/ResNet-34@224px | 71% | Download |
Baseline/ResNet-18@512px | 73% | Download |
Model | Accuracy |
---|---|
Baseline@32px | 25% |
Baseline/ResNet-18@32px | 38% |
Baseline/ResNet-18@128px | 51% |
Baseline/ResNet-18@224px | 60% |
Baseline/ResNet-18@256px | 70% |
Baseline/ResNet-18@512px | 73% |
Baseline/ResNet-34@224px | 71% |
Baseline/ResNet-34@256px | 71% |
Baseline/ResNet-34@512px | 70% |
The below graph is from training ResNet-18@224px. This type of graph is produced during each round of training.