File size: 14,467 Bytes
cfc7a54
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
# SIFQ — Plan & Experiment Tracker

Dùng file này để: ghi kế hoạch trước khi thay đổi code, track tiến độ, và revert khi cần.

---

## Active Experiments

### v32 — Done ❌
**Goal:** Fix two concept grounding failures in v31 via T42 concept map
**Key changes from v31:** T42 concept map (2 changes):
- `dry_skin: [4, 2, 0] → [4, 0]` — remove continuity
- `noise: [3] → [1, 3]` — add clarity as co-target
**Script:** `scripts/run_train_v32.sh`
**Result:** KS=0.1375, Pearson=0.7892 — Track 2 regression vs v31 (KS +0.022, Pearson -0.097)
**Track 4 regressions vs v31:**
- blur→clarity: +0.046 ✗ (was -0.305 ✓)
- noise→clarity: +0.114 ✗ (was -0.236 ✓)
- noise→noise_level: +0.121 ✗ (was -0.081 ✓)
- occlusion→minutiae: +0.121 ✗ (was -0.123 ✓)
- wet_press→minutiae: +0.676 ✗ (was -0.695 ✓)
**Root cause:** Adding clarity[1] to noise map caused clarity concept to absorb noise-degradation gradient, destroying its response to blur. Removing continuity[2] from dry_skin destabilised concept interactions across other degradation types.
**Reverted:** concept map → T39 (restored `noise:[3]`, `dry_skin:[4,2,0]`)
**Status:** Failed — reverted to T39 concept map

---

### v31 — Done ✅
**Goal:** Benchmark DINOv2-ViTS/14 as public teacher replacing unpublished MDGT
**Key change from v28:** `--teacher dinov2` (frozen DINOv2-ViTS/14 CLS token [B,384])
**Script:** `scripts/run_train_v31.sh`
**Result:** KS=0.1152, Pearson=0.8858, q_std≥15 ✅ — **best Track 2 so far**
**Concept issues:** dry_skin→noise_level Spearman -0.758 (spurious, noise_level NOT in target);
blur→continuity +0.214 (wrong direction); noise→noise_level -0.081 (weak signal)
**Status:** Complete

---

### v29 — Done ❌
**Goal:** Fix concept grounding failures in v28 — T41 concept map + anti-saturation losses
**Key changes from v28:**
- T41 concept map: jpeg→[1], dry_skin→[4,0], noise→[1,3] (fix gradient conflicts + noise inversion)
- `--ortho-weight 3.0` (vs 1.0 default) — push saturated concepts apart
- `--concept-spread-weight 1.0` — penalise concepts with batch std < 0.20
**Script:** `scripts/run_train_v29.sh`
**Result:** KS=0.2985, Pearson=0.1448 — catastrophic sensor invariance regression
**Root cause of failure:** `--concept-spread-weight 1.0` forces per-batch concept diversity
which amplifies sensor-specific texture features, destroying cross-sensor score alignment.
G_roll_png and H_roll_png particularly affected (KS 0.86 and 0.77 vs other sensors).
**Status:** Failed — reverted to v28 code base (train_sifq.py, degradation_ranking.py T39)

---

### v28 — Done ✅
**Goal:** Validate matcher-free quality learning — L_mat disabled entirely (`--no-mat`)
**Key change from v26:** No MDGT teacher. Loss = L_sens + L_deg + L_ortho + L_spread only.
**Script:** `scripts/run_train_v28.sh`
**Result:** KS=0.1346, Pearson=0.7645, q_std~23.2 (60 epochs)
**Concept issues found:** continuity collapsed (mean=0.068), noise_level inverted (+0.56), orient_coh saturated (0.94), contrast_uni saturated (0.85), clarity flat (std=0.043). Only minutiae_rel discriminating.
**Paper claim:** ✅ "SIFQ quality is self-supervised — no external matcher needed" validated by KS close to v24
**Status:** Complete → concept grounding needs fix (next experiment TBD)

---

### v26 — Đang train 🚀
**Goal:** Verify v25 regression root cause = gamma=1.5 (not T40 concept map)  
**Key change from v25:** `--concept-deg-gamma 2.0` (restored), DEGRADATION_CONCEPT_MAP reverted to T39  
**Script:** `scripts/run_train_v26.sh`  
**Log:** `logs/train_v26.log`  
**Expected:** KS ≈ 0.126, Pearson ≈ 0.80 (match v24)  
**Eval:** `scripts/run_eval_v26.sh` (auto-runs after training)  
**Status:** Training in progress

### v27 — Pending ⏳
**Goal:** Validate SpatialConceptHead (14×14 spatial tokens) improves concept grounding  
**Key change from v26:** `--spatial-concept-head` flag — `SpatialConceptHead` replaces `ConceptHead`  
**Script:** `scripts/run_train_v27.sh`  
**Expected:** KS ≈ v26, Track 4 diagonal stronger (especially orientation_coherence, continuity, minutiae_reliability)  
**Blocker:** Wait for v26 to confirm KS/Pearson target first  
**Status:** Code ready, not launched

---

## Code Change Log

### 2026-06-04 — T42 concept map: 2 changes for v32

**Files changed:**
- `src/losses/degradation_ranking.py` — T42 DEGRADATION_CONCEPT_MAP:
  - `dry_skin: [4,2,0] → [4,0]` (removed continuity [2])
  - `noise: [3] → [1,3]` (added clarity [1] as co-target)

**Root cause (dry_skin):** v31 shows noise_level (c=3) Spearman -0.758 with dry_skin (NOT in target).
Continuity [2] shares backbone patch-scale features (~16×16) with noise texture → cross-activation.
Fix: use contrast[4] + orientation[0] (regional features at multi-patch scale) only.

**Root cause (noise):** v31 shows noise→noise_level Spearman only -0.081 (nearly no signal).
TinyViT 16×16 patch embed averages out pixel Gaussian noise (σ=5–30) → concept[3] gradient ≈ 0.
Adding clarity[1] anchors noise degradation to ridge-valley blur (detectable at patch scale).

**Backward compatibility:** ⚠️ Modifies shared DEGRADATION_CONCEPT_MAP.

**Revert T42 → T39:**
```python
"noise":     [3],
"dry_skin":  [4, 2, 0],
```

---

### 2026-06-03 — DINOv2Teacher: replace MDGT with public DINOv2-ViTS/14

**Files changed:**
- `src/training/mdgt_teacher.py` — Added `DINOv2Teacher` class: frozen DINOv2-ViTS/14 (via `torch.hub`), handles grayscale→RGB channel repeat + ImageNet normalization internally, returns L2-normalized [B, 384] CLS embeddings. `MDGTCheckpointTeacher` unchanged.
- `src/train.py` — Added `--teacher {dinov2,mdgt}` arg (default=`dinov2`). Import `DINOv2Teacher`. Instantiation in `main()` dispatches on `args.teacher`. `--mdgt-checkpoint` arg remains but only used when `--teacher=mdgt`.

**Root cause / motivation:** MDGT is unpublished work → not reproducible by reviewers → academic integrity risk. DINOv2-ViTS/14 is public (Meta, ICLR 2024), cite-able, and `torch.hub` reproducible.

**Expected Pearson impact:** DINOv2 raw → expect Pearson ~0.55–0.70 vs 0.80 with MDGT. Run v31 to benchmark.

**Backward compatibility:** ✅ All existing scripts using `--teacher mdgt --mdgt-checkpoint <path>` unaffected.

**Revert:**
```bash
# train.py: change --teacher default back to "mdgt"
# or pass --teacher mdgt --mdgt-checkpoint <ckpt_path> explicitly
```

---

### 2026-06-02 — T41 concept map + anti-saturation losses (v29)

**Files changed:**
- `src/losses/degradation_ranking.py` — T41 DEGRADATION_CONCEPT_MAP:
  - `jpeg: [2,1] → [1]` (remove continuity — JPEG artifacts wrong gradient direction in v28)
  - `dry_skin: [4,2,0] → [4,0]` (remove continuity — gradient conflict, Spearman+0.10 wrong)
  - `noise: [3] → [1,3]` (add clarity co-target — noise blurs ridges, anchors concept 3)
- `scripts/train_sifq.py` — Added `--ortho-weight` (default 1.0) and `--concept-spread-weight` (default 0.0) args; l_orth now weighted; per-concept spread loss (std < 0.20 → penalty) added to total loss; logged as `l_cspread` in running dict and epoch print

**Root cause:** v28 concept collapse/inversion diagnosed via inference stats:
  - continuity std=0.076, mean=0.068 → dead concept (3 conflicting grad sources: blur✓, jpeg✗, dry_skin✗)
  - noise_level Spearman +0.56 → inverted (Gaussian noise increases texture energy in TinyViT)
  - orient_coh mean=0.942, contrast_uni mean=0.851 → L_ortho=1.0 too weak to break saturation

**Backward compatibility:** ✅ `--ortho-weight` default=1.0, `--concept-spread-weight` default=0.0 → all v16-v28 unaffected.

**Revert T41 → T39:**
```python
# degradation_ranking.py DEGRADATION_CONCEPT_MAP:
"noise":     [3],
"jpeg":      [2, 1],
"dry_skin":  [4, 2, 0],
```

---

### 2026-06-02 — --no-mat flag (v28 teacher-free experiment)

**Files changed:**
- `scripts/train_sifq.py` — Added `--no-mat` flag; MDGT teacher/emb_cache/prototypes wrapped in `if not args.no_mat`; training loop forces `l_mat = 0.0` when flag is set

**Backward compatibility:** ✅ Default `--no-mat=False` — all existing versions unaffected.

**Revert:** Remove `--no-mat` block in `parse_args()` and restore unconditional MDGT instantiation in `main()`.

---

### 2026-06-01 — SpatialConceptHead

**Files changed:**
- `src/models/concept_head.py` — Added `SpatialConceptHead` class
- `src/models/sifq.py``SIFQ.forward()` dispatches via `concept_head.uses_spatial`
- `src/models/__init__.py` — Export `SpatialConceptHead`
- `scripts/train_sifq.py``--spatial-concept-head` flag (default=False)
- `src/train.py` — same flag
- `scripts/run_eval.py` — auto-detect from `ckpt["config"]["spatial_concept_head"]`
- `scripts/run_infer.py` — same auto-detect
- `rules/SIFQ_explained.md` — Section 2.2 updated, diagram updated, File Map updated


**Backward compatibility:** ✅ All v16–v26 checkpoints load cleanly without flag.

---

### 2026-06-01 — T39 concept map revert + gamma restore (v26)

**Problem:** v25 used gamma=1.5 AND T40 concept map. Regression KS 0.126→0.213.  
**Root cause identified:** gamma=1.5 too weak during S1→S2 ramp.  
  - v24 (gamma=2.0): spread stable ~0.003, q_std grows 18→22 monotonically
  - v25 (gamma=1.5): spread spikes to 0.028, q_std collapses 22→10 (epochs 13–16)

**Files changed:**
- `src/losses/degradation_ranking.py` — T40 reverted to T39 DEGRADATION_CONCEPT_MAP
- `scripts/run_train_v26.sh``--concept-deg-gamma 2.0`

**DEGRADATION_CONCEPT_MAP T39 (current, correct):**
```python
"blur":      [1, 2]
"noise":     [3]
"jpeg":      [2, 1]
"occlusion": [5]
"dry_skin":  [4, 2, 0]
"wet_press": [1, 5, 0]
```

**Revert target:** T40 map (v25):
```python
"blur":      [1, 2, 0]    # + orient_coh
"noise":     [3, 4]       # + contrast_u
"jpeg":      [2, 1, 4]    # + contrast_u
"occlusion": [5]
"dry_skin":  [4, 2, 0]
"wet_press": [1, 5, 0]
```
**Do NOT revert to T40** unless v26 confirms gamma=2.0 alone is insufficient and T39 concept grounding is weaker than expected.

---

## Revert Cookbook

### Revert concept map to previous version
```bash
# Check what the map looked like in a specific git commit:
git log --oneline src/losses/degradation_ranking.py
git show <commit>:sifq/src/losses/degradation_ranking.py | grep -A 30 "DEGRADATION_CONCEPT_MAP"

# Edit directly:
# src/losses/degradation_ranking.py — DEGRADATION_CONCEPT_MAP dict
```

### Revert to v24 hyperparameters (known good baseline)
```bash
# Key v24 flags (from scripts/run_train_v24.sh):
--concept-deg-gamma 2.0
--spread-weight 3.0
--spread-mode uniform
--deg-every-n-steps 2
--no-mat-stats
--proto-max-batches 0
--k-cross 0
--batch-size 96
```

### Load and inspect a checkpoint
```python
import torch
ckpt = torch.load("checkpoints/v24/last.pt", map_location="cpu", weights_only=False)
print(ckpt["metrics"])     # KS, Pearson, q_std, etc.
print(ckpt["config"])      # all argparse flags used
print(ckpt["epoch"])       # which epoch
```

### Compare two checkpoints' configs
```python
import torch, json
c24 = torch.load("checkpoints/v24/last.pt", map_location="cpu", weights_only=False)["config"]
c25 = torch.load("checkpoints/v25/last.pt", map_location="cpu", weights_only=False)["config"]
for k in c24:
    if c24.get(k) != c25.get(k):
        print(f"{k}: v24={c24.get(k)}  v25={c25.get(k)}")
```

### Run eval manually on any checkpoint
```bash
cd /home/aiserver/works/fingerprint

# Step 1: Inference
python sifq/scripts/run_infer.py \
    --checkpoint sifq/checkpoints/vXX/last.pt \
    --root-302a  dataset/302a/images/challengers \
    --root-302b  dataset/302b/images/baseline \
    --root-302d  dataset/nist_302d/images/auxiliary \
    --exclude-sensor "R_1000_slap,R_500_slap,S_500_slap" \
    --output sifq/eval_results/sifq_scores_vXX.jsonl

# Step 2: Track 2 + Track 4
python sifq/scripts/run_eval.py \
    --sifq-scores sifq/eval_results/sifq_scores_vXX.jsonl \
    --checkpoint  sifq/checkpoints/vXX/last.pt \
    --out-dir     sifq/eval_results/vXX \
    --exclude-sensor "R_1000_slap,R_500_slap,S_500_slap" \
    --skip-track1
```

### Smoke test (~2 min)
```bash
cd /home/aiserver/works/fingerprint
bash sifq/scripts/run_smoke.sh
```

---

## Decision Log

### Why not T40 concept map?
T40 added `orient_coh` to blur/noise/jpeg. Reverted in v26 because root cause of v25 regression was **gamma=1.5**, not concept map. T40 change had no confirmed benefit. Defer until v26 evaluation is done.

### Why FVC-only L_deg (not SD302)?
SD302 images are all high quality by protocol → clean images satisfy L_rank at a single ~53 attractor → blocks quality discrimination signal from L_mat. FVC has genuine quality variation (8 impressions/subject) → MDGT cosine varies → L_mat gradient meaningful → transfers to SD302 at inference. (v20 root cause analysis)

### Why --no-mat-stats?
Per-identity cosine stats (T31) created asymmetry: FVC has stable tanh targets, SD302 gets raw cosine ~0.85 constant. Backbone learned "FVC=quality-variable, SD302=fixed" → no L_mat gradient for SD302 → GRL destroyed SD302 features. (v17 root cause)

### Why --k-cross 0?
k_cross>0 forces k guaranteed cross-sensor pairs per batch → over-constrains L_sens → backbone over-optimises sensor invariance → loses quality discrimination → Pearson collapses to ~0.09. (v21 root cause)

### Why --proto-max-batches 0?
Partial prototypes (150 batches = 45% data) → SD302 identities have 2–3 sensor prototypes instead of full 19-sensor → cosine correlates with WHICH sensors in prototype window (sensor-biased) → no quality gradient for SD302. (v19/v20 root cause)

### Why gamma must be ≥ 2.0?
During S1→S2 ramp, mat loss is introduced alongside existing deg loss. If deg loss too weak (gamma=1.5), mat loss dominates momentarily → spread spikes → model partially collapses and never fully recovers. gamma=2.0 keeps deg strong enough to maintain ordinal grounding through the ramp. (v25 root cause)

---

## Pending Research Questions

- [ ] **v26 eval:** Does restoring gamma=2.0 fully recover v24 KS/Pearson? (expected: yes)
- [ ] **v27 eval:** Does SpatialConceptHead improve Track 4 diagonal ρ vs v26?
- [ ] **noise→noise_level:** v24 Track 4 shows +0.365 (wrong direction). Defer to v28.
- [ ] **T40 revisit:** Once v26/v27 stable, evaluate if blur/noise/jpeg → orient_coh improves orientation_coherence grounding.