#!/usr/bin/env bash
# F12-only finetune: identity-init Conformer on the current best linear head.
# Does not call stage 2.
set -euo pipefail
ROOT="$(cd "$(dirname "$0")/.." && pwd)"
cd "$ROOT"

TAG="${TAG:-frame_asd_F12_conf_ft}"
RESUME="${RESUME:-$ROOT/save/icbhi_beats_frame_asd_frame_asd_F12_sastruct_s1_rerun2/best.pth}"
OUT="$ROOT/save/icbhi_beats_frame_asd_${TAG}"
mkdir -p "$OUT"

python -u train.py \
  --tag "$TAG" \
  --method frame_asd --model beats --dataset icbhi --seed 1 \
  --save_dir "$ROOT/save" \
  --class_split lungsound --n_cls 4 --batch_size 16 \
  --desired_length 5 --optimizer adam --weight_decay 1e-6 \
  --cosine --test_fold official --pad_types repeat \
  --ma_update --ma_beta 0.5 --print_freq 50 \
  --min_se 48 --min_sp 72 --early_stop_patience 6 \
  --mil_pool topk --mil_topk 3 \
  --use_specaug --specaug_policy structured \
  --beats_wave_scale 32768 --threshold_n_points 41 \
  --ablation_stage F12_conf_ft --epochs 12 --learning_rate 2e-5 --head_lr 1e-4 \
  --layer_decay 0.9 --head_type temporal --temporal_layers 2 --temporal_heads 8 \
  --resume "$RESUME" --resume_linear_readout --reset_epoch_on_resume \
  --eval_first --num_workers 4 --feedback_stage 0 \
  "$@" 2>&1 | tee "$OUT/train.log"
