UFR-Fing / rules /HOWTO_RUN.md
anbinh39's picture
Add files using upload-large-folder tool
cfc7a54 verified
|
Raw
History Blame Contribute Delete
35.9 kB
# SIFQ — Hướng dẫn chạy
Tất cả lệnh chạy từ thư mục gốc: `/home/aiserver/works/fingerprint`
| Version | Status | Epochs | Highlights |
|---------|--------|--------|------------|
| v11 | ✅ Done | 80 | PolyU back in L_sens |
| v12 | ✅ Done | 80 | T17–T19 concept fixes |
| v13 | ✅ Done | 80 | Revert T17, per-dataset L_spread, occlusion fix |
| v14 | ✅ Done | 60 | Exclude non-segmented slap; KS=0.263 ✅, Pearson=0.294 ✅; dry_skin ↑↑ |
| v15 | ✅ Done | 60 | T30: SD302 concept-only L_deg + gamma=2.0; KS=0.2758 (tệ), score collapse (24–56) ❌ |
| v16 | ✅ Done | 60 | T31: per-identity cos stats + tanh; score collapse 46.9–50.5 ❌ (worse!); KS=0.527 ❌ |
| v17 | ✅ Done | 60 | T32: FVC-only cos stats; score collapse ALL SD302 at 52.7, q_std=0.60 ❌; KS=0.616 ❌ |
| v18 | ✅ Done ❌ | 60 | T33: revert v14 loss + SD302-A; **score collapse** q_std≈0.01, KS=0.249⚠️(false positive), Pearson=0.007❌; concept head stuck near bounds |
| v19 | ✅ Done ❌ | 60 | T34: true revert to v14 — spread-weight=3.0, deg-every-n-steps=2; score collapse ALL ~53.1x, q_std≈0.01 ❌ |
| v20 | ✅ Done ❌ | 60 | T35: full prototypes (proto-max=0) + L_deg on SD302; score collapse q_std≈0.007 ❌ — --deg-include-sd302 was wrong fix |
| v21 | ✅ Done ❌ | 60 | T36: full prototypes + FVC-only L_deg; KS=0.312, Pearson=0.092 ❌ — CrossSensorBatchSampler k_cross=16 destroyed quality discrimination |
| v22 | ✅ Done | 60 | T37: fix k_cross=0 + single GPU; KS=0.278, Pearson=0.546 |
| v24 | ✅ Done | 60 | Best: KS=0.126 ✅, Pearson=0.800 ✅, q_std~22 |
| v25 | ❌ Done | 60 | gamma=1.5 too weak; KS=0.213, Pearson=0.620 |
| v26 | ✅ Done | 60 | gamma=2.0 restored |
| v27 | ✅ Done | 60 | SpatialConceptHead |
| v28 | ✅ Done | 60 | No L_mat (--no-mat); KS=0.1346, Pearson=0.7645 |
| v29 | ❌ Done | 60 | T41 concept map + ortho-weight 3.0 + concept-spread-weight 1.0; KS=0.2985, Pearson=0.1448 |
| v31 | ✅ Done | 60 | DINOv2-ViTS/14 teacher (public); KS=0.1152, Pearson=0.8858 — best so far |
| v32 | 🚀 Next | 60 | T42: dry_skin[4,0] + noise[1,3] — fix noise_level crosstalk + weak noise signal |
---
## 1. Smoke test (kiểm tra pipeline ~2 phút)
```bash
cd /home/aiserver/works/fingerprint
bash sifq/scripts/run_smoke.sh
```
Kết quả ở `sifq/checkpoints_smoke/last.pt``metrics.jsonl`.
---
## 2. Full training v21 — Active 🚀 (60 epochs, từ đầu)
> **v21 — T36: Full prototypes + FVC-only L_deg (remove --deg-include-sd302).**
>
> **Root cause of v20 failure (new diagnosis):**
>
> v20 training showed q_std≈18.3 (healthy) but ALL SD302 inference scores collapsed to ~53.38
> (q_std≈0.007). The `--proto-max-batches 0` fix (T35a) was correct. But `--deg-include-sd302`
> (T35b) was WRONG and caused the collapse:
>
> - L_rank on SD302 says: Q(clean) > Q(low_deg) + m > Q(high_deg) + m
> - The model satisfies this with a single ~53.38 for ALL clean SD302 images + lower for degraded
> - L_rank does NOT require different clean images to score differently → attractor at ~53.38
> - L_spread_ds (batch-level) + L_pair reinforce the collapse
>
> **Why v14 worked without --deg-include-sd302:**
> FVC genuine quality variation → MDGT raw cosine genuinely varies (0.75→0.93) per impression
> → L_mat gradient shapes backbone to be quality-discriminative → transfers to SD302 at inference.
> L_rank on SD302 BLOCKS this transfer by creating the stable ~53.38 attractor.
>
> **T36 fix:** Remove `--deg-include-sd302`. Keep `--proto-max-batches 0`.
> FVC-only L_deg: genuine quality signal trains backbone → SD302 scored by intrinsic quality.
> **v20 — T35: Full prototypes + L_deg on SD302. Fix root causes of ALL v15–v19 failures.**
>
> **Root cause analysis (v19 failure = same collapse as v15–v18):**
>
> v19 was supposed to reproduce v14 exactly but STILL collapsed (all scores ~53.1x, q_std≈0.01).
> The "spread-weight/deg-every-n-steps mismatch" explanation was wrong. Two deeper root causes:
>
> **Root cause 1 — Truncated prototypes (T35a):**
> - v14's code had NO `--proto-max-batches` cap → prototypes computed on full 42,683 images
> - When this param was added (default=150 batches = ~19,200 images = 45% of data), SD302 identities
> went from full 19-sensor multi-sensor prototypes to 2–3 sensor partial prototypes
> - Full prototype: raw cosine varies with image quality across sensors (quality-discriminative)
> - Partial prototype: raw cosine correlates with WHICH sensors are in the prototype window
> → sensor-biased, NOT quality-correlated → no per-image quality gradient for SD302 → collapse
>
> **Root cause 2 — FVC-only L_deg leaves SD302 without ordinal grounding (T35b):**
> - T27 reverted T17 (L_deg on all images) because clean SD302 anchored at ~28
> - But T27 ITSELF introduced per-dataset L_spread_ds — which prevents anchoring
> - With L_spread_ds forcing SD302 to span [10,90], re-enabling full L_rank for SD302 is now safe
> - L_deg (L_rank + L_concept) on SD302 provides the only stable per-image quality signal
> for SD302 at inference (synthetic degradation response ≈ ridge quality proxy)
>
> **T35 fixes:**
> 1. **T35a — `--proto-max-batches 0`**: Full dataset prototype computation. Cost: ~10–15 min
> overhead at epoch 0 (334 batches vs 150). Restores genuine per-image L_mat quality signal.
> 2. **T35b — `--deg-include-sd302`**: Apply full L_deg (L_rank + L_concept) to SD302 images.
> L_spread_ds prevents the T17 score anchoring issue. Per-image ordinal grounding for SD302.
>
> **All other settings from v19 kept unchanged:**
> - `--no-mat-stats`, `--spread-weight 3.0`, `--deg-every-n-steps 2`
> - `--concept-deg-gamma 0.5`, `--sd302-concept-weight 0.0`
> - SD302-A included, `--batch-size 128`, `--gpus 0`
## 2. Full training v22 — 🚀 Next run (60 epochs, từ đầu)
> **v22 — T37: Fix ALL bugs from v15–v21. First correct run with full dataset.**
>
> **Three bugs caused v15–v21 to fail:**
>
> **BUG 1 — CrossSensorBatchSampler k_cross=16:**
> - k_cross=16 forces 16 guaranteed pairs/batch = 8–16× more L_sens pressure
> - With full prototypes (nearly-constant L_mat targets), backbone over-optimises sensor
> invariance and loses quality discrimination → Pearson collapses to ~0.09 (v21)
> - **Fix: `--k-cross 0` (random batching)**
>
> **BUG 2 — proto-max-batches default=150:**
> - Only 45% of dataset used for prototypes → partial sensor prototypes → sensor-biased cosine
> - **Fix: `--proto-max-batches 0` (full dataset)**
>
> **BUG 3 — DataParallel (--gpus 0,1) causes 4.3× slowdown for TinyViT-5M:**
> - **Fix: `--gpus 0` (single GPU)**
>
> **BONUS — Redundant teacher double-pass eliminated:**
> - Now `build_prototypes_from_cache()` computes prototypes from emb_cache (O(N) CPU)
> **Note on high L_sens / pair loss in v22:**
> v22 includes SD302-A (8 diverse roll sensors per finger). L_mat targets vary by sensor
> for the same finger → L_pair starts high (~12 at S2 onset) and decreases gradually.
> This is EXPECTED with a richer dataset — not a failure. q_std=21–22 (best quality
> discrimination so far). L_sens equilibrium is found by ep60.
```bash
cd /home/aiserver/works/fingerprint
version=v32
nohup bash sifq/scripts/run_train_$version.sh > sifq/logs/train_$version.log 2>&1 &
echo "PID: $!"
tail -f sifq/logs/train_$version.log
pkill -f train_sifq.py
```
**Expected results (research design goals, 171 sensor pairs):**
| Metric | v21 ❌ | v22 (ep51) | v22 goal |
|--------|--------|--------|----------|
| q_std (train) | ~17.7 | **~22** ✅ | ≥18 |
| epoch time | ~970s ❌ | **~220s** ✅ | ≤250s |
| Track 2 mean_KS | 0.312 | — (training) | **≤0.30** |
| Track 2 Pearson | +0.092 ❌ | — (training) | **≥0.20** |
| Concept grounding | dry_skin+0.83 ❌ | — (training) | **all targets negative ρ** |
**Dấu hiệu v22 đang train đúng:**
| Epoch | Dấu hiệu tốt |
|-------|-------------|
| ep 0 | Startup nhanh (~teacher 1 pass + cache); epoch ~220s |
| ep 0–10 | q_std tăng nhanh 1→10→18; l_mat ~0.18–0.20; l_deg > 0 |
| ep 12+ | l_pair cao (~12) khi S2 bắt đầu — BÌNH THƯỜNG với SD302-A 8 sensors |
| ep 20–50 | l_pair giảm dần (12→4→2); adv tăng về rand_ce; q_std ~20–22 ✅ |
| ep 40–60 | Stable: l_spread ≈0.002, q_mean ~52, q_std ~21–22 |
---
## 3. Full training v21 — Done ❌ (60 epochs)
| ep 20+ | `train_l_pair` → 0.01–0.05, q_std ổn định 12–18 |
> **Key difference from v20:** `train_q_std` in v20 was also 18.3 (false positive driven by L_spread).
> In v21, watch for **INFERENCE q_std > 5** at end — run a quick spot-check:
> `python sifq/scripts/run_infer.py --checkpoint sifq/checkpoints/v21/last.pt --max-samples 200 --output /tmp/spot.jsonl && python -c "import json,statistics; s=[json.loads(l)['q_score'] for l in open('/tmp/spot.jsonl')]; print(f'std={statistics.stdev(s):.2f} range=[{min(s):.1f},{max(s):.1f}]')"`
```bash
cd /home/aiserver/works/fingerprint
nohup bash sifq/scripts/run_train_v21.sh > sifq/logs/train_v21.log 2>&1 &
echo "PID: $!"
tail -f sifq/logs/train_v21.log
```
- Checkpoint: `sifq/checkpoints/v21/last.pt`
- Train từ đầu, LR: `1e-4` cosine → 5e-6, Batch: `128`, GPU: `0`
- **Auto-eval** sau training: kết quả ở `sifq/eval_results/v21/`
---
## 2b. Eval v21 — Chạy thủ công nếu cần
```bash
cd /home/aiserver/works/fingerprint
nohup bash sifq/scripts/run_eval_v32.sh > sifq/eval_v32.log 2>&1 &
echo "PID: $!"
```
Kết quả ở `sifq/eval_results/v21/`.
---
## 2c. Full training v20 — Completed ❌ (score collapse)
> **v20 actual results:** q_std≈0.007 (collapsed), mean_KS=0.4936 ❌, Pearson=0.0048 ❌.
> Root cause: `--deg-include-sd302` applied L_rank to all clean SD302 → stable ~53.38 attractor.
> See v21 for fix.
---
## 2d. Eval v20 — Chạy thủ công nếu cần
```bash
cd /home/aiserver/works/fingerprint
nohup bash sifq/scripts/run_eval_v20.sh > sifq/eval_v20.log 2>&1 &
echo "PID: $!"
```
Kết quả ở `sifq/eval_results/v20/`.
---
## 2c. Full training v19 — Completed ❌ (score collapse — 60 epochs)
> **v19 — T34: True revert to v14 hyperparameters (FAILED — same collapse as v18).**
> Root cause was NOT the spread/deg values (those were already correct in v19).
> Real root cause: truncated prototypes + FVC-only L_deg. See v20 analysis above.
---
## 2. Full training v18 — Completed ❌ (score collapse — 60 epochs)
> **v18 — T33: revert toward v14 + include SD302-A.**
>
> Root cause từ v17 eval:
> - T32 chỉ remove explicit L_mat vs L_pair conflict, nhưng SD302 VẪNN collapse → q_std=0.60 at inference.
> - FVC tanh targets (variable) vs SD302 raw cosine targets (constant) tạo asymmetry → model học shortcut "FVC=variable, SD302=52.7".
> - W_SPREAD=4.0 + gamma=2.0 + sd302_concept_weight=1.0 làm tệ thêm so với v14.
>
> **T33 fixes: revert tất cả additions từ v15–v17:**
> 1. **T33a — `--no-mat-stats`**: Skip per-identity cosine stats hoàn toàn. Tất cả images (FVC + SD302) đều dùng raw cosine làm L_mat target → không còn FVC/SD302 quality signal asymmetry.
> 2. **T33b — W_SPREAD = 2.0** (revert từ 4.0 — v14 level)
> 3. **T33c — concept_deg_gamma = 0.5** (revert từ 2.0 — v14 default)
> 4. **T33d — sd302_concept_weight = 0.0** (revert T30b — v14 default)
> 5. **T33e — deg-every-n-steps = 4** (revert từ 2 — v14 default)
> 6. **NEW — SD302-A included**: 13,630 images, 8 sensors (A-H) trong training (v14 chỉ dùng B+D)
```bash
cd /home/aiserver/works/fingerprint
nohup bash sifq/scripts/run_train_v18.sh > sifq/logs/train_v18.log 2>&1 &
echo "PID: $!"
tail -f sifq/logs/train_v18.log
```
- Checkpoint: `sifq/checkpoints/v18/last.pt`
- Metrics: `sifq/checkpoints/v18/metrics.jsonl`
- Train từ đầu (không resume)
- LR: `1e-4` cosine → 5e-6
- Batch: `128`
- **Auto-eval** sau training: kết quả ở `sifq/eval_results/v18/`
**Kết quả v18 thực tế (FAILED — score collapse):**
| Metric | v14 ✅ | v17 ❌ | v18 actual ❌ | Target |
|--------|--------|--------|--------------|--------|
| q_std (inference) | ~15 | 0.60 | **0.01 ❌❌** | **>12** |
| Score range | 10–90 | 18–53 | **54.62–54.65 ❌** | **10–90** |
| Track 2 mean_KS | 0.263 | 0.616 | **0.249 ⚠️** | **≤0.27** |
| Track 2 Pearson | +0.294 | -0.002 | **0.007 ❌** | **≥0.25** |
| n_sensor_pairs | 55 | 171 | **171** | **≥100** |
> **⚠️ v18 KS=0.249 là false positive**: Model không phân biệt được images — tất cả sensors cho cùng score ≈54.64. KS thấp vì các phân bố trivially giống nhau (đều là Dirac delta tại 54.64). Root cause mới: raw cosine L_mat hằng số (~0.85) không tạo per-image quality gradient → model collapse về mean. Cần T34: tìm cách tạo per-image quality signal mà không gây FVC/SD302 asymmetry.
**Dấu hiệu v18 đang train đúng:**
| Epoch | Dấu hiệu tốt |
|-------|-------------|
| ep 0–10 | `train_q_std` tăng > 15, `train_l_mat` giảm (~0.25–0.35) |
| ep 11–20 | `train_l_pair` giảm (GRL kick-in), q_std giảm tạm (~12-15) |
| ep 20+ | `train_l_pair` → 0.01–0.05, q_std ổn định 12–18 |
---
## 2a. Eval v18 — Chạy thủ công nếu cần
```bash
cd /home/aiserver/works/fingerprint
nohup bash sifq/scripts/run_eval_v18.sh > sifq/eval_v18.log 2>&1 &
echo "PID: $!"
```
Kết quả ở `sifq/eval_results/v18/`.
---
## 2. Full training v19 — Active 🚀 (60 epochs, từ đầu)
> **v19 — T34: True revert to v14 hyperparameters.**
>
> Root cause từ v18 failure:
> - v18 comments nói "revert to v14" nhưng dùng sai giá trị:
> - `--spread-weight 2.0` (v14 thực tế: **3.0** — sai 50%)
> - `--deg-every-n-steps 4` (v14 thực tế: **2** — sai 2×)
> - Hai sai số này làm L_spread + L_deg yếu hơn v14 → backbone không học được quality-discriminative features → inference collapse (q_std≈0.01).
> - Xác nhận bằng `diff run_train_v14.sh run_train_v18.sh`.
>
> **T34 fixes:**
> 1. **T34a — `--spread-weight 3.0`**: Restore v14 actual value. Gradient L_spread mạnh hơn buộc backbone phân biệt quality.
> 2. **T34b — `--deg-every-n-steps 2`**: Restore v14 actual value. 2× tần suất L_deg → ordinal grounding mạnh hơn.
>
> **Giữ nguyên từ v18:**
> - `--no-mat-stats`: cần thiết để reproduce v14 pre-T31 behavior với code hiện tại
> - `--concept-deg-gamma 0.5`, `--sd302-concept-weight 0.0` (v14 defaults)
> - SD302-A included (v18 addition, giữ lại)
> - `--batch-size 128`, `--gpus 0`
```bash
cd /home/aiserver/works/fingerprint
nohup bash sifq/scripts/run_train_v19.sh > sifq/logs/train_v19.log 2>&1 &
echo "PID: $!"
tail -f sifq/logs/train_v19.log
```
- Checkpoint: `sifq/checkpoints/v19/last.pt`
- Metrics: `sifq/checkpoints/v19/metrics.jsonl`
- Train từ đầu (không resume)
- LR: `1e-4` cosine → 5e-6
- Batch: `128`, GPU: `0`
- **Auto-eval** sau training: kết quả ở `sifq/eval_results/v19/`
**Expected results (target = v14 baseline):**
| Metric | v14 ✅ | v18 ❌ | v19 target |
|--------|--------|--------|-----------|
| q_std (inference) | ~15.5 | 0.01 | **>12** |
| Score range | 10–90 | 54.62–54.65 | **10–90** |
| Track 2 mean_KS | 0.263 | 0.249⚠️ | **≤0.27 (real)** |
| Track 2 Pearson | +0.294 | 0.007 | **≥0.25** |
**Dấu hiệu v19 đang train đúng:**
| Epoch | Dấu hiệu tốt |
|-------|-------------|
| ep 0–10 | `train_q_std` > 15, `train_l_mat` giảm (~0.25–0.35) |
| ep 11–20 | `train_l_pair` giảm (GRL kick-in), q_std giảm tạm (~12–15) |
| ep 20+ | `train_l_pair` → 0.01–0.05, q_std ổn định 12–18 |
---
## 2b. Eval v19 — Chạy thủ công nếu cần
```bash
cd /home/aiserver/works/fingerprint
nohup bash sifq/scripts/run_eval_v19.sh > sifq/eval_v19.log 2>&1 &
echo "PID: $!"
```
Kết quả ở `sifq/eval_results/v19/`.
---
## 3. Full training v17 — Completed (60 epochs) ✅ (score collapse ❌)
> **v17 thất bại**: Score collapse nghiêm trọng — tất cả SD302 images output ~52.7 (q_std=0.60 at inference). Training q_std=16.59 vẫn ổn (driven by FVC). KS=0.616 ❌.
>
> **Root cause v17 (sâu hơn T32 đã fix)**:
> - T32 fix (FVC-only stats, SD302 raw cosine fallback) đã loại bỏ L_mat vs L_pair CONFLICT nhưng không fix SCORE COLLAPSE.
> - SD302 raw cosine ≈ 0.85 là CONSTANT cho tất cả images → L_mat không phân biệt được SD302 identities với nhau → không có per-image quality signal cho SD302.
> - GRL + L_pair triệt tiêu discriminative features từ SD302 backbone: GRL xóa sensor-correlated info (bao gồm quality-correlated-with-sensor). L_pair ép same-identity same-score.
> - L_spread_ds tạo relative constraints per-batch nhưng KHÔNG CONSISTENT qua các batches → average score cho mỗi SD302 image settle về ~52.7.
> - FVC images: có stable per-image tanh targets → model học được quality function. SD302: chỉ có inconsistent batch-relative spread signals → feature collapse.
>
> **v16 root cause (T32 mục tiêu)**:
> **v17 là training hiện tại.** Root cause từ v16 eval:
> - **Score collapse nghiêm trọng**: inference q_std=0.33, range 46.9–50.5 (tệ hơn v15!). Training q_std=15.6 trông ổn nhưng driven bởi FVC images. Inference chỉ chạy SD302 → collapse.
> - **T32 — Root cause**: T31's per-identity stats conflict trực tiếp với L_pair.
> - L_mat (T31b): `q_mat = tanh((cos−μᵢ)/σᵢ)` → muốn **within-identity variation** (ảnh khác nhau của cùng ngón tay nên score khác nhau)
> - L_pair: `|Q(s1)−Q(s2)| ≤ 0.05` → muốn **within-identity uniformity** (cùng ngón tay, khác sensor, phải score bằng nhau)
> - Hai loss conflict → model giải quyết bằng output ~50 cho tất cả SD302. FVC không có L_pair → spread được → training q_std=15.6 driven by FVC only.
>
> **v17 fixes (T32): FVC-only per-identity stats**
> 1. **T32a — `compute_identity_cos_stats(fvc_only=True)`**: Chỉ tính stats cho FVC identities. FVC không có cross-sensor pairs → L_pair=0 → không conflict với L_mat.
> 2. **T32b — `_compute_q_mat` fallback to raw cosine**: SD302 identities không có trong stats → dùng raw cosine (~0.85, hằng số) giống v14. Không còn conflict với L_pair.
> 3. **Giữ nguyên**: W_SPREAD=4.0, concept_deg_gamma=2.0, sd302_concept_weight=1.0, deg-every=2.
```bash
cd /home/aiserver/works/fingerprint
nohup bash sifq/scripts/run_train_v17.sh > sifq/logs/train_v17.log 2>&1 &
echo "PID: $!"
tail -f sifq/logs/train_v17.log
```
- Checkpoint: `sifq/checkpoints/v17/last.pt`
- Metrics: `sifq/checkpoints/v17/metrics.jsonl`
- Train từ đầu (không resume)
- LR: `1e-4` cosine → 5e-6
- Batch: `128`
- **Auto-eval** sau training: kết quả ở `sifq/eval_results/v17/`
**Kết quả v17 (thực tế so với target):**
| Metric | v14 | v16 | Target v17 | Thực tế v17 |
|--------|-----|-----|------------|-------------|
| Score range (eval, SD302) | — | 46.9–50.5 ❌ | **0–100** | 18.1–53.0 (all ~52.7) ❌ |
| q_std (inference) | — | 0.33 ❌ | **>10** | **0.60** ❌ (worse collapse) |
| q_std (train, final) | ~15.5 | 15.6 | ~15–20 | 16.59 ✅ |
| Track 2 mean_KS | 0.263 ✅ | 0.527 ❌ | **≤0.27** | **0.616** ❌ |
| Track 2 Pearson | 0.294 ✅ | 0.046 ❌ | **≥0.25** | **-0.002** ❌ |
**Dấu hiệu v17 đang train đúng (watch trong log):**
| Epoch | Dấu hiệu tốt |
|-------|-------------|
| ep 0–5 | `train_l_mat` bắt đầu giảm (~0.15–0.25) — FVC quality signal hoạt động |
| ep 0–10 | `train_q_std` tăng lên > 15 (L_spread có tác dụng trên mixed batch) |
| ep 11–15 | `train_l_pair` giảm nhanh (GRL kick-in), q_std giảm tạm thời |
| ep 20+ | `train_l_pair` → 0.01–0.05, `train_q_std` ≥ 12, ổn định |
---
## 2a. Eval v17 — Chạy thủ công nếu cần
Auto-eval đã được tích hợp vào `run_train_v17.sh`. Nếu cần chạy lại riêng:
```bash
cd /home/aiserver/works/fingerprint
nohup bash sifq/scripts/run_eval_v17.sh > sifq/eval_v17.log 2>&1 &
echo "PID: $!"
```
Kết quả ở `sifq/eval_results/v17/`.
---
## 2b. Full training v16 — Completed (60 epochs) ✅ (score collapse ❌)
> **v16 thất bại**: score collapse 46.9–50.5 (tệ hơn v15!), KS=0.527. Root cause: T31 conflict với L_pair → T32 fix.
```bash
# Xem kết quả v16 eval
cat sifq/eval_results/v16/eval_summary.json
```
- Checkpoint: `sifq/checkpoints/v16/last.pt`
- Eval kết quả: `sifq/eval_results/v16/`
---
## 2c. Full training v15 — Completed (60 epochs) ✅ (score collapse ❌)
> **v15 thất bại**: score range 24–56 (score collapse), KS=0.2758 (tệ hơn v14). Root cause: T31.
```bash
# Chỉ xem logs — không cần chạy lại
cat sifq/eval_v15.log
cat sifq/checkpoints_full_v15/metrics.jsonl | tail -5
```
---
## 2c. Full training v14 — Completed (60 epochs, từ đầu) ✅
```bash
nohup bash sifq/scripts/run_eval_v15.sh > sifq/eval_v15.log 2>&1 &
echo "PID: $!"
```
Kết quả ở `sifq/eval_results/v15/`.
---
## 2c. Full training v14 — Completed (60 epochs, từ đầu) ✅
> **v14 đã train xong.** Nguyên nhân gốc từ v13 eval:
> 1. **T28 — Non-segmented slap std≈0**: `R_1000_slap`, `R_500_slap`, `S_500_slap` là ảnh 4 ngón tay → backbone cho score ~21.2 cho mọi người (std=0). Kéo mean_KS từ 0.51 (v12) lên 0.634 (v13 — tệ hơn). Loại khỏi training và eval.
> 2. **T29 — Train từ đầu (không resume)**: backbone TinyViT từ IN22k pretrained, concept head + aggregator ngẫu nhiên → cần 60 epochs để converge đầy đủ.
```bash
cd /home/aiserver/works/fingerprint
nohup bash sifq/scripts/run_train_v14.sh > sifq/train_v14.log 2>&1 &
echo "PID: $!"
tail -f sifq/train_v14.log
```
- Checkpoint: `sifq/checkpoints_full_v14/last.pt`
- Metrics: `sifq/checkpoints_full_v14/metrics.jsonl`
- Train từ đầu (không resume)
- **Sensors bị loại**: `R_1000_slap`, `R_500_slap`, `S_500_slap` (~1,700 records)
- **Dataset**: 42,683 records, 29 sensors
**Kết quả training v14 (60 epochs):**
| Metric | v13 | v14 thực tế | Trend |
|--------|-----|-------------|-------|
| `q_mean` (train) | ~33 | **52.6** | ✅ Centered tốt hơn hẳn |
| `q_std` (train) | 12.5 | **~15.5** | ✅ Spread ổn định |
| `l_pair` (ep59) | — | **0.006** | ✅ Sensor invariance xuất sắc |
| `l_mat` (ep59) | — | **0.270** | ✅ Converged tốt |
| `l_spread` (ep59) | — | **0.025** | ✅ Ổn định |
| Eval (KS/Pearson) | 0.634 / 0.224 | **0.263 / 0.294** ✅ | Target ✅ |
**3-phase training dynamics (quan sát được lần đầu ở v14 do train from scratch):**
| Phase | Epochs | q_std | l_pair | Mô tả |
|-------|--------|-------|--------|-------|
| S1 — Spread | 0–10 | 1 → 22.6 | 0.47 → 25 | GRL λ warm-up, L_spread mở rộng phân bố |
| Transition | 11–15 | 22.6 → 14 | 24 → 0.13 | β kick-in, GRL triệt tiêu sensor signature |
| Equilibrium | 16–59 | ~15.5 | → 0.006 | l_pair/l_mat converged, l_spread stable |
**Kết quả eval v14 (Track 2 + Track 4):**
| Track | Metric | v12 | v13 | v14 |
|-------|--------|-----|-----|-----|
| Track 2 | mean_KS | 0.510 | 0.634 ❌ | **0.263** ✅ |
| Track 2 | Pearson | -0.003 | +0.224 | **+0.294** ✅ |
| Track 2 | n\_sensor\_pairs | 91 | 91 | 55 (slap loại) |
| Track 4 | dry_skin → contrast | — | -0.376 | **-0.623** ✅⬆ |
| Track 4 | dry_skin → continuity | — | +0.009 | **-0.563** ✅⬆ |
| Track 4 | blur → clarity | — | -0.490 ✅ | -0.187 ⚠️ (yếu hơn) |
| Track 4 | noise → noise_level | — | -0.533 ✅ | -0.019 ⚠️ (regression) |
| Track 4 | wet_press → minutiae | — | +0.326 ❌ | +0.565 ❌ (tệ hơn) |
**Expected improvements v14 — đã đạt:**
| Track | Metric | v13 | Target v14 |
|-------|--------|-----|------------|
| Score | Sensor clusters | 3 cụm (~21, ~50, ~55) | **2 cụm hoặc phẳng** (slap đã loại) |
| Track 2 | mean_KS | 0.634 ❌ | **<0.35** ✅ |
| Track 2 | Pearson | 0.224 | **≥0.25** |
| Train | Epochs | 80 | **60** (from scratch) |
---
## 2d. Eval v14 — Chạy sau khi training xong ⭐
> **Bước tiếp theo bắt buộc** sau khi v14 training completed.
```bash
# Bước 1: Inference — sinh Q scores
python sifq/scripts/run_infer.py \
--checkpoint sifq/checkpoints_full_v14/last.pt \
--exclude-sensor "R_1000_slap,R_500_slap,S_500_slap" \
--output sifq/eval_results/sifq_scores_v14.jsonl
# Bước 2: Eval — Track 2 + Track 4
python sifq/scripts/run_eval.py \
--sifq-scores sifq/eval_results/sifq_scores_v14.jsonl \
--checkpoint sifq/checkpoints_full_v14/last.pt \
--out-dir sifq/eval_results/v14 \
--skip-track1
# Bước 3: Visual score milestones
mkdir -p sifq/eval_results/v14
python sifq/visualize_score_milestones.py \
--scores sifq/eval_results/sifq_scores_v14.jsonl \
--output sifq/eval_results/v14/milestone_samples.png \
--n_buckets 8
```
---
## 2b. Eval v13 (chính xác, exclude non-segmented slap)
```bash
bash sifq/scripts/run_eval_v13.sh
```
Kết quả ở `sifq/eval_results/v13_seg/` (exclude `R/S_*_slap`).
---
## 2c. Full training v13 — Completed (80 epochs)
> **v13 là training hiện tại.** Phân tích sau v12 eval cho thấy T17 fix (L_deg on all datasets) là sai về nguyên tắc:
> 1. **T20 — SD302 anchored tại ~28**: Synthetic degradation trên SD302 kéo clean images về gần degraded floor (~28). SD302 toàn ảnh chất lượng cao → synthetic degradation không phản ánh quality variation thực → anchoring sai.
> 2. **T21 — Non-segmented slap std=0**: Full-hand slap images visually homogeneous → model gán cùng score (behavior đúng, không cần fix).
> 3. **T22 — Noise concept regression**: `noise_level: +0.188 (v11) → -0.168 (v12)`. Old `c_idx==3` special case gây conflict với L_rank → model invert noise_level direction.
> 4. **T23 — Occlusion vẫn dead**: 40% coverage chưa đủ + continuity concept không được supervise.
>
> **v13 fixes:**
> - **T27**: Revert T17 (FVC-only L_deg) + **per-dataset L_spread** cho SD302 subset riêng (prevents SD302 collapse mà không cần synthetic degradation anchoring).
> - **T25**: Remove `c_idx==3` special case. Tất cả concepts giảm với degradation (high=better).
> - **T26**: Occlusion: add continuity (c_idx=2) to DEGRADATION_CONCEPT_MAP + coverage 40%→55%.
```bash
cd /home/aiserver/works/fingerprint
nohup bash sifq/scripts/run_train_v13.sh > sifq/train_v13.log 2>&1 &
echo "PID: $!"
tail -f sifq/train_v13.log
```
- Checkpoint: `sifq/checkpoints_full_v13/last.pt`
- Metrics: `sifq/checkpoints_full_v13/metrics.jsonl`
- Resume từ: `sifq/checkpoints_full_v12/last.pt`
**Expected improvements v13:**
| Track | Metric | v11 | v12 | Target v13 |
|-------|--------|-----|-----|----------|
| Score | q_std (inference) | 6.47 | 12.53 | **>18** (spread đều, bao gồm SD302 roll/flat) |
| Score | mean | 59.81 | 33.63 | **45–65** (SD302 anchored đúng chỗ) |
| Track 2 | mean_KS | 0.5566 | 0.5100 | **<0.20** (sensor type bias vẫn còn nhưng giảm) |
| Track 4 | wet_press → clarity | +0.219 ❌ | -0.647 ✅ | giữ ✅ |
| Track 4 | noise → noise_level | +0.188 ✅ | -0.168 ❌ | **positive ✅** (T25 fix) |
| Track 4 | occlusion → continuity | -0.029 ❌ | +0.023 ❌ | **negative ✅** (T26 fix) |
| Track 4 | occlusion → minutiae | -0.032 ❌ | +0.075 ❌ | **negative ✅** (T26 fix) |
---
## 2b. Full training v11 — Completed (80 epochs)
> v11 đã train xong. Checkpoint tại `sifq/checkpoints_full_v11/last.pt`.
> 1. **PolyU trở lại L_sens** — contact vs contactless pairs là tín hiệu L_sens mạnh nhất (2,612 anchor groups thay vì 2,276)
> 2. **PolyU bị mask khỏi L_mat** — không compute prototype / teacher loss cho PolyU
> 3. **PolyU bị mask khỏi L_deg** — không apply degradation cho PolyU images
> 4. **Schedule mới: β/α = 1.0 ngay từ S2 (ep20)** — β ramp nhanh hơn α trong ep10–19
> - S2: α=0.30 β=0.30 γ=0.60 (β/α=1.0) thay vì α=0.40 β=0.20 của v9
> - S3: α=0.25 β=0.35 γ=0.50 (β/α=1.4)
> + Root cause của v9 oscillation: β/α=0.50 trong S2 quá yếu — GRL không đủ override L_mat với PolyU cross-modality pairs
```bash
cd /home/aiserver/works/fingerprint
nohup bash sifq/scripts/run_train_v14.sh > sifq/train_v14.log 2>&1 &
echo "PID: $!"
# Theo dõi log
tail -f sifq/train_v11.log
```
- Dữ liệu: SD302-A/B/D + FVC2002 + FVC2004 + PolyU = **43,559 ảnh, 24 sensors**
- L_sens anchors: SD302 (~2,276 groups) + PolyU (336 cross-modal groups) = 2,612 total
- L_mat: SD302 + FVC (PolyU masked)
- L_deg: FVC only (SD302 + PolyU masked)
- Checkpoint: `sifq/checkpoints_full_v11/last.pt`
- Metrics: `sifq/checkpoints_full_v11/metrics.jsonl`
- Thời gian ước tính: **~9 giờ** (2× RTX A4000, DataParallel, 453 steps/epoch)
Kiểm tra nhanh training đang chạy:
```bash
# Xem loss mới nhất
tail -5 sifq/checkpoints_full_v11/metrics.jsonl | python3 -c "
import sys, json
for l in sys.stdin: r=json.loads(l); print(f'ep{r[\"epoch\"]:02d} deg={r[\"train_l_deg\"]:.4f} sens={r[\"train_l_sens\"]:.4f} spread={r[\"train_l_spread\"]:.4f} lr={r[\"lr\"]:.2e} total={r[\"train_total\"]:.4f}')
"
```
**Expected trends v11:**
| Loss | S1 (ep0-9) | S2 (ep20-34) | S3 (ep40+) |
|------|-----------|-------------|------------|
| `L_deg` | 0.10 → **<0.05** | giữ <0.05 | giữ <0.05 (γ=0.50) |
| `L_sens` | tracked only | **<1.5** (β/α=1.0 → GRL cân bằng) | <1.0 |
| `spread` | **giảm rõ** (uniform mode) | tiếp tục giảm | → ~0 |
| `L_mat` | flat ~0.3 | giảm (có FVC signal) | flat ~0.01 |
---
## 3. Inference — sinh Q scores từ model đã train
```bash
cd /home/aiserver/works/fingerprint
source .venv/bin/activate
python sifq/scripts/run_infer.py \
--checkpoint sifq/checkpoints_full_v11/last.pt \
--output sifq/eval_results/sifq_scores_v11.jsonl
```
Output: `sifq/eval_results/sifq_scores_v11.jsonl` — mỗi dòng là 1 ảnh với Q score + 6 concepts.
---
## 4. Evaluation — verify SOTA
### 4a. Nhanh: chỉ Track 2 (sensor invariance) + Track 4 (concept grounding)
```bash
python sifq/scripts/run_eval.py \
--sifq-scores sifq/eval_results/sifq_scores_v11.jsonl \
--checkpoint sifq/checkpoints_full_v11/last.pt \
--out-dir sifq/eval_results \
--skip-track1
```
### 4b. Đầy đủ: Track 1 (ERC) + Track 2 + Track 4
```bash
python sifq/scripts/run_eval.py \
--sifq-scores sifq/eval_results/sifq_scores_v11.jsonl \
--checkpoint sifq/checkpoints_full_v11/last.pt \
--out-dir sifq/eval_results \
--max-pairs 3000
```
### 4c. Có NFIQ2 baseline (so sánh trực tiếp với SOTA)
```bash
# NFIQ2 is not on PyPI — generate proxy scores using image quality heuristics:
python sifq/scripts/gen_nfiq2_proxy_scores.py \
--sifq-scores sifq/eval_results/sifq_scores_v11.jsonl \
--output /tmp/nfiq2_scores.jsonl
python sifq/scripts/run_eval.py \
--sifq-scores sifq/eval_results/sifq_scores_v11.jsonl \
--checkpoint sifq/checkpoints_full_v11/last.pt \
--out-dir sifq/eval_results \
--nfiq2-scores /tmp/nfiq2_scores.jsonl
```
---
## 5. Xem kết quả
```bash
# Bảng số
cat sifq/eval_results/eval_summary.json
# Plots (mở file)
ls sifq/eval_results/*.png
```
| File | Nội dung |
|------|----------|
| `eval_summary.json` | Tất cả metrics (AUC_ERC, KS statistic, Pearson) |
| `plot_erc.png` | Track 1 — ERC curve, AUC thấp hơn là tốt hơn |
| `plot_sensor_hist.png` | Track 2 — Q distribution per sensor |
| `plot_sensor_scatter.png` | Track 2 — scatter Q_s1 vs Q_s2 |
| `plot_crosstalk.png` | Track 4 — concept grounding heatmap |
---
## 6. Tiêu chí SOTA rank 1
| Track | Metric | v5 | v7 nofvc | Target v11 |
|-------|--------|-----|---------|----------|
| Track 1 (ERC) | AUC_ERC | 0.8884 | — | < NFIQ2 proxy |
| Track 2 (Sensor) | mean_KS | 0.326 | 0.326 (collapse) | < 0.10 |
| Track 2 (Sensor) | Pearson cross-sensor | 0.179 | — | > 0.70 |
| Track 4 (Concepts) | blur → clarity rho | +0.483 ❌ | — | negative |
| Track 4 (Concepts) | occlusion → minutiae rho | -0.013 ❌ | — | negative |
---
## Checkpoint paths (hiện tại)
| Thành phần | Path |
|-----------|------|
| MDGT teacher | `pad/TRAM-downstream/checkpoint/checkpoints_dinov2_tram/best_eer.pt` |
| NIST SD302-A | `dataset/302a/images/challengers` |
| NIST SD302-B | `dataset/302b/images/baseline` |
| NIST SD302-D | `dataset/nist_302d/images/auxiliary` |
| FVC2002 | `dataset/FVC_Dataset/FVC2002` |
| FVC2004 | `dataset/FVC_Dataset/FVC2004` |
| PolyU | `dataset/PolyU` |
| SIFQ v18 (done, score collapse q_std≈0.01, Pearson=0.007 ❌) | `sifq/checkpoints/v18/last.pt` |
| SIFQ v17 (done, score collapse 18.1–53.0, q_std=0.60 ❌) | `sifq/checkpoints/v17/last.pt` |
| SIFQ v16 (done, score collapse 46.9–50.5 ❌) | `sifq/checkpoints/v16/last.pt` |
| SIFQ v15 (done, score collapse 24–56 ❌) | `sifq/checkpoints_full_v15/last.pt` |
| SIFQ v14 (eval done, KS=0.263 ✅) | `sifq/checkpoints_full_v14/last.pt` |
| SIFQ v13 (completed) | `sifq/checkpoints_full_v13/last.pt` |
| SIFQ v12 (completed) | `sifq/checkpoints_full_v12/last.pt` |
| SIFQ v11 (completed, score collapse ~58.3) | `sifq/checkpoints_full_v11/last.pt` |
| SIFQ v10 (stopped, PolyU excluded from L_sens) | `sifq/checkpoints_full_v10/last.pt` |
| SIFQ v9 (stopped ep63, β/α=0.50 too weak) | `sifq/checkpoints_full_v9/last.pt` |
| SIFQ v8 (stopped ep22, sens stuck 3-3.5) | `sifq/checkpoints_full_v8/last.pt` |
| SIFQ v7 nofvc (ref) | `sifq/checkpoints_full_v7_nofvc/last.pt` |
## Lịch sử checkpoint
| Version | Epochs | Vấn đề | Trạng thái |
|---------|--------|--------|----------|
| `checkpoints_full/` | 21 | beta=0 bug → GRL tắt | Lỗi |
| `checkpoints_full_v2/` | 50 | spread loss bimodal | Lỗi |
| `checkpoints_full_v3/` | 30 | Q collapse, deg dead | Lỗi |
| `checkpoints_full_v5/` | 25 | Chỉ noise degradation | l_deg≈0 |
| `checkpoints_full_v6/` | 80 | Full deg pipeline | Ref |
| `checkpoints_full_v7_nofvc/` | 80 | Score collapse (spread=0.010), L_sens explosion ep17-18, γ=0.40 làm L_deg plateau 0.104 | Ref |
| `checkpoints_full_v8/` | 22 | Uniform spread, β ramp, γ=0.50, cosine LR, FVC — dừng ep22 vì α/γ step change tại ep15 gây sens oscillate 3–3.5 | Stopped |
| `checkpoints_full_v9/` | 63 | Ramp ALL THREE (α/β/γ) ep10–19 + PolyU — dừng ep63 vì β/α=0.50 trong S2 quá yếu, sens oscillate 2–3 suốt S2/S3 | Stopped |
| `checkpoints_full_v10/` | early | PolyU excluded từ L_sens — dừng sớm, sai thiết kế | Stopped |
| `checkpoints_full_v11/` | 80 | Score collapse: 95% ảnh tại ~58.3, wet_press concept sai chiều | Completed |
| `checkpoints_full_v12/` | 80 | T17+T18+T19: L_deg all datasets, fix wet_press erode, gamma=1.0 | Completed |
| `checkpoints_full_v13/` | 80 | Revert T17, per-dataset L_spread, T25 noise fix, T26 occlusion fix | Completed |
| `checkpoints_full_v14/` | 60 | Train from scratch; exclude non-seg slap; KS=0.263; Pearson=0.294 | Completed |
| `checkpoints_full_v15/` | 60 | T30: SD302 concept-only L_deg, gamma=2.0; score collapse 24–56 ❌ | Completed |
| `checkpoints/v16/` | 60 | T31: per-identity stats ALL datasets; score collapse 46.9–50.5 ❌; L_mat vs L_pair conflict | Completed |
| `checkpoints/v17/` | 60 | T32: FVC-only stats; score collapse 18.1–53.0 (q_std=0.60 ❌); GRL suppresses SD302 quality | Completed |
| `checkpoints/v18/` | 60 | T33: --no-mat-stats + W_SPREAD=2.0 + gamma=0.5 + SD302-A; revert to v14 design; score collapse q_std≈0.01, KS=0.249⚠️(false positive) ❌ | Completed ❌ |