UFR-Fing / scripts /run_train_v16.sh
anbinh39's picture
Add files using upload-large-folder tool
cfc7a54 verified
Raw
History Blame Contribute Delete
3.11 kB
#!/usr/bin/env bash
# v16 training — Fix score collapse / no discrimination từ v15.
#
# Root cause analysis (v15 failure):
#
# Tất cả ảnh được score gần như giống nhau (range 24–56, thay vì 0–100).
# Model không phân biệt được ảnh tốt/xấu.
#
# Nguyên nhân chính: stats=None trong mọi lần gọi loss_mat().
#
# Khi stats=None:
# q_mat = raw cosine ≈ 0.85 cho mọi ảnh (MDGT quality-robust)
# → model tối ưu pred_score → (0.85/2 + 0.5)×100 ≈ 92.5 cho tất cả
# → L_spread kéo về [10,90], L_mat kéo về 92.5
# → equilibrium tại q_mean ≈ 52 không thay đổi suốt 60 epoch
#
# v16 fixes:
# T31a — Per-identity cosine stats (compute_identity_cos_stats):
# Sau khi tính prototype, chạy second pass để tính (mean_cos, std_cos)
# per identity. Pass stats vào loss_mat() → target được normalize:
# q_mat = tanh((cos - mu_i) / sigma_i)
# Ảnh tốt hơn trung bình của identity → target > 0 → score > 50.
# Ảnh kém hơn → target < 0 → score < 50.
# L_mat và L_spread giờ CÙNG chiều thay vì conflict.
#
# T31b — tanh scaling trong _compute_q_mat:
# tanh maps z ∈ (-∞,+∞) về (-1,1), tương thích với
# pred_normalized = (score/100 - 0.5) × 2 ∈ [-1,1].
# Không cần clamp thủ công, không có extreme target.
#
# T31c — Tăng W_SPREAD từ 2.0 → 4.0:
# Với teacher target đã zero-centred, tăng spread weight
# giúp model học spread nhanh hơn mà không conflict.
#
# T31d — deg-every-n-steps 1 (thay vì 2):
# L_deg mỗi step = 2× signal so với v15. FVC-only ranking.
#
# Train từ đầu, 60 epochs, LR=1e-4 cosine.
set -euo pipefail
REPO_ROOT="$(cd "$(dirname "$0")/../.." && pwd)"
source "${REPO_ROOT}/.venv/bin/activate"
VERSION="v16"
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"
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 4.0 \
--concept-deg-gamma 2.0 \
--sd302-concept-weight 1.0 \
--deg-every-n-steps 2 \
--min-sigma 0.02 \
--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