-
Notifications
You must be signed in to change notification settings - Fork 13
Expand file tree
/
Copy pathcompute_metrics.py
More file actions
80 lines (67 loc) · 2.08 KB
/
Copy pathcompute_metrics.py
File metadata and controls
80 lines (67 loc) · 2.08 KB
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
import argparse
import sys
from configs import MetricsConfig
from utils.argparse.argparse_utils import update_config_from_args
from utils.hardware.hardware_utils import select_device
from utils.metrics import compute_all_metrics
from utils.validation.project_validator import ProjectValidationError, ProjectValidator
def parse_args() -> argparse.Namespace:
"""
Parse command-line arguments for metric computation.
"""
parser = argparse.ArgumentParser(
description="Compute metrics for generated images",
)
parser.add_argument(
"--generated_img_dir",
type=str,
help="Generated image directory",
)
parser.add_argument(
"--ground_truth_img_dir",
type=str,
help="Ground Truth image directory",
)
parser.add_argument(
"--eval_batch_size",
type=int,
help="Batch size for evaluation",
)
parser.add_argument(
"--device",
type=str,
help="Evaluation device (mps, cpu, cuda)",
)
return parser.parse_args()
def main() -> None:
"""
Main function to run the metric computation.
"""
try:
args = parse_args()
ProjectValidator.validate_directory(
dir_path=args.generated_img_dir,
name="Generated image directory",
)
ProjectValidator.validate_directory(
dir_path=args.ground_truth_img_dir,
name="Ground Truth image directory",
)
metrics_config = update_config_from_args(
converting_config=MetricsConfig(),
args=args,
)
device = select_device(args.device)
compute_all_metrics(
generated_img_dir=args.generated_img_dir,
ground_truth_img_dir=args.ground_truth_img_dir,
eval_batch_size=args.eval_batch_size,
device=device,
)
print("✅ Metric computation completed successfully")
except ProjectValidationError as e:
print(f"❌ {e}")
print("❌ Metric computation failed")
sys.exit(1)
if __name__ == "__main__":
main()