-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfid_usage_example.py
More file actions
55 lines (40 loc) · 1.67 KB
/
fid_usage_example.py
File metadata and controls
55 lines (40 loc) · 1.67 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
# ---------------------------------------------------------------
# Copyright (c) Cybersecurity Cooperative Research Centre 2023.
#
# This source code is licensed under the MIT license found in the
# LICENSE file in the root directory of this source tree.
# ---------------------------------------------------------------
'''
This file demonstrates how to run the FID metrics presented in the paper.
The `init_fid_model` automatically downloads the pre-trained weights from an AWS bucket a
and creates a new model.
The "Example Usage" code block below shows how to calculate FID with your own model.
The inputs to the FID model need to be in a compatible format.
'''
import click
import os
from utils import load_cfg
from fid import init_fid_model, calculate_frechet_distance
@click.command()
@click.option('--config_file','-c', default='default.yaml')
def main(config_file):
###########################################
# Load Configurations
cur_dir = os.path.dirname(os.path.realpath(__file__))
cfg_dir = os.path.join(cur_dir, 'config')
cfg = load_cfg(config_file, cfg_dir)
###########################################
# Initialize fid model
fid_model, fid_stats = init_fid_model(cfg, load_path=cur_dir, device_id=0)
mu1, sigma1, act1 = fid_stats['test']
###########################################
# Example usage.
###########################################
# x_hat = chart_model.sample()
# activations, _, _ = fid_model(x_hat)
# mu2 = np.mean(acts, axis=0)
# sigma2 = np.cov(acts, rowvar=False)
# score = calculate_frechet_distance(mu1, sigma1, mu2, sigma2)
# print(score)
if __name__ == "__main__":
main()