ResNet-18 compressed with Tucker-2 — oral epithelial dysplasia grading
ResNet-18 for oral epithelial dysplasia grading (OralEpitheliumDB) with its 3×3 convolutions replaced by Tucker-2 factorizations on the channel modes: each convolution becomes three convolutions executed in sequence (1×1 reduce → 3×3 core → 1×1 expand), so the reduction in parameters is also a real reduction in FLOPs.
Files
| File | τ | Content |
|---|---|---|
model.safetensors |
0.9 | Threshold set in the pipeline for its final dense vs. Tucker-2 vs. Tensor-Train comparison. |
model_e0.4.safetensors |
0.4 | High-compression point, chosen after inspecting the sweep on the test set (see limitations). |
oed_models.py |
Model definition, loading and preprocessing. |
Compression
Every 3×3 convolution with more than 64 input channels (11 layers, layer2.0.conv2 to layer4.1.conv2) is decomposed,
starting from the fold-1 checkpoint of the baseline (LuisPaim/oed-resnet18).
Ranks are chosen per layer by an energy threshold τ: the smallest rank whose singular values keep a fraction τ of the energy
(Σσ²) of the corresponding unfolding. After decomposition the network is fine-tuned for up to 15 epochs (AdamW, lr 1e-4,
cosine schedule, class-weighted cross-entropy, early stopping on validation AUC), using a validation split carved from the
training portion; the test set is not used in fine-tuning.
Results (hold-out test set, n = 92)
| Model | Params | GFLOPs | AUC | ΔAUC vs. baseline [95% CI] | F1 (macro) | QWK | Acc. | Danger rate | GPU latency (ms) | CPU latency (ms) |
|---|---|---|---|---|---|---|---|---|---|---|
| ResNet-18 baseline (fold 1) | 11.18 M | 3.63 | 0.9586 | — | 0.7956 | 0.8591 | 0.7935 | 0.043 | 2.72 | 26.8 |
| Tucker-2, τ = 0.9 | 6.29 M | 2.64 | 0.9420 | -0.0167 [-0.0460, +0.0082] | 0.7842 | 0.8852 | 0.7935 | 0.033 | 3.37 | 25.8 |
| Tucker-2, τ = 0.4 (post hoc) | 0.89 M | 1.43 | 0.9564 | -0.0024 [-0.0255, +0.0223] | 0.8111 | 0.8445 | 0.8152 | 0.054 | 3.36 | 14.7 |
All metrics were re-computed on CPU from the published files, on the 92-image hold-out set; they match the original GPU run to within 0.0002 AUC. ΔAUC and its 95% CI (1,000 paired bootstrap resamples) come from the original run. GPU latency: RTX 3050 Laptop, batch 1, AMP, median of 50 runs after warm-up. CPU latency: 2-core Intel Xeon @ 2.1 GHz, batch 1, fp32, median of 50 runs. For reference, the 5-fold ensemble of the baseline reaches AUC 0.9789, F1 0.8771, QWK 0.9153 and accuracy 0.8804 on the same test set.
Reading the table
- τ = 0.4 removes 92% of the parameters and cuts FLOPs by 2.54×; the AUC change is not distinguishable from zero.
- Fewer FLOPs do not mean lower latency everywhere: on CPU τ = 0.4 is 1.8× faster, but on the GPU at batch 1 both Tucker models are slower than the dense baseline (three small kernels instead of one).
Usage
# pip install torch torchvision safetensors huggingface_hub
from huggingface_hub import hf_hub_download
import importlib.util, sys
from PIL import Image
path = hf_hub_download("LuisPaim/oed-resnet18-tucker2", "oed_models.py")
spec = importlib.util.spec_from_file_location("oed_models", path)
oed = importlib.util.module_from_spec(spec); sys.modules["oed_models"] = oed; spec.loader.exec_module(oed)
model = oed.from_pretrained("LuisPaim/oed-resnet18-tucker2")
print(oed.predict(model, Image.open("roi.tif"))) # {'healthy': ..., 'mild': ..., 'moderate': ..., 'severe': ...}
The compressed architecture is rebuilt from the tensor shapes stored in the file, so neither the original decomposition
code nor tensorly is needed.
High-compression variant: oed.from_pretrained("LuisPaim/oed-resnet18-tucker2", "model_e0.4.safetensors").
Intended use and limitations
- Research and education only. Not a medical device and not validated for diagnosis. The models were trained on mouse tissue and have not been tested on human biopsies, other staining protocols or other scanners.
- Small test set (92 images): confidence intervals are wide, and differences of a few hundredths of AUC are within noise.
- Single starting point (one seed, fold 1): the compression results describe one checkpoint, not an average over seeds.
- τ = 0.4 was selected after the threshold sweep was evaluated on the same test set, so its metrics are optimistic. τ = 0.9 is the threshold the pipeline uses for its final comparison, not the best point of the sweep.
Citation
If you use these models, please cite the dataset (OralEpitheliumDB, Journal of Imaging Informatics in Medicine, 2024, doi:10.1007/s10278-024-01041-w) and this repository.
Author: Luis Felipe Garcia de Souza Paim — Faculdade de Computação, Universidade Federal de Uberlândia (UFU). Supervision: Prof. Marcelo Zanchetta do Nascimento.
Related
- Baseline:
LuisPaim/oed-resnet18 - Tucker-2:
LuisPaim/oed-resnet18-tucker2 - Tensor-Train:
LuisPaim/oed-resnet18-tensortrain - Demo:
LuisPaim/oed-compression-demo
Model tree for LuisPaim/oed-resnet18-tucker2
Base model
LuisPaim/oed-resnet18