Beispiel #1
0
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]))

      sess = tf.Session()
      saver = tf.train.Saver()
      if not restore_from_checkpoint(sess, saver):
        raise NotImplementedError

      options = tf.RunOptions(trace_level=tf.RunOptions.FULL_TRACE)
      run_metadata = tf.RunMetadata()
      sess.run(images, options=options, run_metadata=run_metadata)
      cg = CompGraph('gan_mnist', run_metadata, tf.get_default_graph())

      cg_tensor_dict = cg.get_tensors()
      cg_sorted_keys = sorted(cg_tensor_dict.keys())
      cg_sorted_items = []
      for cg_key in cg_sorted_keys:
        cg_sorted_items.append(tf.shape(cg_tensor_dict[cg_key]))

      cg_sorted_shape = sess.run(cg_sorted_items)
      cg.op_analysis(dict(zip(cg_sorted_keys, cg_sorted_shape)),
                     'gan_mnist.pickle')

      exit(0)
    #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)
Beispiel #2
0
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:
        pass
        '''
    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
    print("**********{}".format([
        tf.contrib.training.SummaryAtEndHook(FLAGS.eval_dir),
        tf.contrib.training.StopAfterNEvalsHook(1)
    ]))
    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)
Beispiel #3
0
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)
Beispiel #4
0
def _unconditional_generator(noise, mode):
    """3D generator with extra argument for tf.Estimator's `mode`."""
    is_training = (mode == tf.estimator.ModeKeys.TRAIN)
    return networks.unconditional_generator(noise, is_training=is_training)