ahmed-3m commited on
Commit
6d84596
Β·
verified Β·
1 Parent(s): 7500199

docs: comprehensive README with results tables, step-by-step instructions, HF/GitHub cross-links

Browse files
Files changed (1) hide show
  1. README.md +285 -25
README.md CHANGED
@@ -1,25 +1,285 @@
1
- ---
2
- library_name: pytorch
3
- tags:
4
- - conditional-diffusion
5
- - out-of-distribution-detection
6
- - cifar10
7
- - thesis
8
- license: mit
9
- ---
10
-
11
- # CIFAR-10 Conditional Diffusion OOD Models
12
-
13
- This Hugging Face package contains the model-release side of the CIFAR-10/OOD thesis experiments. Exact final CIFAR checkpoints referenced by the thesis were not present in the local `ssh00` folder; they are therefore documented in `missing_checkpoints.md` rather than replaced by uncertain local weights.
14
-
15
- ## Reported Thesis Results
16
- - Within-CIFAR audited AUROC: 98.98%.
17
- - External OOD audited AUROC range: 90.50% to 96.97% across CIFAR-100, Places365, FashionMNIST, SVHN, and Textures.
18
- - Separation loss effect: lambda 0.02 reaches 99.03% +/- 0.07% AUROC, versus 80.25% for lambda 0.
19
-
20
- ## Contents
21
- - `raw_scores/`: auditable score tensors available locally.
22
- - `results_json/`: ablation/evaluation JSON artifacts.
23
- - `tables/` and `figures/`: thesis table and figure artifacts.
24
- - `dataset_sources.md`: dataset provenance and expected sources.
25
- - `missing_checkpoints.md`: exact absent checkpoint provenance from thesis documentation.
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ library_name: pytorch
3
+ tags:
4
+ - conditional-diffusion
5
+ - out-of-distribution-detection
6
+ - cifar10
7
+ - anomaly-detection
8
+ - thesis
9
+ license: mit
10
+ ---
11
+
12
+ # DiffusionOOD β€” Pretrained Models & Results
13
+
14
+ [![GitHub Code](https://img.shields.io/badge/GitHub-ahmed--3m%2FDiffusionOOD-black)](https://github.com/ahmed-3m/DiffusionOOD)
15
+ [![Companion Repo](https://img.shields.io/badge/πŸ€—%20HuggingFace-InkjetOOD%20(Industrial)-blue)](https://huggingface.co/ahmed-3m/InkjetOOD)
16
+
17
+ **Thesis:** *Conditional Diffusion Models as Generative Classifiers for Out-of-Distribution Detection in Inkjet Print Quality Control*
18
+ **Author:** Ahmed Mohammed β€” MSc AI, Johannes Kepler University Linz (2026)
19
+ **Supervisor:** Univ.-Prof. Dr. Sepp Hochreiter
20
+
21
+ ---
22
+
23
+ ## What Is This?
24
+
25
+ This HuggingFace repository stores **all trained checkpoints and raw results** for the CIFAR-10 OOD detection experiments from the above thesis.
26
+
27
+ The **code** lives on GitHub: [https://github.com/ahmed-3m/DiffusionOOD](https://github.com/ahmed-3m/DiffusionOOD)
28
+
29
+ **Method summary:** A binary Conditional Diffusion Model (CDM) trained on one CIFAR-10 class detects out-of-distribution images by comparing reconstruction errors under two conditioning signals (ID vs OOD proxy). A separation loss pushes the two class embeddings apart during training.
30
+
31
+ OOD score = `E_t[ ||Ξ΅ βˆ’ Ξ΅_ΞΈ(x_t, t, c=ID)||Β² ] βˆ’ E_t[ ||Ξ΅ βˆ’ Ξ΅_ΞΈ(x_t, t, c=OOD)||Β² ]`
32
+
33
+ Higher score β†’ more likely OOD. This is **Algorithm 1** from the thesis.
34
+
35
+ ---
36
+
37
+ ## Quick Start
38
+
39
+ ### Option A β€” Evaluate with pretrained weights (~10 min)
40
+
41
+ ```bash
42
+ # 1. Clone the code repo
43
+ git clone https://github.com/ahmed-3m/DiffusionOOD
44
+ cd DiffusionOOD
45
+ pip install -r requirements.txt
46
+
47
+ # 2. Download pretrained checkpoints from this HF repo
48
+ python download_weights.py
49
+
50
+ # 3. Evaluate (CIFAR-10 auto-downloaded to ./data)
51
+ python scripts/evaluate.py \
52
+ --checkpoint_path models/seed42_best.ckpt \
53
+ --num_trials 10 \
54
+ --data_dir ./data
55
+ ```
56
+
57
+ Expected: AUROC β‰ˆ 0.989, FPR@95 β‰ˆ 0.047.
58
+
59
+ ---
60
+
61
+ ### Option B β€” Train from scratch (single seed)
62
+
63
+ ```bash
64
+ CUDA_VISIBLE_DEVICES=0 python scripts/train.py \
65
+ --seed 42 \
66
+ --separation_loss_weight 0.02 \
67
+ --batch_size 64 \
68
+ --max_epochs 200 \
69
+ --eval_interval 10 \
70
+ --scoring_method difference \
71
+ --timestep_mode uniform \
72
+ --experiment_tag thesis_seed42 \
73
+ --wandb_mode disabled \
74
+ --output_dir outputs/seed42
75
+ ```
76
+
77
+ Expected: AUROC β‰ˆ 0.987 at best validation checkpoint.
78
+
79
+ ---
80
+
81
+ ### Option C β€” Reproduce the 3-seed study
82
+
83
+ ```bash
84
+ bash scripts/run_three_seeds.sh
85
+ ```
86
+
87
+ Expected: mean AUROC 0.9833 (seeds 42/123/456), individual: 0.9898 / 0.9914 / 0.9686.
88
+
89
+ ---
90
+
91
+ ## Step-by-Step: Load a Pretrained Checkpoint
92
+
93
+ **Step 1 β€” Download**
94
+
95
+ ```python
96
+ from huggingface_hub import hf_hub_download
97
+ import torch
98
+
99
+ # Download the thesis headline model (seed=42, val AUROC 0.9873)
100
+ path = hf_hub_download(
101
+ repo_id="ahmed-3m/DiffusionOOD",
102
+ filename="models/main_training/seed42_best_auroc0.9873.ckpt"
103
+ )
104
+ ckpt = torch.load(path, map_location="cpu", weights_only=False)
105
+ print(list(ckpt.keys())) # ['state_dict', 'hyper_parameters', ...]
106
+ ```
107
+
108
+ **Step 2 β€” Load the model**
109
+
110
+ ```python
111
+ from src.model import DiffusionOODModel
112
+
113
+ device = "cuda"
114
+ model = DiffusionOODModel.load_from_checkpoint(path, map_location=device)
115
+ model.eval()
116
+ print("Model loaded.")
117
+ ```
118
+
119
+ **Step 3 β€” Run inference**
120
+
121
+ ```python
122
+ import torch
123
+ from src.scoring import compute_ood_score
124
+
125
+ # x: (B, 3, 32, 32) float tensor in [-1, 1]
126
+ x = torch.randn(1, 3, 32, 32).to(device)
127
+ score = compute_ood_score(model, x, num_trials=10, device=device)
128
+ # score > 0 β†’ likely OOD; score < 0 β†’ likely ID
129
+ print(f"OOD score: {score.item():.4f}")
130
+ ```
131
+
132
+ For full evaluation details, see [`scripts/evaluate.py`](https://github.com/ahmed-3m/DiffusionOOD/blob/main/scripts/evaluate.py).
133
+
134
+ ---
135
+
136
+ ## Models
137
+
138
+ | File | Description | Val AUROC | Test AUROC | Params |
139
+ |---|---|---|---|---|
140
+ | `models/main_training/seed42_best_auroc0.9873.ckpt` | **3-seed study, seed=42 (thesis headline)** | 0.9873 | **0.9898** | 68.79 M |
141
+ | `models/main_training/seed123_best_auroc0.9886.ckpt` | 3-seed study, seed=123 | 0.9886 | **0.9914** | 68.79 M |
142
+ | `models/main_training/seed456_best_auroc0.9887.ckpt` | 3-seed study, seed=456 | 0.9887 | **0.9686** | 68.79 M |
143
+ | `models/separation_loss_ablation/sep_loss_lambda_0p0_epoch79_auroc0.8025.ckpt` | Baseline Ξ»=0 | 0.8025 | β€” | 68.79 M |
144
+ | `models/separation_loss_ablation/sep_loss_lambda_0p02_epoch29_auroc0.9911.ckpt` | Ablation best Ξ»=0.02 | **0.9911** | β€” | 68.79 M |
145
+ | `models/separation_loss_ablation/sep_loss_lambda_0p1_epoch149_auroc0.9667.ckpt` | Ablation Ξ»=0.1 | 0.9667 | β€” | 68.79 M |
146
+
147
+ ### Raw Score Tensors
148
+
149
+ | File | Contents |
150
+ |---|---|
151
+ | `models/raw_scores/seed42_cifar10_id_scores.pt` | 1000 ID scores (seed=42, test split) |
152
+ | `models/raw_scores/seed42_cifar10_ood_scores.pt` | 9000 OOD scores (seed=42, test split) |
153
+
154
+ Load with `torch.load("seed42_cifar10_id_scores.pt")` β†’ float tensor of shape `(1000,)`.
155
+
156
+ > **Which checkpoint for evaluation?** Use `seed42_best_auroc0.9873.ckpt` β€” it gives the thesis headline result of **98.98% test AUROC**. Use the raw scores to recompute AUROC instantly without running inference.
157
+
158
+ ---
159
+
160
+ ## Results
161
+
162
+ ### Main Results (3-Seed Evaluation)
163
+
164
+ | Seed | Val AUROC | Test AUROC | FPR@95 |
165
+ |---|---|---|---|
166
+ | seed=42 | 0.9873 | **0.9898** | 0.047 |
167
+ | seed=123 | 0.9886 | **0.9914** | 0.046 |
168
+ | seed=456 | 0.9887 | **0.9686** | 0.122 |
169
+ | **Mean** | 0.9882 | **0.9833** | 0.072 |
170
+
171
+ > Thesis headline result: **98.98% AUROC** (seed=42). Verified from stored score tensors.
172
+
173
+ ### Separation Loss Ablation (seed=42)
174
+
175
+ | Ξ» | Best Val AUROC | Epoch | Gain vs Ξ»=0 |
176
+ |---|---|---|---|
177
+ | 0.0 (baseline) | 0.8025 | 79 | β€” |
178
+ | 0.001 | 0.9732 | 19 | +17.1 pp |
179
+ | 0.01 | 0.9869 | β€” | +18.4 pp |
180
+ | **0.02** | **0.9911** | **29** | **+18.9 pp** |
181
+ | 0.05 | 0.9851 | 19 | +18.3 pp |
182
+ | 0.1 | 0.9667 | 149 | +16.4 pp |
183
+
184
+ > Thesis reports: **+18.8 pp** separation loss gain βœ…
185
+
186
+ ### K Ablation (Monte Carlo Trials, seed=42)
187
+
188
+ | K | AUROC | Time/sample |
189
+ |---|---|---|
190
+ | 1 | 0.9100 | 0.010 s |
191
+ | 5 | 0.9724 | 0.049 s |
192
+ | **10** | **0.9819** | **0.097 s** |
193
+ | 25 | 0.9852 | 0.243 s |
194
+ | 50 | 0.9864 | 0.486 s |
195
+ | 100 | 0.9869 | 0.972 s |
196
+
197
+ > K=10 is the thesis default β€” best accuracy-efficiency trade-off.
198
+
199
+ ### External OOD Generalization (seed=42)
200
+
201
+ | Dataset | AUROC |
202
+ |---|---|
203
+ | CIFAR-10 (within-split) | **0.9898** |
204
+ | Food101 | 0.9927 |
205
+ | CIFAR-100 | 0.9697 |
206
+ | STL-10 | 0.9521 |
207
+ | FashionMNIST | 0.9403 |
208
+ | Textures | 0.9284 |
209
+ | SVHN | 0.9050 |
210
+
211
+ ---
212
+
213
+ ## Architecture
214
+
215
+ ```
216
+ CIFAR-10 image (32Γ—32Γ—3) + noisy version x_t
217
+ β”‚
218
+ β”Œβ”€β”€β”€β”€β”€β”€β”€β–Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
219
+ β”‚ UNet2DModel (HuggingFace Diffusers) β”‚
220
+ β”‚ block_out_channels: (128, 256, 256, 256) β”‚
221
+ β”‚ Attention: at 16Γ—16 resolution β”‚
222
+ β”‚ Class conditioning: 2 embeddings β”‚
223
+ β”‚ (c=0: ID class, c=1: OOD proxy) β”‚
224
+ β””β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
225
+ β”‚ predicted noise Ξ΅Μ‚
226
+ β”Œβ”€β”€β”€β”€β”€β”€β”€β–Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
227
+ β”‚ Algorithm 1 Scoring (K=10 trials) β”‚
228
+ β”‚ score = mean_t[e(x,t,c=0) βˆ’ e(x,t,c=1)] β”‚
229
+ β”‚ e(x,t,c) = ||Ξ΅ βˆ’ Ξ΅Μ‚(x_t,t,c)||Β² β”‚
230
+ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
231
+ ```
232
+
233
+ - **Parameters:** 68.79 M
234
+ - **Diffusion schedule:** Cosine cap (`squaredcos_cap_v2`), T=1000
235
+ - **Training:** 200 epochs, AdamW (lr=1e-4), batch=64, AMP 16-bit
236
+ - **Separation loss:** pushes ID/OOD class embeddings apart; Ξ»=0.02 is optimal
237
+
238
+ ---
239
+
240
+ ## Repository Contents
241
+
242
+ ```
243
+ ahmed-3m/DiffusionOOD (HuggingFace)
244
+ β”œβ”€β”€ models/
245
+ β”‚ β”œβ”€β”€ main_training/
246
+ β”‚ β”‚ β”œβ”€β”€ seed42_best_auroc0.9873.ckpt ← thesis headline model
247
+ β”‚ β”‚ β”œβ”€β”€ seed123_best_auroc0.9886.ckpt
248
+ β”‚ β”‚ └── seed456_best_auroc0.9887.ckpt
249
+ β”‚ β”œβ”€β”€ separation_loss_ablation/
250
+ β”‚ β”‚ β”œβ”€β”€ sep_loss_lambda_0p0_epoch79_auroc0.8025.ckpt
251
+ β”‚ β”‚ β”œβ”€β”€ sep_loss_lambda_0p02_epoch29_auroc0.9911.ckpt
252
+ β”‚ β”‚ └── sep_loss_lambda_0p1_epoch149_auroc0.9667.ckpt
253
+ β”‚ └── raw_scores/
254
+ β”‚ β”œβ”€β”€ seed42_cifar10_id_scores.pt ← 1000 ID scores
255
+ β”‚ └── seed42_cifar10_ood_scores.pt ← 9000 OOD scores
256
+ ```
257
+
258
+ ---
259
+
260
+ ## Citation
261
+
262
+ ```bibtex
263
+ @mastersthesis{mohammed2026diffusionood,
264
+ title = {Conditional Diffusion Models as Generative Classifiers for
265
+ Out-of-Distribution Detection in Inkjet Print Quality Control},
266
+ author = {Mohammed, Ahmed},
267
+ school = {Johannes Kepler University Linz},
268
+ year = {2026},
269
+ type = {Master's Thesis}
270
+ }
271
+ ```
272
+
273
+ ---
274
+
275
+ ## Companion Repository
276
+
277
+ The **InkjetOOD** companion applies the same CDM approach to industrial inkjet print quality control:
278
+ - GitHub: [https://github.com/ahmed-3m/InkjetOOD](https://github.com/ahmed-3m/InkjetOOD)
279
+ - HuggingFace: [https://huggingface.co/ahmed-3m/InkjetOOD](https://huggingface.co/ahmed-3m/InkjetOOD)
280
+
281
+ ---
282
+
283
+ ## License
284
+
285
+ MIT License β€” see the [GitHub repo](https://github.com/ahmed-3m/DiffusionOOD) for the LICENSE file.