fairtalking-second-work / scripts /BATCH_TESTING_README.md
huahua123313's picture
Add files using upload-large-folder tool
a17b394 verified
|
Raw
History Blame Contribute Delete
3.68 kB
# Batch Testing Script Documentation
## Overview
The `batch_test_all.sh` script automates the testing of all trained models (CTA, PSM, RADR) on all available test datasets (ours, THB, FF++, HDTF). It tests the top-3 checkpoints (based on validation AUC) and the last checkpoint for each method.
## Quick Start
```bash
# Run the full batch test
bash scripts/batch_test_all.sh
# Check the configuration first
bash scripts/test_batch_script.sh
```
## What It Tests
### Methods
- **CTA** (Cross-Temporal Attention)
- **PSM** (Pairwise Similarity Matching)
- **RADR** (Random Adversarial Regularization)
### Datasets
- **ours**: Original FairTalking test set
- **thb**: TalkingHeadBench test set
- **ff++**: FaceForensics++ test set
- **hdtf**: HDTF-paired test set
### Checkpoints per Method
- Top-3 checkpoints (highest validation AUC)
- Last checkpoint (final training state)
**Total tests**: 3 methods × 4 datasets × 4 checkpoints = **48 test combinations**
## Output Format
The script generates a CSV file with the following columns:
```csv
method,checkpoint,dataset,test_acc,test_auc,timestamp
psm,epoch24-valauc0.9963.ckpt,ours,0.9553,0.9935,2026-04-30_11:20:28
psm,epoch24-valauc0.9963.ckpt,thb,0.8721,0.9456,2026-04-30_11:21:15
...
```
## File Locations
### Input Checkpoints
- `outputs/cta/checkpoints/` - CTA model checkpoints
- `outputs/psm/checkpoints/` - PSM model checkpoints
- `outputs/radr/checkpoints/` - RADR model checkpoints
### Test Scripts
- `scripts/test_{method}.sh` - Ours dataset testing
- `scripts/test_{method}_thb.sh` - THB dataset testing
- `scripts/test_ffpp.sh` - FF++ dataset testing
- `scripts/test_hdtf_paired.sh` - HDTF dataset testing
### Output Files
- `batch_test_results_YYYYMMDD_HHMMSS.csv` - Main results file
- `outputs/{method}/test_predictions_*.csv` - Per-sample predictions
## Example Usage
```bash
# Test a single method on a single dataset
bash scripts/test_psm.sh outputs/psm/checkpoints/last.ckpt
# Test all methods and datasets (full batch)
bash scripts/batch_test_all.sh
# Check results
cat batch_test_results_20260430_112000.csv | column -t -s,
```
## Metrics Explanation
- **test/acc**: Test accuracy (binary classification accuracy)
- **test/auc**: Test AUC (Area Under ROC Curve)
Higher values indicate better performance. AUC is generally more informative for imbalanced datasets.
## Troubleshooting
### Common Issues
1. **Script not found**: Check that all test scripts exist in the `scripts/` directory
2. **Checkpoint not found**: Ensure models have been trained and checkpoints exist
3. **Metrics not extracted**: The script uses regex to extract metrics from stdout
### Manual Testing
If the batch script fails, you can test individual combinations manually:
```bash
# Test PSM on THB dataset
bash scripts/test_psm_thb.sh outputs/psm/checkpoints/last.ckpt
# Test CTA on FF++ dataset
bash scripts/test_ffpp.sh cta outputs/cta/checkpoints/last.ckpt
```
## Performance Notes
- The full batch test takes approximately **30-60 minutes** to complete
- Each individual test takes **1-3 minutes** depending on dataset size
- Results are saved incrementally, so you can interrupt and resume
- The script uses DDP (Distributed Data Parallel) for faster inference
## File Name Fix
The script automatically handles the checkpoint filename issue where `val_auc` was showing as 0.0000 due to template mismatch. New checkpoints will have correct AUC values in their filenames.
## Best Model Selection
The "best" model for each method is the checkpoint with the highest validation AUC among the top-3 saved checkpoints. This is automatically selected by PyTorch Lightning's ModelCheckpoint callback.