File size: 5,608 Bytes
7c2871f | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 | #!/usr/bin/env bash
# Batch test script for all methods and datasets
# Tests top-3 checkpoints and last checkpoint for each method on all test datasets
set -euo pipefail
cd "$(dirname "$0")/.."
# Load .env if present
[ -f .env ] && set -a && . ./.env && set +a
# Configuration
OUTPUT_DIR="outputs"
RESULTS_CSV="batch_test_results_$(date +%Y%m%d_%H%M%S).csv"
# Methods to test
METHODS=("cta" "psm" "radr")
# Test datasets and their corresponding scripts
# Note: We'll handle method-specific scripts in the main loop
DATASET_NAMES=("ours" "thb" "ff++" "hdtf" "mmdf")
echo "=== Batch Testing All Methods and Datasets ==="
echo "Output CSV: $RESULTS_CSV"
echo ""
# Create results CSV header
echo "method,checkpoint,dataset,test_acc,test_auc,timestamp" > "$RESULTS_CSV"
# Function to run test and extract metrics
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
# Run the test and capture output
timestamp=$(date +%Y-%m-%d_%H:%M:%S)
# Determine how to call the script based on dataset
case "$dataset" in
"ff++"|"hdtf")
# These scripts expect method as first argument
output=$(bash "$script" "$method" "$checkpoint" 2>&1)
;;
*)
# Other scripts expect checkpoint as first argument
output=$(bash "$script" "$checkpoint" 2>&1)
;;
esac
# Extract metrics from the output
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 metrics not found in output, try to extract from log files
if [[ "$test_acc" == "N/A" || "$test_auc" == "N/A" ]]; then
echo " Metrics not found in output, checking log files..."
# This is a fallback - in practice the metrics should be in the output
fi
# Append results to CSV
echo "$method,$(basename "$checkpoint"),$dataset,$test_acc,$test_auc,$timestamp" >> "$RESULTS_CSV"
echo " Results: acc=$test_acc, auc=$test_auc"
echo ""
}
# Main testing loop
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
# Get all checkpoint files (excluding last.ckpt)
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"
# Test top-3 checkpoints
echo "Testing top-3 checkpoints:"
for ((i=0; i<3 && i<${#checkpoints[@]}; i++)); do
checkpoint="${checkpoints[$i]}"
# Test on all datasets
for dataset in "ours" "thb" "ff++" "hdtf" "mmdf"; do
# Determine script path based on dataset
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
# Test last checkpoint
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 ""
# Small delay between methods
sleep 2
done
echo "=== Batch testing completed ==="
echo "Results saved to: $RESULTS_CSV"
# Display summary
echo ""
echo "Summary of results:"
echo "=================="
column -t -s, "$RESULTS_CSV"
echo ""
echo "Batch testing completed successfully!" |