Image Classification
PyTorch
timm
facial-expression-recognition
driver-monitoring
vision-transformer
parameter-efficient-fine-tuning
lora
adaptformer
Instructions to use headless-start/parameter-efficient-dfer with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- timm
How to use headless-start/parameter-efficient-dfer with timm:
import timm model = timm.create_model("hf-hub:headless-start/parameter-efficient-dfer", pretrained=True) - Notebooks
- Google Colab
- Kaggle
Update model card
Browse files
README.md
CHANGED
|
@@ -18,128 +18,123 @@ metrics:
|
|
| 18 |
|
| 19 |
# Parameter-Efficient Adaptation of Facial Expression Recognition Models for Driver Monitoring
|
| 20 |
|
| 21 |
-
Trained weights for the MSc thesis
|
|
|
|
| 22 |
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
(Stage 2): full fine-tuning, a linear probe, SSF, LoRA and AdaptFormer.
|
| 27 |
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
configuration, 51 checkpoints in total, together with the per-fold metrics,
|
| 31 |
-
per-frame predictions and selection records. No image data is included.
|
| 32 |
|
| 33 |
-
|
|
|
|
|
|
|
|
|
|
| 34 |
|
| 35 |
-
##
|
| 36 |
-
|
| 37 |
-
### Stage 1: FER+ (six classes)
|
| 38 |
-
|
| 39 |
-
Learning rate selected from {1e-5, 3e-5, 1e-4} on the official validation split;
|
| 40 |
-
the test split was evaluated once, for the selected checkpoint.
|
| 41 |
-
|
| 42 |
-
| Learning rate | Epoch kept | Val. accuracy | Test accuracy | Test UAR | Test weighted F1 |
|
| 43 |
-
|---|---|---|---|---|---|
|
| 44 |
-
| 1e-5 | 28 | 94.36 | 93.21 | 81.40 | 93.13 |
|
| 45 |
-
|
| 46 |
-
### Stage 2: KMU-FED, ten-fold cross-validation
|
| 47 |
-
|
| 48 |
-
Mean over the ten held-out folds (110 frames each); ± is the standard deviation
|
| 49 |
-
across folds, reported as spread only.
|
| 50 |
-
|
| 51 |
-
| Strategy | Selected configuration | Trainable parameters | Accuracy (%) | UAR (%) | Weighted F1 (%) |
|
| 52 |
-
|---|---|---|---|---|---|
|
| 53 |
-
| LoRA | lr 1e-3, rank 4 | 152,070 (0.177%) | 99.00 ± 2.59 | 98.56 | 98.83 |
|
| 54 |
-
| AdaptFormer | lr 1e-3, bottleneck 64 (reduction factor 12) | 1,194,246 (1.373%) | 98.45 ± 2.43 | 98.21 | 98.40 |
|
| 55 |
-
| SSF | lr 3e-3 | 210,438 (0.245%) | 97.91 ± 2.88 | 97.48 | 97.75 |
|
| 56 |
-
| Full fine-tuning | lr 3e-5 | 85,803,270 (100%) | 97.55 ± 4.11 | 96.87 | 97.25 |
|
| 57 |
-
| Linear probe | lr 3e-3 | 4,614 (0.005%) | 93.27 ± 6.83 | 92.76 | 92.42 |
|
| 58 |
-
|
| 59 |
-
### How to read these numbers
|
| 60 |
-
|
| 61 |
-
- Folds are contiguous per-class blocks of frames, so the same drivers appear in
|
| 62 |
-
training and test. The results describe familiar drivers, not unseen ones.
|
| 63 |
-
- Each fold keeps the epoch with the highest accuracy on its own held-out block,
|
| 64 |
-
and each strategy's configuration was chosen by mean accuracy over the same ten
|
| 65 |
-
folds. Both choices make the estimates optimistic. There is no separate
|
| 66 |
-
validation split at Stage 2.
|
| 67 |
-
- One seed (42) was used throughout.
|
| 68 |
-
|
| 69 |
-
## Repository layout
|
| 70 |
-
|
| 71 |
-
```text
|
| 72 |
-
stage1/
|
| 73 |
-
best.ckpt full ViT-B/16 fine-tuned on FER+ (sha256 3094f103c17bd135...)
|
| 74 |
-
results.json validation history and test metrics
|
| 75 |
-
study.json the three learning-rate candidates and the selection rule
|
| 76 |
-
stage2/<strategy>/
|
| 77 |
-
selection.json every candidate's ten-fold mean accuracy and the selected configuration
|
| 78 |
-
search_summary.json summary of the strategy's search
|
| 79 |
-
fold_00 ... fold_09/
|
| 80 |
-
best.ckpt retained checkpoint for that fold
|
| 81 |
-
results.json metrics, per-class recall, confusion matrix, training history
|
| 82 |
-
predictions.json label, prediction and probabilities for every held-out frame
|
| 83 |
-
load_weights.py loads any checkpoint into the model of the code release
|
| 84 |
-
```
|
| 85 |
|
| 86 |
-
|
| 87 |
-
|
| 88 |
-
|
| 89 |
-
trained parameters and the classification head (0.02 to 4.8 MB), which are
|
| 90 |
-
applied on top of the Stage-1 encoder.
|
| 91 |
|
| 92 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 93 |
|
| 94 |
-
|
| 95 |
-
|
| 96 |
-
|
| 97 |
|
| 98 |
-
|
| 99 |
-
from load_weights import load_stage2
|
| 100 |
|
| 101 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 102 |
```
|
| 103 |
|
| 104 |
-
|
| 105 |
-
|
| 106 |
-
|
| 107 |
-
|
| 108 |
-
|
| 109 |
-
|
| 110 |
-
every fold it reproduces the stored prediction for all 110 held-out frames.
|
| 111 |
|
| 112 |
-
|
| 113 |
-
|
| 114 |
|
| 115 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 116 |
|
| 117 |
-
|
| 118 |
-
|
| 119 |
-
|
| 120 |
-
|
| 121 |
-
|
| 122 |
-
|
| 123 |
-
| Batch, precision | 32, mixed precision | same |
|
| 124 |
-
| Augmentation | grayscale flip, rotation ±15°, translation, scale 0.90-1.10, shear, blur, erasing | same, rotation ±30° and scale 0.75-1.15 |
|
| 125 |
-
| Search | learning rate | learning rate, then rank (LoRA) or bottleneck width (AdaptFormer) at the selected rate |
|
| 126 |
|
| 127 |
-
|
|
|
|
|
|
|
|
|
|
| 128 |
|
| 129 |
-
|
| 130 |
-
were trained on FER+ (FER2013 images with the Microsoft FER+ labels) and on
|
| 131 |
-
KMU-FED, which is available from its authors on request; the terms of those
|
| 132 |
-
datasets and of the pretrained ViT checkpoint continue to apply. The Stage-2
|
| 133 |
-
models were trained and evaluated on a small number of drivers and are not
|
| 134 |
-
suitable for any decision about a real person.
|
| 135 |
|
| 136 |
-
|
|
|
|
|
|
|
| 137 |
|
| 138 |
```bibtex
|
| 139 |
@mastersthesis{tiwari2026peft_dfer,
|
| 140 |
author = {Ayush Tiwari},
|
| 141 |
-
title
|
| 142 |
school = {Brandenburgische Technische Universit{\"a}t Cottbus-Senftenberg},
|
| 143 |
-
year
|
| 144 |
}
|
| 145 |
```
|
|
|
|
| 18 |
|
| 19 |
# Parameter-Efficient Adaptation of Facial Expression Recognition Models for Driver Monitoring
|
| 20 |
|
| 21 |
+
Trained weights for the MSc thesis by **Ayush Tiwari**, BTU
|
| 22 |
+
Cottbus-Senftenberg, 2026.
|
| 23 |
|
| 24 |
+
[Code and training instructions](https://github.com/headless-start/parameter-efficient-dfer)
|
| 25 |
+
· [Weight files](https://huggingface.co/headless-start/parameter-efficient-dfer/tree/main)
|
| 26 |
+
· [Author profile](https://huggingface.co/headless-start)
|
|
|
|
| 27 |
|
| 28 |
+
The code repository is currently a private preview; its link becomes accessible
|
| 29 |
+
to everyone when the code is published. The weights here are public.
|
|
|
|
|
|
|
| 30 |
|
| 31 |
+
A public ImageNet-pretrained ViT-B/16 is fine-tuned on six-class FER+ (Stage 1),
|
| 32 |
+
then its encoder is adapted to KMU-FED with a fresh classifier (Stage 2).
|
| 33 |
+
Five strategies are provided: full fine-tuning, linear probe, AdaptFormer,
|
| 34 |
+
LoRA and SSF.
|
| 35 |
|
| 36 |
+
## Contents
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 37 |
|
| 38 |
+
There are **51 checkpoints**: one selected FER+ model and ten held-out-fold
|
| 39 |
+
models for each selected KMU-FED strategy. Per-fold results, predictions and
|
| 40 |
+
search-selection summaries accompany the weights. No image data is included.
|
|
|
|
|
|
|
| 41 |
|
| 42 |
+
| Path | Contents |
|
| 43 |
+
|---|---|
|
| 44 |
+
| `stage1/best.ckpt` | Complete FER+-adapted model |
|
| 45 |
+
| `stage2/<strategy>/fold_00/` … `fold_09/` | Fold weights, results and predictions |
|
| 46 |
+
| `stage2/<strategy>/selection.json` | Search scores and selected configuration |
|
| 47 |
+
| `load_weights.py` | Loader for the accompanying code release |
|
| 48 |
|
| 49 |
+
Full fine-tuning stores complete networks. The other Stage-2 strategies store
|
| 50 |
+
trained parameters and their classifier; the loader combines them with the
|
| 51 |
+
Stage-1 encoder. There is no separately trained all-data deployment model.
|
| 52 |
|
| 53 |
+
## Results
|
|
|
|
| 54 |
|
| 55 |
+
FER+ six-class test: **93.21% accuracy**, **81.40% UAR**, **93.13% weighted F1**.
|
| 56 |
+
The learning rate (1e-5) and epoch (28) were selected on the official validation
|
| 57 |
+
split; the selected model was tested once.
|
| 58 |
+
|
| 59 |
+
KMU-FED values below are **fold means**; accuracy ± is sample standard deviation
|
| 60 |
+
across ten folds. The thesis and code README instead report **pooled weighted
|
| 61 |
+
F1**, which differs from averaging fold F1 scores.
|
| 62 |
+
|
| 63 |
+
| Strategy | Selected setting | Trainable parameters | Accuracy (%) | UAR (%) | Fold-mean weighted F1 (%) |
|
| 64 |
+
|---|---|---:|---:|---:|---:|
|
| 65 |
+
| Full fine-tuning | lr 3e-5 | 85,803,270 | 97.55 ± 4.11 | 96.87 | 97.25 |
|
| 66 |
+
| Linear probe | lr 3e-3 | 4,614 | 93.27 ± 6.83 | 92.76 | 92.42 |
|
| 67 |
+
| AdaptFormer | lr 1e-3, width 64 (reduction 12) | 1,194,246 | 98.45 ± 2.43 | 98.21 | 98.40 |
|
| 68 |
+
| LoRA | lr 1e-3, rank 4 | 152,070 | 99.00 ± 2.59 | 98.56 | 98.83 |
|
| 69 |
+
| SSF | lr 3e-3 | 210,438 | 97.91 ± 2.88 | 97.48 | 97.75 |
|
| 70 |
+
|
| 71 |
+
Both the retained epoch and configuration were selected on the reported folds,
|
| 72 |
+
so these are optimistic, best-observed estimates. Folds share drivers and
|
| 73 |
+
sequences; they measure familiar-driver performance. Fold spread is descriptive,
|
| 74 |
+
with one base seed (42) and deterministic fold-specific initialisation. The study
|
| 75 |
+
does not establish equivalence, condition-specific robustness, the benefit of
|
| 76 |
+
the intermediate FER+ stage, or inference speed.
|
| 77 |
+
|
| 78 |
+
## Use the weights
|
| 79 |
+
|
| 80 |
+
Install the accompanying code release's requirements and run from its root
|
| 81 |
+
directory. The loader needs its `methods.py`, `data.py` and `experiment.py`;
|
| 82 |
+
the checkpoint files alone are not a Transformers pipeline.
|
| 83 |
+
|
| 84 |
+
Download the helper at the verified weight revision:
|
| 85 |
+
|
| 86 |
+
```bash
|
| 87 |
+
python - <<'PY'
|
| 88 |
+
from huggingface_hub import hf_hub_download
|
| 89 |
+
hf_hub_download(
|
| 90 |
+
"headless-start/parameter-efficient-dfer", "load_weights.py",
|
| 91 |
+
revision="92a70a21dc4810e346d7daf7b4e3c04b7dc721bb",
|
| 92 |
+
local_dir="runs/released",
|
| 93 |
+
)
|
| 94 |
+
PY
|
| 95 |
```
|
| 96 |
|
| 97 |
+
```python
|
| 98 |
+
import sys
|
| 99 |
+
import torch
|
| 100 |
+
from PIL import Image
|
| 101 |
+
from data import build_transform
|
| 102 |
+
from experiment import CLASS_NAMES
|
|
|
|
| 103 |
|
| 104 |
+
sys.path.insert(0, "runs/released")
|
| 105 |
+
from load_weights import load_stage2
|
| 106 |
|
| 107 |
+
model = load_stage2("lora", fold=0)
|
| 108 |
+
with Image.open("face_crop.jpg") as image:
|
| 109 |
+
x = build_transform(False, kmufed=True)(image.convert("RGB"))[None]
|
| 110 |
+
with torch.inference_mode():
|
| 111 |
+
predicted = model(x).argmax(1).item()
|
| 112 |
+
print(CLASS_NAMES[predicted])
|
| 113 |
+
```
|
| 114 |
|
| 115 |
+
The loader downloads the required weights and returns an evaluation-mode model.
|
| 116 |
+
Use `load_stage1()` for FER+ or `load_stage2(method, fold)` for KMU-FED;
|
| 117 |
+
methods are `full_ft`, `linear_probe`, `adaptformer`, `lora`, `ssf`, and folds
|
| 118 |
+
are zero-based (`0`–`9`). Class order is `angry, disgust, fear, happy, sad,
|
| 119 |
+
surprise`. Inputs must be face crops; preprocessing makes three-channel grayscale,
|
| 120 |
+
resizes to 224 × 224 with bicubic interpolation and normalises with mean/std 0.5.
|
|
|
|
|
|
|
|
|
|
| 121 |
|
| 122 |
+
These original-format weights are for inference through the helper, not
|
| 123 |
+
`--resume` inputs for the standalone training scripts. Hosted result JSONs also
|
| 124 |
+
use the original format; the code release's plotter reads its own training
|
| 125 |
+
outputs. The supplied loader retains adapter modules rather than merging them.
|
| 126 |
|
| 127 |
+
## Licence and citation
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 128 |
|
| 129 |
+
Weights: **CC BY-NC 4.0**. The code release is MIT-licensed. Dataset and
|
| 130 |
+
pretrained-weight terms remain with their providers. These are research models
|
| 131 |
+
evaluated on a small driver corpus, without validation for operational use.
|
| 132 |
|
| 133 |
```bibtex
|
| 134 |
@mastersthesis{tiwari2026peft_dfer,
|
| 135 |
author = {Ayush Tiwari},
|
| 136 |
+
title = {Parameter-Efficient Adaptation of Facial Expression Recognition Models for Driver Monitoring},
|
| 137 |
school = {Brandenburgische Technische Universit{\"a}t Cottbus-Senftenberg},
|
| 138 |
+
year = {2026}
|
| 139 |
}
|
| 140 |
```
|