#!/usr/bin/env bash # v22 training — First correct run: full prototypes + random batching + single GPU. # # Root cause analysis — why v15–v21 all failed: # # BUG 1 — CrossSensorBatchSampler default k_cross=16: # k_cross=16 forces 16 guaranteed cross-sensor pairs per batch. # With full prototypes (nearly-constant L_mat targets for SD302), backbone # over-optimises sensor invariance → loses quality discrimination → # Pearson collapses (~0.09 in v21). Fix: --k-cross 0 (random batching). # # BUG 2 — proto-max-batches default=150: # Only 45% of dataset used for prototypes → 2–3 partial sensor prototypes # per SD302 identity → cosine target is sensor-biased, not quality-correlated # → no per-image quality gradient → score collapse in v15–v19. # Fix: --proto-max-batches 0 (full dataset). # # BUG 3 — DataParallel (––gpus 0,1) 4.3× slower for TinyViT-5M: # Fix: --gpus 0 (single GPU). # # BUG 4 — Redundant teacher double-pass at startup: # Fix: build_prototypes_from_cache() — O(N) CPU, no second teacher forward. # cd /home/aiserver/works/fingerprint nohup bash sifq/scripts/run_train_v22.sh > sifq/logs/train_v22.log 2>&1 & echo "PID: $!" tail -f sifq/logs/train_v22.log# v22 design goals (per research design §4–7): # Quality-discriminative : q_std ≥ 18 (model ranks fingerprints by utility) # Sensor-invariant : pair loss → 0 (L_sens equilibrium), adv → rand_ce # Concept-grounded : all Track 4 target concepts negative Spearman ρ # Training speed : ~220s/epoch (single GPU, no DataParallel overhead) # # Note on L_sens / pair loss: # v22 includes SD302-A (8 diverse roll sensors per finger) which creates genuine # cross-sensor quality variation in L_mat targets. L_pair starts high (~12 at # S2 onset) and decreases as L_sens equilibrium is found. This is expected # with a richer, more diverse dataset — it is NOT a training failure. set -euo pipefail REPO_ROOT="$(cd "$(dirname "$0")/../.." && pwd)" export PATH="/home/aiserver/miniconda3/bin:$PATH" VERSION="v22" 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 96 \ --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 \ --k-cross 0 \ --max-train-samples -1 \ --num-workers 8 \ --gpus 0 \ --save-dir "${SAVE_DIR}" echo "[auto-eval] Training done. Starting eval ${VERSION}..." bash "${EVAL_SCRIPT}" >> "${LOG_FILE}" 2>&1