#!/usr/bin/env bash # v21 training — T36: full prototypes + FVC-only L_deg (remove --deg-include-sd302). # # Root cause analysis (v20 failure — same collapse as v15–v19): # # v20 training showed healthy q_std≈18.3 across all 60 epochs but INFERENCE # collapsed (all SD302 sensors score ~53.38, q_std≈0.007, concepts stuck at # [0.994, 0.008, ...]). The T35 diagnosis was right about truncated # prototypes (root cause 1) but the second fix (--deg-include-sd302) was # WRONG and caused the collapse: # # Root cause — L_rank on SD302 creates a stable attractor at ~53.38 (T35b was wrong): # SD302 images are ALL high quality (controlled NIST acquisition protocol). # With --deg-include-sd302, L_rank says: # Q(clean_SD302) > Q(low_deg_SD302) + m # Q(low_deg_SD302) > Q(high_deg_SD302) + m # The model satisfies this constraint by assigning a single "clean score" (~53.38) # to ALL clean SD302 images and lower scores to degraded variants. There is # NO gradient pushing different clean SD302 images apart — L_rank only requires # clean > degraded, not that clean images differ from each other. Combined with # L_spread_ds (batch-level, arbitrary ordering) and L_pair (same-identity # same-score pressure), the model collapses all clean SD302 to ~53.38 at inference. # # Why v14 worked without --deg-include-sd302: # FVC has GENUINE quality variation (8 impressions per subject with naturally # different quality — blur, dry, wet, pressure). MDGT raw cosine to prototype # GENUINELY varies (~0.75 worst to ~0.93 best) for FVC subjects. L_mat gradient # on FVC shapes the backbone to be quality-discriminative. At inference on SD302, # the backbone's learned quality features transfer (ridge clarity, noise level, # ridge continuity) → SD302 images scored by intrinsic quality, not batch rank. # This transfer mechanism is BLOCKED when L_rank on SD302 creates the ~53.38 # attractor that overrides the learned quality representation. # # v21 fix (T36): # T36 — Remove --deg-include-sd302. Revert to FVC-only L_deg (T27 original design). # Keep --proto-max-batches 0 (T35a, the correct fix from v20). # L_deg applied only to FVC images: genuine quality variation → genuine L_mat # gradient → backbone learns quality features that transfer to SD302 at inference. # L_spread_ds still applied to SD302 to force batch-level spread (prevents batch- # collapse without creating the attractor problem). # # All other settings kept from v20: # --no-mat-stats --spread-weight 3.0 --deg-every-n-steps 2 # --concept-deg-gamma 0.5 --sd302-concept-weight 0.0 # --batch-size 128 --gpus 0 --epochs 60 # SD302-A+B+D included (full 30K sensor-invariant images, 19 sensors) # # Expected improvements vs v20: # q_std (inference) : >12 (v20: ~0.007) # Score range : 10–90 (v20: 53.20–53.41) # Track 2 mean_KS : ≤0.30 (v20: 0.4936 — driven by sensor clusters, not quality) # Track 2 Pearson : ≥0.20 (v20: 0.0048) # Concept grounding : blur→clarity<0, noise→noise_level<0, etc. set -euo pipefail REPO_ROOT="$(cd "$(dirname "$0")/../.." && pwd)" export PATH="/home/aiserver/miniconda3/bin:$PATH" VERSION="v21" SAVE_DIR="${REPO_ROOT}/sifq/checkpoints/${VERSION}" LOG_FILE="${REPO_ROOT}/sifq/logs/train_${VERSION}.log" EVAL_SCRIPT="${REPO_ROOT}/sifq/scripts/run_eval_${VERSION}.sh" mkdir -p "${REPO_ROOT}/sifq/logs" python "${REPO_ROOT}/sifq/scripts/train_sifq.py" \ --root-302a "${REPO_ROOT}/dataset/302a/images/challengers" \ --root-302b "${REPO_ROOT}/dataset/302b/images/baseline" \ --root-302d "${REPO_ROOT}/dataset/nist_302d/images/auxiliary" \ --root-fvc2002 "${REPO_ROOT}/dataset/FVC_Dataset/FVC2002" \ --root-fvc2004 "${REPO_ROOT}/dataset/FVC_Dataset/FVC2004" \ --root-polyu "${REPO_ROOT}/dataset/PolyU" \ --exclude-sensor "R_1000_slap,R_500_slap,S_500_slap" \ --mdgt-checkpoint "${REPO_ROOT}/pad/TRAM-downstream/checkpoint/checkpoints_dinov2_tram/best_eer.pt" \ --epochs 60 \ --batch-size 128 \ --image-size 224 \ --lr 1e-4 \ --spread-mode uniform \ --spread-weight 3.0 \ --concept-deg-gamma 0.5 \ --sd302-concept-weight 0.0 \ --deg-every-n-steps 2 \ --no-mat-stats \ --proto-max-batches 0 \ --max-train-samples -1 \ --num-workers 8 \ --gpus 0,1 \ --save-dir "${SAVE_DIR}" echo "[auto-eval] Training done. Starting eval ${VERSION}..." bash "${EVAL_SCRIPT}" >> "${LOG_FILE}" 2>&1