File size: 3,684 Bytes
a17b394
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
# 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.