本文整理汇总了Python中util.get_frechet_inception_distance方法的典型用法代码示例。如果您正苦于以下问题:Python util.get_frechet_inception_distance方法的具体用法?Python util.get_frechet_inception_distance怎么用?Python util.get_frechet_inception_distance使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类util
的用法示例。
在下文中一共展示了util.get_frechet_inception_distance方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_get_frechet_inception_distance
# 需要导入模块: import util [as 别名]
# 或者: from util import get_frechet_inception_distance [as 别名]
def test_get_frechet_inception_distance(self, mock_fid):
mock_fid.return_value = 1.0
util.get_frechet_inception_distance(
tf.placeholder(tf.float32, shape=[None, 28, 28, 3]),
tf.placeholder(tf.float32, shape=[None, 28, 28, 3]),
batch_size=100,
num_inception_images=10)
示例2: main
# 需要导入模块: import util [as 别名]
# 或者: from util import get_frechet_inception_distance [as 别名]
def main(_, run_eval_loop=True):
# Fetch and generate images to run through Inception.
with tf.name_scope('inputs'):
real_data, num_classes = _get_real_data(
FLAGS.num_images_generated, FLAGS.dataset_dir)
generated_data = _get_generated_data(
FLAGS.num_images_generated, FLAGS.conditional_eval, num_classes)
# Compute Frechet Inception Distance.
if FLAGS.eval_frechet_inception_distance:
fid = util.get_frechet_inception_distance(
real_data, generated_data, FLAGS.num_images_generated,
FLAGS.num_inception_images)
tf.summary.scalar('frechet_inception_distance', fid)
# Compute normal Inception scores.
if FLAGS.eval_real_images:
inc_score = util.get_inception_scores(
real_data, FLAGS.num_images_generated, FLAGS.num_inception_images)
else:
inc_score = util.get_inception_scores(
generated_data, FLAGS.num_images_generated, FLAGS.num_inception_images)
tf.summary.scalar('inception_score', inc_score)
# If conditional, display an image grid of difference classes.
if FLAGS.conditional_eval and not FLAGS.eval_real_images:
reshaped_imgs = util.get_image_grid(
generated_data, FLAGS.num_images_generated, num_classes,
FLAGS.num_images_per_class)
tf.summary.image('generated_data', reshaped_imgs, max_outputs=1)
# Create ops that write images to disk.
image_write_ops = None
if FLAGS.conditional_eval:
reshaped_imgs = util.get_image_grid(
generated_data, FLAGS.num_images_generated, num_classes,
FLAGS.num_images_per_class)
uint8_images = data_provider.float_image_to_uint8(reshaped_imgs)
image_write_ops = tf.write_file(
'%s/%s'% (FLAGS.eval_dir, 'conditional_cifar10.png'),
tf.image.encode_png(uint8_images[0]))
else:
if FLAGS.num_images_generated >= 100:
reshaped_imgs = tfgan.eval.image_reshaper(
generated_data[:100], num_cols=FLAGS.num_images_per_class)
uint8_images = data_provider.float_image_to_uint8(reshaped_imgs)
image_write_ops = tf.write_file(
'%s/%s'% (FLAGS.eval_dir, 'unconditional_cifar10.png'),
tf.image.encode_png(uint8_images[0]))
# For unit testing, use `run_eval_loop=False`.
if not run_eval_loop: return
tf.contrib.training.evaluate_repeatedly(
FLAGS.checkpoint_dir,
master=FLAGS.master,
hooks=[tf.contrib.training.SummaryAtEndHook(FLAGS.eval_dir),
tf.contrib.training.StopAfterNEvalsHook(1)],
eval_ops=image_write_ops,
max_number_of_evaluations=FLAGS.max_number_of_evaluations)
示例3: main
# 需要导入模块: import util [as 别名]
# 或者: from util import get_frechet_inception_distance [as 别名]
def main(_, run_eval_loop=True):
# Fetch and generate images to run through Inception.
with tf.name_scope('inputs'):
real_data, num_classes = _get_real_data(
FLAGS.num_images_generated, FLAGS.dataset_dir)
generated_data = _get_generated_data(
FLAGS.num_images_generated, FLAGS.conditional_eval, num_classes)
# Compute Frechet Inception Distance.
if FLAGS.eval_frechet_inception_distance:
fid = util.get_frechet_inception_distance(
real_data, generated_data, FLAGS.num_images_generated,
FLAGS.num_inception_images)
tf.summary.scalar('frechet_inception_distance', fid)
# Compute normal Inception scores.
if FLAGS.eval_real_images:
inc_score = util.get_inception_scores(
real_data, FLAGS.num_images_generated, FLAGS.num_inception_images)
else:
inc_score = util.get_inception_scores(
generated_data, FLAGS.num_images_generated, FLAGS.num_inception_images)
tf.summary.scalar('inception_score', inc_score)
# If conditional, display an image grid of difference classes.
if FLAGS.conditional_eval and not FLAGS.eval_real_images:
reshaped_imgs = util.get_image_grid(
generated_data, FLAGS.num_images_generated, num_classes,
FLAGS.num_images_per_class)
tf.summary.image('generated_data', reshaped_imgs, max_outputs=1)
# Create ops that write images to disk.
image_write_ops = None
if FLAGS.conditional_eval and FLAGS.write_to_disk:
reshaped_imgs = util.get_image_grid(
generated_data, FLAGS.num_images_generated, num_classes,
FLAGS.num_images_per_class)
uint8_images = data_provider.float_image_to_uint8(reshaped_imgs)
image_write_ops = tf.write_file(
'%s/%s'% (FLAGS.eval_dir, 'conditional_cifar10.png'),
tf.image.encode_png(uint8_images[0]))
else:
if FLAGS.num_images_generated >= 100 and FLAGS.write_to_disk:
reshaped_imgs = tfgan.eval.image_reshaper(
generated_data[:100], num_cols=FLAGS.num_images_per_class)
uint8_images = data_provider.float_image_to_uint8(reshaped_imgs)
image_write_ops = tf.write_file(
'%s/%s'% (FLAGS.eval_dir, 'unconditional_cifar10.png'),
tf.image.encode_png(uint8_images[0]))
# For unit testing, use `run_eval_loop=False`.
if not run_eval_loop: return
tf.contrib.training.evaluate_repeatedly(
FLAGS.checkpoint_dir,
master=FLAGS.master,
hooks=[tf.contrib.training.SummaryAtEndHook(FLAGS.eval_dir),
tf.contrib.training.StopAfterNEvalsHook(1)],
eval_ops=image_write_ops,
max_number_of_evaluations=FLAGS.max_number_of_evaluations)