| #!/usr/bin/env bash |
| |
| |
|
|
| set -euo pipefail |
| cd "$(dirname "$0")/.." |
|
|
| |
| [ -f .env ] && set -a && . ./.env && set +a |
|
|
| |
| OUTPUT_DIR="outputs" |
| RESULTS_CSV="batch_test_results_$(date +%Y%m%d_%H%M%S).csv" |
|
|
| |
| METHODS=("cta" "psm" "radr") |
|
|
| |
| |
| DATASET_NAMES=("ours" "thb" "ff++" "hdtf" "mmdf") |
|
|
| echo "=== Batch Testing All Methods and Datasets ===" |
| echo "Output CSV: $RESULTS_CSV" |
| echo "" |
|
|
| |
| echo "method,checkpoint,dataset,test_acc,test_auc,timestamp" > "$RESULTS_CSV" |
|
|
| |
| run_test() { |
| local method="$1" |
| local checkpoint="$2" |
| local dataset="$3" |
| local script="$4" |
| |
| echo "Testing: method=$method, checkpoint=$(basename "$checkpoint"), dataset=$dataset" |
| |
| if [ ! -f "$script" ]; then |
| echo " Script not found: $script" |
| echo "$method,$(basename "$checkpoint"),$dataset,SCRIPT_NOT_FOUND,SCRIPT_NOT_FOUND,$(date +%Y-%m-%d_%H:%M:%S)" >> "$RESULTS_CSV" |
| return 1 |
| fi |
| |
| if [ ! -f "$checkpoint" ]; then |
| echo " Checkpoint not found: $checkpoint" |
| echo "$method,$(basename "$checkpoint"),$dataset,CHECKPOINT_NOT_FOUND,CHECKPOINT_NOT_FOUND,$(date +%Y-%m-%d_%H:%M:%S)" >> "$RESULTS_CSV" |
| return 1 |
| fi |
| |
| |
| timestamp=$(date +%Y-%m-%d_%H:%M:%S) |
| |
| |
| case "$dataset" in |
| "ff++"|"hdtf") |
| |
| output=$(bash "$script" "$method" "$checkpoint" 2>&1) |
| ;; |
| *) |
| |
| output=$(bash "$script" "$checkpoint" 2>&1) |
| ;; |
| esac |
| |
| |
| test_acc=$(echo "$output" | grep -oP "test/acc.*?\K[0-9\.]+" | head -1 || echo "N/A") |
| test_auc=$(echo "$output" | grep -oP "test/auc.*?\K[0-9\.]+" | head -1 || echo "N/A") |
| |
| |
| if [[ "$test_acc" == "N/A" || "$test_auc" == "N/A" ]]; then |
| echo " Metrics not found in output, checking log files..." |
| |
| fi |
| |
| |
| echo "$method,$(basename "$checkpoint"),$dataset,$test_acc,$test_auc,$timestamp" >> "$RESULTS_CSV" |
| |
| echo " Results: acc=$test_acc, auc=$test_auc" |
| echo "" |
| } |
|
|
| |
| for method in "${METHODS[@]}"; do |
| echo "=== Testing method: $method ===" |
| |
| method_dir="$OUTPUT_DIR/$method/checkpoints" |
| |
| if [ ! -d "$method_dir" ]; then |
| echo "Method directory not found: $method_dir" |
| continue |
| fi |
| |
| |
| checkpoints=($(find "$method_dir" -name "*.ckpt" -not -name "last.ckpt" | sort -r)) |
| |
| if [ ${#checkpoints[@]} -eq 0 ]; then |
| echo "No checkpoints found for method: $method" |
| continue |
| fi |
| |
| echo "Found ${#checkpoints[@]} checkpoints for $method" |
| |
| |
| echo "Testing top-3 checkpoints:" |
| for ((i=0; i<3 && i<${#checkpoints[@]}; i++)); do |
| checkpoint="${checkpoints[$i]}" |
| |
| |
| for dataset in "ours" "thb" "ff++" "hdtf" "mmdf"; do |
| |
| case "$dataset" in |
| "ours") |
| script="scripts/test_${method}.sh" |
| ;; |
| "thb") |
| script="scripts/test_${method}_thb.sh" |
| ;; |
| "ff++") |
| script="scripts/test_ffpp.sh" |
| ;; |
| "hdtf") |
| script="scripts/test_hdtf_paired.sh" |
| ;; |
| "mmdf") |
| script="scripts/test_${method}_mmdf.sh" |
| ;; |
| esac |
| |
| run_test "$method" "$checkpoint" "$dataset" "$script" |
| done |
| done |
| |
| |
| echo "Testing last checkpoint:" |
| last_checkpoint="$method_dir/last.ckpt" |
| if [ -f "$last_checkpoint" ]; then |
| for dataset in "ours" "thb" "ff++" "hdtf" "mmdf"; do |
| case "$dataset" in |
| "ours") |
| script="scripts/test_${method}.sh" |
| ;; |
| "thb") |
| script="scripts/test_${method}_thb.sh" |
| ;; |
| "ff++") |
| script="scripts/test_ffpp.sh" |
| ;; |
| "hdtf") |
| script="scripts/test_hdtf_paired.sh" |
| ;; |
| "mmdf") |
| script="scripts/test_${method}_mmdf.sh" |
| ;; |
| esac |
| |
| run_test "$method" "$last_checkpoint" "$dataset" "$script" |
| done |
| else |
| echo "Last checkpoint not found: $last_checkpoint" |
| fi |
| |
| echo "" |
| echo "---" |
| echo "" |
| |
| |
| sleep 2 |
| done |
|
|
| echo "=== Batch testing completed ===" |
| echo "Results saved to: $RESULTS_CSV" |
|
|
| |
| echo "" |
| echo "Summary of results:" |
| echo "==================" |
| column -t -s, "$RESULTS_CSV" |
|
|
| echo "" |
| echo "Batch testing completed successfully!" |