-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patheval.py
More file actions
46 lines (39 loc) · 1.45 KB
/
eval.py
File metadata and controls
46 lines (39 loc) · 1.45 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
import os
import yaml
import torch
from pytorch_fid import fid_score
from src import set_seed
if __name__ == "__main__":
with open("config/eval.yaml", "r") as f:
config = yaml.safe_load(f)
device = torch.device('cuda' if torch.cuda.is_available() else 'cpu')
print(f"Using device: {device}")
# OS
os_config = config["os"]
set_seed(os_config["seed"])
# Data
data_config = config["data"]
path_real_images = data_config["path_real_images"]
path_generated_images = data_config["path_generated_images"]
if not os.path.isdir(path_real_images):
raise NotADirectoryError(
f"Real image path does not exist or is not a directory: {path_real_images}")
if not os.path.isdir(path_generated_images):
raise NotADirectoryError(
f"Generated image path does not exist or is not a directory: {path_generated_images}")
# Inference
inference_config = config["inference"]
batch_size = inference_config["batch_size"]
dims = inference_config["dims"]
print("Calculating FID score...")
try:
fid_value = fid_score.calculate_fid_given_paths(
paths=[path_real_images, path_generated_images],
batch_size=batch_size,
device=device,
dims=dims,
num_workers=8
)
print(f"Calculated FID score: {fid_value}")
except Exception as e:
print(f"An error occurred while calculating FID: {e}")