-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add disc mse error
- Loading branch information
Showing
7 changed files
with
103 additions
and
53 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,50 +1,56 @@ | ||
#!/usr/bin/env python3 | ||
|
||
|
||
from argparse import ArgumentParser | ||
import os | ||
|
||
os.environ['TF_CPP_MIN_LOG_LEVEL'] = '3' | ||
parser = ArgumentParser() | ||
parser.add_argument("mode") | ||
parser.add_argument("image_path") | ||
parser.add_argument("stats_path") | ||
parser.add_argument("model_path") | ||
parser.add_argument("--gpu", default="-1") | ||
args = parser.parse_args() | ||
|
||
os.environ['CUDA_VISIBLE_DEVICES'] = args.gpu | ||
import glob | ||
# os.environ['CUDA_VISIBLE_DEVICES'] = '2' | ||
import numpy as np | ||
import fid | ||
from scipy.misc import imread | ||
import tensorflow as tf | ||
|
||
data_path = 'E:/ixarea/dataset/128' | ||
stat_path = '../LittleGAN-test/fid_stats_celeba_128_all.npz' | ||
inception_path = '../LittleGAN-test/' | ||
image_path = '../LittleGAN-result' | ||
|
||
print("check for inception model..", end=" ", flush=True) | ||
inception_path = fid.check_or_download_inception(inception_path) | ||
print("ok") | ||
print("check for inception model..") | ||
inception_path = fid.check_or_download_inception(args.model_path) | ||
|
||
if not os.path.isfile(stat_path): | ||
print("load images..", end=" ", flush=True) | ||
image_list = glob.glob(os.path.join(data_path, '*.jpg')) | ||
if args.mode == "pre-calculate": | ||
print("load images..") | ||
image_list = glob.glob(os.path.join(args.image_path, '*.jpg')) | ||
images = np.array([imread(image).astype(np.float32) for image in image_list]) | ||
print("%d images found and loaded" % len(images)) | ||
|
||
print("create inception graph..", end=" ", flush=True) | ||
fid.create_inception_graph(inception_path) | ||
print("ok") | ||
|
||
print("calculte FID stats..", end=" ", flush=True) | ||
print("calculate FID stats..", end=" ", flush=True) | ||
with tf.Session() as sess: | ||
sess.run(tf.global_variables_initializer()) | ||
mu, sigma = fid.calculate_activation_statistics(images, sess, batch_size=100) | ||
np.savez_compressed(stat_path, mu=mu, sigma=sigma) | ||
np.savez_compressed(args.stats_path, mu=mu, sigma=sigma) | ||
print("finished") | ||
else: | ||
image_list = glob.glob(os.path.join(args.image_path, '*.jpg')) | ||
images = np.array([imread(str(fn)).astype(np.float32) for fn in image_list]) | ||
|
||
image_list = glob.glob(os.path.join(image_path, '*.jpg')) | ||
images = np.array([imread(str(fn)).astype(np.float32) for fn in image_list]) | ||
f = np.load(args.stats_path) | ||
mu_real, sigma_real = f['mu'][:], f['sigma'][:] | ||
f.close() | ||
|
||
f = np.load(stat_path) | ||
mu_real, sigma_real = f['mu'][:], f['sigma'][:] | ||
f.close() | ||
|
||
fid.create_inception_graph(inception_path) | ||
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.create_inception_graph(inception_path) | ||
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) | ||
fid_value = fid.calculate_frechet_distance(mu_gen, sigma_gen, mu_real, sigma_real) | ||
print("FID: %s" % fid_value) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters