-
Notifications
You must be signed in to change notification settings - Fork 12
/
fid_example.py
32 lines (26 loc) · 1.14 KB
/
fid_example.py
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
#!/usr/bin/env python3
from __future__ import absolute_import, division, print_function
import os
import glob
#os.environ['CUDA_VISIBLE_DEVICES'] = '0'
import numpy as np
import fid
from scipy.misc import imread
import tensorflow as tf
# Paths
image_path = '/local00/bioinf/tmp/' # set path to some generated images
stats_path = '/local00/bioinf/fid_stats_cifar10.npz' # training set statistics
inception_path = fid.check_or_download_inception(None) # download inception network
# loads all images into memory (this might require a lot of RAM!)
image_list = glob.glob(os.path.join(datapath, '*.jpg'))
images = np.array([imread(str(fn)).astype(np.float32) for fn in files])
# load precalculated training set statistics
f = np.load(path)
mu_real, sigma_real = f['mu'][:], f['sigma'][:]
f.close()
fid.create_incpetion_graph(inception_path) # load the graph into the current TF graph
with tf.Session() as sess:
sess.run(tf.global_variables_initializer())
mu_gen, sigma_gen = fid.calculate_activation_statistics(images, sess, batch_size=100)
fid_value = fid.calculate_frechet_distance(mu_gen, sigma_gen, mu_real, sigma_real)
print("FID: %s" % fid_value)