Python util.mnist_score() Examples
The following are 15
code examples of util.mnist_score().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
util
, or try the search function
.
Example #1
Source File: eval.py From yolo_v2 with Apache License 2.0 | 5 votes |
def main(_, run_eval_loop=True): # Fetch real images. with tf.name_scope('inputs'): real_images, _, _ = data_provider.provide_data( 'train', FLAGS.num_images_generated, FLAGS.dataset_dir) image_write_ops = None if FLAGS.eval_real_images: tf.summary.scalar('MNIST_Classifier_score', util.mnist_score(real_images, FLAGS.classifier_filename)) else: # In order for variables to load, use the same variable scope as in the # train job. with tf.variable_scope('Generator'): images = networks.unconditional_generator( tf.random_normal([FLAGS.num_images_generated, FLAGS.noise_dims])) tf.summary.scalar('MNIST_Frechet_distance', util.mnist_frechet_distance( real_images, images, FLAGS.classifier_filename)) tf.summary.scalar('MNIST_Classifier_score', util.mnist_score(images, FLAGS.classifier_filename)) if FLAGS.num_images_generated >= 100: reshaped_images = tfgan.eval.image_reshaper( images[:100, ...], num_cols=10) uint8_images = data_provider.float_image_to_uint8(reshaped_images) image_write_ops = tf.write_file( '%s/%s'% (FLAGS.eval_dir, 'unconditional_gan.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, 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)
Example #2
Source File: conditional_eval.py From yolo_v2 with Apache License 2.0 | 5 votes |
def main(_, run_eval_loop=True): with tf.name_scope('inputs'): noise, one_hot_labels = _get_generator_inputs( FLAGS.num_images_per_class, NUM_CLASSES, FLAGS.noise_dims) # Generate images. with tf.variable_scope('Generator'): # Same scope as in train job. images = networks.conditional_generator((noise, one_hot_labels)) # Visualize images. reshaped_img = tfgan.eval.image_reshaper( images, num_cols=FLAGS.num_images_per_class) tf.summary.image('generated_images', reshaped_img, max_outputs=1) # Calculate evaluation metrics. tf.summary.scalar('MNIST_Classifier_score', util.mnist_score(images, FLAGS.classifier_filename)) tf.summary.scalar('MNIST_Cross_entropy', util.mnist_cross_entropy( images, one_hot_labels, FLAGS.classifier_filename)) # Write images to disk. image_write_ops = tf.write_file( '%s/%s'% (FLAGS.eval_dir, 'conditional_gan.png'), tf.image.encode_png(data_provider.float_image_to_uint8(reshaped_img[0]))) # For unit testing, use `run_eval_loop=False`. if not run_eval_loop: return tf.contrib.training.evaluate_repeatedly( FLAGS.checkpoint_dir, 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)
Example #3
Source File: eval.py From Gun-Detector with Apache License 2.0 | 5 votes |
def main(_, run_eval_loop=True): # Fetch real images. with tf.name_scope('inputs'): real_images, _, _ = data_provider.provide_data( 'train', FLAGS.num_images_generated, FLAGS.dataset_dir) image_write_ops = None if FLAGS.eval_real_images: tf.summary.scalar('MNIST_Classifier_score', util.mnist_score(real_images, FLAGS.classifier_filename)) else: # In order for variables to load, use the same variable scope as in the # train job. with tf.variable_scope('Generator'): images = networks.unconditional_generator( tf.random_normal([FLAGS.num_images_generated, FLAGS.noise_dims]), is_training=False) tf.summary.scalar('MNIST_Frechet_distance', util.mnist_frechet_distance( real_images, images, FLAGS.classifier_filename)) tf.summary.scalar('MNIST_Classifier_score', util.mnist_score(images, FLAGS.classifier_filename)) if FLAGS.num_images_generated >= 100 and FLAGS.write_to_disk: reshaped_images = tfgan.eval.image_reshaper( images[:100, ...], num_cols=10) uint8_images = data_provider.float_image_to_uint8(reshaped_images) image_write_ops = tf.write_file( '%s/%s'% (FLAGS.eval_dir, 'unconditional_gan.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, 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)
Example #4
Source File: conditional_eval.py From Gun-Detector with Apache License 2.0 | 5 votes |
def main(_, run_eval_loop=True): with tf.name_scope('inputs'): noise, one_hot_labels = _get_generator_inputs( FLAGS.num_images_per_class, NUM_CLASSES, FLAGS.noise_dims) # Generate images. with tf.variable_scope('Generator'): # Same scope as in train job. images = networks.conditional_generator( (noise, one_hot_labels), is_training=False) # Visualize images. reshaped_img = tfgan.eval.image_reshaper( images, num_cols=FLAGS.num_images_per_class) tf.summary.image('generated_images', reshaped_img, max_outputs=1) # Calculate evaluation metrics. tf.summary.scalar('MNIST_Classifier_score', util.mnist_score(images, FLAGS.classifier_filename)) tf.summary.scalar('MNIST_Cross_entropy', util.mnist_cross_entropy( images, one_hot_labels, FLAGS.classifier_filename)) # Write images to disk. image_write_ops = None if FLAGS.write_to_disk: image_write_ops = tf.write_file( '%s/%s'% (FLAGS.eval_dir, 'conditional_gan.png'), tf.image.encode_png(data_provider.float_image_to_uint8( reshaped_img[0]))) # For unit testing, use `run_eval_loop=False`. if not run_eval_loop: return tf.contrib.training.evaluate_repeatedly( FLAGS.checkpoint_dir, 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)
Example #5
Source File: eval.py From object_detection_with_tensorflow with MIT License | 5 votes |
def main(_, run_eval_loop=True): # Fetch real images. with tf.name_scope('inputs'): real_images, _, _ = data_provider.provide_data( 'train', FLAGS.num_images_generated, FLAGS.dataset_dir) image_write_ops = None if FLAGS.eval_real_images: tf.summary.scalar('MNIST_Classifier_score', util.mnist_score(real_images, FLAGS.classifier_filename)) else: # In order for variables to load, use the same variable scope as in the # train job. with tf.variable_scope('Generator'): images = networks.unconditional_generator( tf.random_normal([FLAGS.num_images_generated, FLAGS.noise_dims])) tf.summary.scalar('MNIST_Frechet_distance', util.mnist_frechet_distance( real_images, images, FLAGS.classifier_filename)) tf.summary.scalar('MNIST_Classifier_score', util.mnist_score(images, FLAGS.classifier_filename)) if FLAGS.num_images_generated >= 100: reshaped_images = tfgan.eval.image_reshaper( images[:100, ...], num_cols=10) uint8_images = data_provider.float_image_to_uint8(reshaped_images) image_write_ops = tf.write_file( '%s/%s'% (FLAGS.eval_dir, 'unconditional_gan.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, 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)
Example #6
Source File: conditional_eval.py From object_detection_with_tensorflow with MIT License | 5 votes |
def main(_, run_eval_loop=True): with tf.name_scope('inputs'): noise, one_hot_labels = _get_generator_inputs( FLAGS.num_images_per_class, NUM_CLASSES, FLAGS.noise_dims) # Generate images. with tf.variable_scope('Generator'): # Same scope as in train job. images = networks.conditional_generator((noise, one_hot_labels)) # Visualize images. reshaped_img = tfgan.eval.image_reshaper( images, num_cols=FLAGS.num_images_per_class) tf.summary.image('generated_images', reshaped_img, max_outputs=1) # Calculate evaluation metrics. tf.summary.scalar('MNIST_Classifier_score', util.mnist_score(images, FLAGS.classifier_filename)) tf.summary.scalar('MNIST_Cross_entropy', util.mnist_cross_entropy( images, one_hot_labels, FLAGS.classifier_filename)) # Write images to disk. image_write_ops = tf.write_file( '%s/%s'% (FLAGS.eval_dir, 'conditional_gan.png'), tf.image.encode_png(data_provider.float_image_to_uint8(reshaped_img[0]))) # For unit testing, use `run_eval_loop=False`. if not run_eval_loop: return tf.contrib.training.evaluate_repeatedly( FLAGS.checkpoint_dir, 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)
Example #7
Source File: eval.py From g-tensorflow-models with Apache License 2.0 | 5 votes |
def main(_, run_eval_loop=True): # Fetch real images. with tf.name_scope('inputs'): real_images, _, _ = data_provider.provide_data( 'train', FLAGS.num_images_generated, FLAGS.dataset_dir) image_write_ops = None if FLAGS.eval_real_images: tf.summary.scalar('MNIST_Classifier_score', util.mnist_score(real_images, FLAGS.classifier_filename)) else: # In order for variables to load, use the same variable scope as in the # train job. with tf.variable_scope('Generator'): images = networks.unconditional_generator( tf.random_normal([FLAGS.num_images_generated, FLAGS.noise_dims]), is_training=False) tf.summary.scalar('MNIST_Frechet_distance', util.mnist_frechet_distance( real_images, images, FLAGS.classifier_filename)) tf.summary.scalar('MNIST_Classifier_score', util.mnist_score(images, FLAGS.classifier_filename)) if FLAGS.num_images_generated >= 100 and FLAGS.write_to_disk: reshaped_images = tfgan.eval.image_reshaper( images[:100, ...], num_cols=10) uint8_images = data_provider.float_image_to_uint8(reshaped_images) image_write_ops = tf.write_file( '%s/%s'% (FLAGS.eval_dir, 'unconditional_gan.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, 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)
Example #8
Source File: conditional_eval.py From g-tensorflow-models with Apache License 2.0 | 5 votes |
def main(_, run_eval_loop=True): with tf.name_scope('inputs'): noise, one_hot_labels = _get_generator_inputs( FLAGS.num_images_per_class, NUM_CLASSES, FLAGS.noise_dims) # Generate images. with tf.variable_scope('Generator'): # Same scope as in train job. images = networks.conditional_generator( (noise, one_hot_labels), is_training=False) # Visualize images. reshaped_img = tfgan.eval.image_reshaper( images, num_cols=FLAGS.num_images_per_class) tf.summary.image('generated_images', reshaped_img, max_outputs=1) # Calculate evaluation metrics. tf.summary.scalar('MNIST_Classifier_score', util.mnist_score(images, FLAGS.classifier_filename)) tf.summary.scalar('MNIST_Cross_entropy', util.mnist_cross_entropy( images, one_hot_labels, FLAGS.classifier_filename)) # Write images to disk. image_write_ops = None if FLAGS.write_to_disk: image_write_ops = tf.write_file( '%s/%s'% (FLAGS.eval_dir, 'conditional_gan.png'), tf.image.encode_png(data_provider.float_image_to_uint8( reshaped_img[0]))) # For unit testing, use `run_eval_loop=False`. if not run_eval_loop: return tf.contrib.training.evaluate_repeatedly( FLAGS.checkpoint_dir, 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)
Example #9
Source File: eval.py From multilabel-image-classification-tensorflow with MIT License | 5 votes |
def main(_, run_eval_loop=True): # Fetch real images. with tf.name_scope('inputs'): real_images, _, _ = data_provider.provide_data( 'train', FLAGS.num_images_generated, FLAGS.dataset_dir) image_write_ops = None if FLAGS.eval_real_images: tf.summary.scalar('MNIST_Classifier_score', util.mnist_score(real_images, FLAGS.classifier_filename)) else: # In order for variables to load, use the same variable scope as in the # train job. with tf.variable_scope('Generator'): images = networks.unconditional_generator( tf.random_normal([FLAGS.num_images_generated, FLAGS.noise_dims]), is_training=False) tf.summary.scalar('MNIST_Frechet_distance', util.mnist_frechet_distance( real_images, images, FLAGS.classifier_filename)) tf.summary.scalar('MNIST_Classifier_score', util.mnist_score(images, FLAGS.classifier_filename)) if FLAGS.num_images_generated >= 100 and FLAGS.write_to_disk: reshaped_images = tfgan.eval.image_reshaper( images[:100, ...], num_cols=10) uint8_images = data_provider.float_image_to_uint8(reshaped_images) image_write_ops = tf.write_file( '%s/%s'% (FLAGS.eval_dir, 'unconditional_gan.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, 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)
Example #10
Source File: conditional_eval.py From multilabel-image-classification-tensorflow with MIT License | 5 votes |
def main(_, run_eval_loop=True): with tf.name_scope('inputs'): noise, one_hot_labels = _get_generator_inputs( FLAGS.num_images_per_class, NUM_CLASSES, FLAGS.noise_dims) # Generate images. with tf.variable_scope('Generator'): # Same scope as in train job. images = networks.conditional_generator( (noise, one_hot_labels), is_training=False) # Visualize images. reshaped_img = tfgan.eval.image_reshaper( images, num_cols=FLAGS.num_images_per_class) tf.summary.image('generated_images', reshaped_img, max_outputs=1) # Calculate evaluation metrics. tf.summary.scalar('MNIST_Classifier_score', util.mnist_score(images, FLAGS.classifier_filename)) tf.summary.scalar('MNIST_Cross_entropy', util.mnist_cross_entropy( images, one_hot_labels, FLAGS.classifier_filename)) # Write images to disk. image_write_ops = None if FLAGS.write_to_disk: image_write_ops = tf.write_file( '%s/%s'% (FLAGS.eval_dir, 'conditional_gan.png'), tf.image.encode_png(data_provider.float_image_to_uint8( reshaped_img[0]))) # For unit testing, use `run_eval_loop=False`. if not run_eval_loop: return tf.contrib.training.evaluate_repeatedly( FLAGS.checkpoint_dir, 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)
Example #11
Source File: infogan_eval.py From yolo_v2 with Apache License 2.0 | 4 votes |
def main(_, run_eval_loop=True): with tf.name_scope('inputs'): noise_args = (FLAGS.noise_samples, CAT_SAMPLE_POINTS, CONT_SAMPLE_POINTS, FLAGS.unstructured_noise_dims, FLAGS.continuous_noise_dims) # Use fixed noise vectors to illustrate the effect of each dimension. display_noise1 = util.get_eval_noise_categorical(*noise_args) display_noise2 = util.get_eval_noise_continuous_dim1(*noise_args) display_noise3 = util.get_eval_noise_continuous_dim2(*noise_args) _validate_noises([display_noise1, display_noise2, display_noise3]) # Visualize the effect of each structured noise dimension on the generated # image. generator_fn = lambda x: networks.infogan_generator(x, len(CAT_SAMPLE_POINTS)) with tf.variable_scope('Generator') as genscope: # Same scope as in training. categorical_images = generator_fn(display_noise1) reshaped_categorical_img = tfgan.eval.image_reshaper( categorical_images, num_cols=len(CAT_SAMPLE_POINTS)) tf.summary.image('categorical', reshaped_categorical_img, max_outputs=1) with tf.variable_scope(genscope, reuse=True): continuous1_images = generator_fn(display_noise2) reshaped_continuous1_img = tfgan.eval.image_reshaper( continuous1_images, num_cols=len(CONT_SAMPLE_POINTS)) tf.summary.image('continuous1', reshaped_continuous1_img, max_outputs=1) with tf.variable_scope(genscope, reuse=True): continuous2_images = generator_fn(display_noise3) reshaped_continuous2_img = tfgan.eval.image_reshaper( continuous2_images, num_cols=len(CONT_SAMPLE_POINTS)) tf.summary.image('continuous2', reshaped_continuous2_img, max_outputs=1) # Evaluate image quality. all_images = tf.concat( [categorical_images, continuous1_images, continuous2_images], 0) tf.summary.scalar('MNIST_Classifier_score', util.mnist_score(all_images, FLAGS.classifier_filename)) # Write images to disk. image_write_ops = [] image_write_ops.append(_get_write_image_ops( FLAGS.eval_dir, 'categorical_infogan.png', reshaped_categorical_img[0])) image_write_ops.append(_get_write_image_ops( FLAGS.eval_dir, 'continuous1_infogan.png', reshaped_continuous1_img[0])) image_write_ops.append(_get_write_image_ops( FLAGS.eval_dir, 'continuous2_infogan.png', reshaped_continuous2_img[0])) # For unit testing, use `run_eval_loop=False`. if not run_eval_loop: return tf.contrib.training.evaluate_repeatedly( FLAGS.checkpoint_dir, 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)
Example #12
Source File: infogan_eval.py From Gun-Detector with Apache License 2.0 | 4 votes |
def main(_, run_eval_loop=True): with tf.name_scope('inputs'): noise_args = (FLAGS.noise_samples, CAT_SAMPLE_POINTS, CONT_SAMPLE_POINTS, FLAGS.unstructured_noise_dims, FLAGS.continuous_noise_dims) # Use fixed noise vectors to illustrate the effect of each dimension. display_noise1 = util.get_eval_noise_categorical(*noise_args) display_noise2 = util.get_eval_noise_continuous_dim1(*noise_args) display_noise3 = util.get_eval_noise_continuous_dim2(*noise_args) _validate_noises([display_noise1, display_noise2, display_noise3]) # Visualize the effect of each structured noise dimension on the generated # image. def generator_fn(inputs): return networks.infogan_generator( inputs, len(CAT_SAMPLE_POINTS), is_training=False) with tf.variable_scope('Generator') as genscope: # Same scope as in training. categorical_images = generator_fn(display_noise1) reshaped_categorical_img = tfgan.eval.image_reshaper( categorical_images, num_cols=len(CAT_SAMPLE_POINTS)) tf.summary.image('categorical', reshaped_categorical_img, max_outputs=1) with tf.variable_scope(genscope, reuse=True): continuous1_images = generator_fn(display_noise2) reshaped_continuous1_img = tfgan.eval.image_reshaper( continuous1_images, num_cols=len(CONT_SAMPLE_POINTS)) tf.summary.image('continuous1', reshaped_continuous1_img, max_outputs=1) with tf.variable_scope(genscope, reuse=True): continuous2_images = generator_fn(display_noise3) reshaped_continuous2_img = tfgan.eval.image_reshaper( continuous2_images, num_cols=len(CONT_SAMPLE_POINTS)) tf.summary.image('continuous2', reshaped_continuous2_img, max_outputs=1) # Evaluate image quality. all_images = tf.concat( [categorical_images, continuous1_images, continuous2_images], 0) tf.summary.scalar('MNIST_Classifier_score', util.mnist_score(all_images, FLAGS.classifier_filename)) # Write images to disk. image_write_ops = [] if FLAGS.write_to_disk: image_write_ops.append(_get_write_image_ops( FLAGS.eval_dir, 'categorical_infogan.png', reshaped_categorical_img[0])) image_write_ops.append(_get_write_image_ops( FLAGS.eval_dir, 'continuous1_infogan.png', reshaped_continuous1_img[0])) image_write_ops.append(_get_write_image_ops( FLAGS.eval_dir, 'continuous2_infogan.png', reshaped_continuous2_img[0])) # For unit testing, use `run_eval_loop=False`. if not run_eval_loop: return tf.contrib.training.evaluate_repeatedly( FLAGS.checkpoint_dir, 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)
Example #13
Source File: infogan_eval.py From object_detection_with_tensorflow with MIT License | 4 votes |
def main(_, run_eval_loop=True): with tf.name_scope('inputs'): noise_args = (FLAGS.noise_samples, CAT_SAMPLE_POINTS, CONT_SAMPLE_POINTS, FLAGS.unstructured_noise_dims, FLAGS.continuous_noise_dims) # Use fixed noise vectors to illustrate the effect of each dimension. display_noise1 = util.get_eval_noise_categorical(*noise_args) display_noise2 = util.get_eval_noise_continuous_dim1(*noise_args) display_noise3 = util.get_eval_noise_continuous_dim2(*noise_args) _validate_noises([display_noise1, display_noise2, display_noise3]) # Visualize the effect of each structured noise dimension on the generated # image. generator_fn = lambda x: networks.infogan_generator(x, len(CAT_SAMPLE_POINTS)) with tf.variable_scope('Generator') as genscope: # Same scope as in training. categorical_images = generator_fn(display_noise1) reshaped_categorical_img = tfgan.eval.image_reshaper( categorical_images, num_cols=len(CAT_SAMPLE_POINTS)) tf.summary.image('categorical', reshaped_categorical_img, max_outputs=1) with tf.variable_scope(genscope, reuse=True): continuous1_images = generator_fn(display_noise2) reshaped_continuous1_img = tfgan.eval.image_reshaper( continuous1_images, num_cols=len(CONT_SAMPLE_POINTS)) tf.summary.image('continuous1', reshaped_continuous1_img, max_outputs=1) with tf.variable_scope(genscope, reuse=True): continuous2_images = generator_fn(display_noise3) reshaped_continuous2_img = tfgan.eval.image_reshaper( continuous2_images, num_cols=len(CONT_SAMPLE_POINTS)) tf.summary.image('continuous2', reshaped_continuous2_img, max_outputs=1) # Evaluate image quality. all_images = tf.concat( [categorical_images, continuous1_images, continuous2_images], 0) tf.summary.scalar('MNIST_Classifier_score', util.mnist_score(all_images, FLAGS.classifier_filename)) # Write images to disk. image_write_ops = [] image_write_ops.append(_get_write_image_ops( FLAGS.eval_dir, 'categorical_infogan.png', reshaped_categorical_img[0])) image_write_ops.append(_get_write_image_ops( FLAGS.eval_dir, 'continuous1_infogan.png', reshaped_continuous1_img[0])) image_write_ops.append(_get_write_image_ops( FLAGS.eval_dir, 'continuous2_infogan.png', reshaped_continuous2_img[0])) # For unit testing, use `run_eval_loop=False`. if not run_eval_loop: return tf.contrib.training.evaluate_repeatedly( FLAGS.checkpoint_dir, 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)
Example #14
Source File: infogan_eval.py From g-tensorflow-models with Apache License 2.0 | 4 votes |
def main(_, run_eval_loop=True): with tf.name_scope('inputs'): noise_args = (FLAGS.noise_samples, CAT_SAMPLE_POINTS, CONT_SAMPLE_POINTS, FLAGS.unstructured_noise_dims, FLAGS.continuous_noise_dims) # Use fixed noise vectors to illustrate the effect of each dimension. display_noise1 = util.get_eval_noise_categorical(*noise_args) display_noise2 = util.get_eval_noise_continuous_dim1(*noise_args) display_noise3 = util.get_eval_noise_continuous_dim2(*noise_args) _validate_noises([display_noise1, display_noise2, display_noise3]) # Visualize the effect of each structured noise dimension on the generated # image. def generator_fn(inputs): return networks.infogan_generator( inputs, len(CAT_SAMPLE_POINTS), is_training=False) with tf.variable_scope('Generator') as genscope: # Same scope as in training. categorical_images = generator_fn(display_noise1) reshaped_categorical_img = tfgan.eval.image_reshaper( categorical_images, num_cols=len(CAT_SAMPLE_POINTS)) tf.summary.image('categorical', reshaped_categorical_img, max_outputs=1) with tf.variable_scope(genscope, reuse=True): continuous1_images = generator_fn(display_noise2) reshaped_continuous1_img = tfgan.eval.image_reshaper( continuous1_images, num_cols=len(CONT_SAMPLE_POINTS)) tf.summary.image('continuous1', reshaped_continuous1_img, max_outputs=1) with tf.variable_scope(genscope, reuse=True): continuous2_images = generator_fn(display_noise3) reshaped_continuous2_img = tfgan.eval.image_reshaper( continuous2_images, num_cols=len(CONT_SAMPLE_POINTS)) tf.summary.image('continuous2', reshaped_continuous2_img, max_outputs=1) # Evaluate image quality. all_images = tf.concat( [categorical_images, continuous1_images, continuous2_images], 0) tf.summary.scalar('MNIST_Classifier_score', util.mnist_score(all_images, FLAGS.classifier_filename)) # Write images to disk. image_write_ops = [] if FLAGS.write_to_disk: image_write_ops.append(_get_write_image_ops( FLAGS.eval_dir, 'categorical_infogan.png', reshaped_categorical_img[0])) image_write_ops.append(_get_write_image_ops( FLAGS.eval_dir, 'continuous1_infogan.png', reshaped_continuous1_img[0])) image_write_ops.append(_get_write_image_ops( FLAGS.eval_dir, 'continuous2_infogan.png', reshaped_continuous2_img[0])) # For unit testing, use `run_eval_loop=False`. if not run_eval_loop: return tf.contrib.training.evaluate_repeatedly( FLAGS.checkpoint_dir, 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)
Example #15
Source File: infogan_eval.py From multilabel-image-classification-tensorflow with MIT License | 4 votes |
def main(_, run_eval_loop=True): with tf.name_scope('inputs'): noise_args = (FLAGS.noise_samples, CAT_SAMPLE_POINTS, CONT_SAMPLE_POINTS, FLAGS.unstructured_noise_dims, FLAGS.continuous_noise_dims) # Use fixed noise vectors to illustrate the effect of each dimension. display_noise1 = util.get_eval_noise_categorical(*noise_args) display_noise2 = util.get_eval_noise_continuous_dim1(*noise_args) display_noise3 = util.get_eval_noise_continuous_dim2(*noise_args) _validate_noises([display_noise1, display_noise2, display_noise3]) # Visualize the effect of each structured noise dimension on the generated # image. def generator_fn(inputs): return networks.infogan_generator( inputs, len(CAT_SAMPLE_POINTS), is_training=False) with tf.variable_scope('Generator') as genscope: # Same scope as in training. categorical_images = generator_fn(display_noise1) reshaped_categorical_img = tfgan.eval.image_reshaper( categorical_images, num_cols=len(CAT_SAMPLE_POINTS)) tf.summary.image('categorical', reshaped_categorical_img, max_outputs=1) with tf.variable_scope(genscope, reuse=True): continuous1_images = generator_fn(display_noise2) reshaped_continuous1_img = tfgan.eval.image_reshaper( continuous1_images, num_cols=len(CONT_SAMPLE_POINTS)) tf.summary.image('continuous1', reshaped_continuous1_img, max_outputs=1) with tf.variable_scope(genscope, reuse=True): continuous2_images = generator_fn(display_noise3) reshaped_continuous2_img = tfgan.eval.image_reshaper( continuous2_images, num_cols=len(CONT_SAMPLE_POINTS)) tf.summary.image('continuous2', reshaped_continuous2_img, max_outputs=1) # Evaluate image quality. all_images = tf.concat( [categorical_images, continuous1_images, continuous2_images], 0) tf.summary.scalar('MNIST_Classifier_score', util.mnist_score(all_images, FLAGS.classifier_filename)) # Write images to disk. image_write_ops = [] if FLAGS.write_to_disk: image_write_ops.append(_get_write_image_ops( FLAGS.eval_dir, 'categorical_infogan.png', reshaped_categorical_img[0])) image_write_ops.append(_get_write_image_ops( FLAGS.eval_dir, 'continuous1_infogan.png', reshaped_continuous1_img[0])) image_write_ops.append(_get_write_image_ops( FLAGS.eval_dir, 'continuous2_infogan.png', reshaped_continuous2_img[0])) # For unit testing, use `run_eval_loop=False`. if not run_eval_loop: return tf.contrib.training.evaluate_repeatedly( FLAGS.checkpoint_dir, 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)