The dataset viewer is not available because its heuristics could not detect any supported data files. You can try uploading some data files, or configuring the data files location manually.
YAML Metadata Warning:empty or missing yaml metadata in repo card
Check out the documentation for more information.
Uncertainty Quantification with Online Handwriting Recognition Data
This package accompanies the paper for the project course "Consulting" and provides the means to replicate its results. We present the code to reproduce the Bayesian NNs and evaluate the associated uncertainty metrics.
Getting Started
Prerequisites
- Linux or Windows
- NVIDIA GPU + CUDA CuDNN. Standalone CPU should work but we strongly advise to use CUDA since it is considerably faster and our code was optimized for it.
- Python 3.9+
Installation
git clone https://gitlab.cc-asp.fraunhofer.de/ottf/uncertainty_quantification.git
cd uncertainty_quantification
pip install -r requirements.txt
Dependencies are in the requirements.txt.
Repository Structure
| Folder | Description |
|---|---|
| uncertainty_quantification | Root folder |
| β archiv | Archive containing mostly data prepping and tensorflow scripts from our predecessors. |
| β bash_scripts | (Exemplary) bash scripts to run the training/validation/hpo. |
| β datasets | Data from the "Schreibtrainer" project, including left-handed observations. |
| β onhw | Main folder with everything related to OnHW analysis. |
| β β evaluation | Folder containing scripts/notebooks to evaluate best models. |
| β β hpo | Folder containing scripts for hyperparameter optimization with Bayesian Optimization. |
| β β model | Folder containing architecture-related scripts. |
| β β train | Folder containing training scripts. |
| β β validation | Folder containing validation scripts. |
| β presentation | Folder containing paper and presentation w/ according plots and scripts to recreate them. |
| β β metrics_models | Folder metrics of best performing models as .pkl . |
| β β plots | Folder containing plots from presentation and paper. Additional plots for winner models are provided in subfolders |
| β β β cutoff | Folder containing the plots for the cutoff analysis. |
| β β β heatmaps | Folder containing heatmaps for aleatoric uncertainty/epistemic uncertainty/confusion matrices. |
| β β β individual_uncertainty | Folder containing entropy and MI plots per writer line. |
| β β β letters | Folder containing entropy and MI plots per letter. |
| β β β reliability | Folder containing calibration plots split by both/left/right. |
| β results | Folder containing trained models, split by data situation. Additionally, Excel tables for a performance overview with R scripts to scrape through results and create aggregated tables. |
| β β hpo_runs | Folder containing experiments for HPO with BO. |
| β swa_gaussian | Copy of SWAG implementation, modified to our needs. Meant to be called as a module. |
| β vadam | Copy of VOGN implementation, modified to our needs. Meant to be called as a module. |
Training
Remark: .py scripts starting with "exec_*" contain a name == "main" functionality so that they can be executed by bash etc.
For training, choose which model to train by choosing the fitting script in onhw/train/ and specifying the desired data configuration (e.g. writer dependent, uppercase character). Additionally, set up training specs like patience (=tolerance) in terms of epochs, how often to check performance on the validation set (=epochs_to_check_val_at), how many Monte Carlo samples to draw for checking validation performance (=mc_samples) etc. .
Optimally, hyperparameters like learning rate or precision parameter $\lambda$ in surrogate distribution $q(\theta$) have been tuned, previously (see HPO section).
Example for training 2 configurations
python onhw/train/exec_train_swag.py --mc_samples 20 \
--burn_in 5 \
--tolerance 80 \
--run_TCN true \
--run_LSTM false \
--run_BILSTM false \
--which_split 3 \
--writer_dependant indep \
--which_char upper \
--epochs_to_check_val_at 1
python onhw/train/exec_train_vprop.py --mc_samples 20 \
--prior_prec 25.3 \
--prec_init 3.7 \
--beta 0.7 \
--tolerance 200 \
--run_TCN false \
--run_LSTM false \
--run_BILSTM true \
--which_split 4 \
--writer_dependant dep \
--which_char lower \
--epochs_to_check_val_at 10
Validation
Do inference: in order to sample (e.g. 100 times) from a trained model and analyze the performance and uncertainty metrics on the held out test set, call one of the scripts in onhw/validation/. Importantly, choose the number of Monte Carlo samples and provide the path to the trained models. The script will identify the most recent/best performing epochs as well as load the Evalplotter which has been collecting all metrics during training, every couple of epochs.
This will yield:
- an Excel table with results on the test set
- heatmaps for aleatoric/epistemic uncertainty + confusion matrix for the test set
- plots showing the validation performance over the course of the training.
Example for testing 1 configuration + saving validation metrics.
python onhw/validation/exec_validate_swag.py --mc_samples 100 \
--path results/onhw2_lower_indep/ensemble/BILSTM_norm_interpolated_17_0.7177_split_0
HPO with Bo
Per default, HPO results are saved in results/hpo_runs/ with the folder name indicating the specific run (model setting + timestamp). Analyzing the Excel table is generally enough. For loading the associated .pkl files, please use onhw/evaluation/get_hpo_results.ipynb.
Example for tuning 1 configuration
python onhw/hpo/exec_hpo_bo_vadam.py --hpo_init_trials 20 \
--hpo_total_trials 60 \
--print_chosen_params true \
--epochs 400 \
--exp_name test_experiment_abc
Evaluation
Please refer to onhw/evaluation/descriptive_analysis_best_models.ipynb. For simply seeing the according plots without rerunning the notebook: presentation/plots has all crucial plots that were made in the python notebook.
Further results
VAdam and VProp converge very late, producing large training folders. In order to save disk space, we outsourced the trained results to https://syncandshare.lrz.de/getlink/fi53d5akCJxp75LJMYfW9qn6/ (see vogn_results/). These results are rather complementary since these methods perform poorly, anyway.
Kudos
SWAG Implementation: https://github.com/wjmaddox/swa_gaussian
VOGN Implementation: https://github.com/emtiyaz/vadam
Ensemble Implementation: Based on the SWAG training config, since SWAG also trains frequentist models in the background.
OnHW Data and Previous Work https://dl.acm.org/doi/abs/10.1145/3411842
For a complete reference list, please refer to the paper (presentation/Consulting_UQ_OnHW.pdf).
- Downloads last month
- 153