# 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 ` unaffected. **Revert:** ```bash # train.py: change --teacher default back to "mdgt" # or pass --teacher mdgt --mdgt-checkpoint 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 :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.