def test_get_inception_scores(self, mock_inception_score): mock_inception_score.return_value = 1.0 batch_size = 100 util.get_inception_scores(tf.zeros([batch_size, 28, 28, 3], dtype=tf.float32), batch_size=batch_size, num_inception_images=10)
def evaluate(hparams, run_eval_loop=True): """Runs an evaluation loop. Args: hparams: An HParams instance containing the eval hyperparameters. run_eval_loop: Whether to run the full eval loop. Set to False for testing. """ # Fetch and generate images to run through Inception. with tf.name_scope('inputs'): real_data, _ = data_provider.provide_data('test', hparams.num_images_generated, shuffle=False) generated_data = _get_generated_data(hparams.num_images_generated) # Compute Frechet Inception Distance. if hparams.eval_frechet_inception_distance: fid = util.get_frechet_inception_distance(real_data, generated_data, hparams.num_images_generated, hparams.num_inception_images) tf.summary.scalar('frechet_inception_distance', fid) # Compute normal Inception scores. if hparams.eval_real_images: inc_score = util.get_inception_scores(real_data, hparams.num_images_generated, hparams.num_inception_images) else: inc_score = util.get_inception_scores(generated_data, hparams.num_images_generated, hparams.num_inception_images) tf.summary.scalar('inception_score', inc_score) # Create ops that write images to disk. image_write_ops = None if hparams.num_images_generated >= 100 and hparams.write_to_disk: reshaped_imgs = tfgan.eval.image_reshaper(generated_data[:100], num_cols=10) uint8_images = data_provider.float_image_to_uint8(reshaped_imgs) image_write_ops = tf.io.write_file( '%s/%s' % (hparams.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 evaluation.evaluate_repeatedly( hparams.checkpoint_dir, master=hparams.master, hooks=[ evaluation.SummaryAtEndHook(hparams.eval_dir), evaluation.StopAfterNEvalsHook(1) ], eval_ops=image_write_ops, max_number_of_evaluations=hparams.max_number_of_evaluations)