UFR-Fing / scripts /_gen_report_v24.py
anbinh39's picture
Add files using upload-large-folder tool
cfc7a54 verified
Raw
History Blame Contribute Delete
8.61 kB
import json, numpy as np
from scipy.stats import spearmanr
from datetime import datetime
records = [json.loads(l) for l in open('eval_results/sifq_scores_v24.jsonl')]
CNAMES = ['orientation_coherence','ridge_valley_clarity','continuity','noise_level','contrast_uniformity','minutiae_reliability']
concepts = np.array([r['concepts'] for r in records])
qs = np.array([r['q_score'] for r in records])
d = json.load(open('eval_results/v24/eval_summary.json'))
t2 = d['track2_sensor_invariance']['SIFQ']
t4 = d['track4_concept_grounding']
TARGETS = {
'blur': ['ridge_valley_clarity', 'continuity'],
'noise': ['noise_level'],
'jpeg': ['continuity', 'ridge_valley_clarity'],
'occlusion': ['minutiae_reliability'],
'dry_skin': ['contrast_uniformity', 'continuity', 'orientation_coherence'],
'wet_press': ['ridge_valley_clarity', 'minutiae_reliability', 'orientation_coherence'],
}
SEP = '=' * 70
SEP2 = '-' * 70
lines = [
SEP,
'SIFQ -- Concept Quality Model: Ly thuyet & Ket qua (v24)',
f'Generated: {datetime.now().strftime("%Y-%m-%d %H:%M")}',
SEP,
'',
'1. DINH NGHIA 6 CONCEPTS',
SEP2,
'Tat ca concepts: cao = chat luong tot hon, dau ra trong [0, 1].',
'',
' # Concept Y nghia vat ly',
' -- -------------------------- -----------------------------------------------',
' 0 orientation_coherence Ridge flow nhat quan, local orientation field smooth',
' 1 ridge_valley_clarity Bien ridge-valley sac net, contrast cuc bo cao',
' 2 continuity Ridge lines lien tuc, khong bi dut gay',
' 3 noise_level It nhieu ngau nhien (cao = it noise = tot)',
' 4 contrast_uniformity Contrast deu tren toan foreground',
' 5 minutiae_reliability Minutiae co the trich xuat chinh xac',
'',
' Degradation Concept Map (v25 -- T40):',
' blur -> [clarity[1], continuity[2], orient_coh[0]]',
' noise -> [noise_level[3], contrast_u[4]]',
' jpeg -> [continuity[2], clarity[1], contrast_u[4]]',
' occlusion -> [minutiae_reliability[5]]',
' dry_skin -> [contrast_u[4], continuity[2], orient_coh[0]]',
' wet_press -> [clarity[1], minutiae_rel[5], orient_coh[0]]',
'',
' Ly do thiet ke map nhu vay:',
' - Moi concept phai duoc giam sat boi >= 2 loai degradation (tranh single-',
' point-of-failure: 1 degradation target 1 concept -> signal yeu, de bi',
' gradient interference invert chieu).',
' - Chon degradation phu hop vat ly: jpeg blocking -> contrast bands (khong',
' chi ridge artifacts), blur -> orientation blur (khong chi clarity loss).',
'',
'',
'2. CO CHE TRAINING CONCEPT (L_concept)',
SEP2,
'Voi moi cap anh (mild degradation vs severe degradation cung loai):',
'',
' L_concept = SUM Huber( c_mild[c], c_severe[c] + 0.1 )',
' c in targets(degradation_type)',
'',
' -> Anh degradation nhe phai co concept cao hon anh degradation nang >= 0.1',
' -> Model hoc tung concept phan ung dung chieu voi loai hu hong tuong ung',
'',
'Ket hop ranking loss:',
' L_rank = relu(Q_severe - Q_mild + m) + relu(Q_mild - Q_clean + m)',
' -> Q giam theo thu tu: clean > mild_deg > severe_deg',
'',
' L_deg = L_rank + gamma * L_concept',
' gamma = 2.0 (v24) -> 1.5 (v25)',
' - gamma qua cao (2.0): gradient conflict qua manh -> noise_level inversion',
' - gamma qua thap (0.5, v22): blur->continuity FAIL (+0.261)',
' - gamma = 1.5: compromise, du manh cho blur/jpeg, khong gay inversion',
'',
'',
'3. VAN DE CONCEPT SATURATION',
SEP2,
'Nguyen nhan goc: L_concept chi train tren synthetic degradation pairs.',
'Voi real fingerprint images, KHONG co gradient dinh huong concept.',
'-> Concept troi ve gia tri mac dinh cua backbone features.',
'',
'Hau qua trong v24 (42,683 real fingerprint images):',
'',
' Concept mean std rho_Q Tinh trang',
' ---------------------------- ------ ----- ------ ---------------------------',
]
STATUS = {
'noise_level': '!! DOMINATES Q (rho=-0.989)',
'minutiae_reliability': '!! Saturated HIGH -- dead (range 0.84-0.93)',
'orientation_coherence':'!! Saturated LOW -- T39 overcorrected',
'ridge_valley_clarity': '!! Near-dead -- low variance',
'continuity': '!! Near-dead -- low variance',
'contrast_uniformity': '!! Near-dead -- low variance',
}
for i, name in enumerate(CNAMES):
c = concepts[:, i]
rho, _ = spearmanr(c, qs)
status = STATUS.get(name, 'OK')
lines.append(f' {name:<28} {c.mean():>6.3f} {c.std():>6.3f} {rho:>+7.3f} {status}')
lines += [
'',
' Vong lap nguy hiem (self-reinforcing collapse):',
' ScoreAggregator chon noise_level (std=0.340, cao nhat)',
' -> gradient tap trung update noise pathway',
' -> cac concept khac it duoc update -> variance thap hon',
' -> cang bi bo qua -> variance cang thap (vong lap)',
'',
' He qua: Q ≈ f(noise_level) -- model thuc chat la "noise detector",',
' khong phai "quality estimator" da khai niem.',
'',
'',
'4. KET QUA v24',
SEP2,
]
ks = t2['mean_ks_across_sensors']
pearson = t2['cross_sensor_pearson']
lines += [
' Track 2 -- Sensor Invariance:',
f' Mean KS (cross-sensor) = {ks:.4f} [goal <= 0.30] {"PASS" if ks <= 0.30 else "FAIL"}',
f' Cross-sensor Pearson = {pearson:.4f} [goal >= 0.20] {"PASS" if pearson >= 0.20 else "FAIL"}',
'',
' Y nghia: cung mot ngon tay chup bang cac sensor khac nhau -> SIFQ cho',
' score nhat quan. KS thap = phan bo giong nhau, Pearson cao = ranking on dinh.',
' NFIQ2 thuong co KS > 0.5 cho cross-sensor pairs.',
'',
' Track 4 -- Concept Grounding (rho < 0 = PASS):',
f' {"Degradation":<12} {"Concept":<28} {"rho":>7} Status',
f' {"------------":<12} {"----------------------------":<28} {"-------":>7} ------',
]
pass_count = total = 0
for row in t4:
deg = row['degradation']
for concept in TARGETS.get(deg, []):
rho = row.get(concept)
if rho is None:
continue
total += 1
ok = rho < 0
if ok:
pass_count += 1
status = 'PASS' if ok else 'FAIL <--'
lines.append(f' {deg:<12} {concept:<28} {rho:>+7.3f} {status}')
lines += [
'',
f' Result: {pass_count}/{total} pairs PASS',
'',
' 3 failures phan tich:',
'',
' [1] noise -> noise_level (rho=+0.365):',
' Regression tu v22 (-0.052, OK) -> v24 (+0.365, FAIL).',
' gamma=2.0 + T39 (orient_coh added to dry_skin/wet_press) thay doi',
' gradient landscape cua ScoreAggregator. Noise la degradation duy nhat',
' target noise_level -> single-point pressure -> de bi invert.',
'',
' [2] dry_skin -> contrast_u (rho=+0.051):',
' Persistent qua cac phien ban (v22: +0.504). Dry_skin la degradation',
' DUY NHAT target contrast_uniformity -> signal yeu, de bi gradient',
' tu cac loss khac at di.',
'',
' [3] dry_skin -> orient_coh (rho=+0.008):',
' T39 moi them orient_coh vao dry_skin, nhung wet_press->orient_coh',
' hoat dong tot (-0.448). Ly do: wet_press + blur deu co orientation',
' disruption manh, nhung dry_skin tao ra orientation noise khong nhat',
' quan -> khong du signal de orient_coh feature phan biet.',
'',
'',
'5. v25 -- T40 FIXES (dang chay)',
SEP2,
' Thay doi so voi v24:',
'',
' gamma: 2.0 -> 1.5',
'',
' blur: [1, 2] -> [1, 2, 0] (them orient_coh[0])',
' noise: [3] -> [3, 4] (them contrast_u[4])',
' jpeg: [2, 1] -> [2, 1, 4] (them contrast_u[4])',
' dry_skin / wet_press / occlusion: khong doi',
'',
' Ket qua ky vong:',
' - noise->noise_lv: +0.365 -> negative (gamma thap + noise 2-concept)',
' - dry_skin->contrast_u: +0.051 -> negative (3 degs co-supervise contrast_u)',
' - dry_skin->orient_coh: +0.008 -> negative (blur gives orient_coh strong signal)',
' - Cac pairs da PASS: giu nguyen (blur/jpeg/occlusion/wet_press)',
' - Track 2: giu PASS (KS, Pearson khong thay doi co ban)',
'',
SEP,
'END',
SEP,
]
txt = '\n'.join(lines)
with open('eval_results/sifq_report_v24.txt', 'w', encoding='utf-8') as f:
f.write(txt)
print(txt)
print()
print('>>> Saved: eval_results/sifq_report_v24.txt')