fairtalking-second-work / scripts /batch_test_all.sh
huahua123313's picture
Add files using upload-large-folder tool
7c2871f verified
Raw
History Blame Contribute Delete
5.61 kB
#!/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!"