(generated_images, num_batches)
return _eval_fn
Get a fn returning the ms ssim score for generated images.

  Args:
    generated_images: TF Tensor of shape [batch_size, dim, dim, 3] which
      evaluates to a batch of generated images. Should be in range [0..255].
    num_batches: Number of batches to consider.

  Returns:
    eval_fn: a function which takes a session as an argument and returns the
      average ms ssim score among all the possible image pairs from
      generated_images.
Get a fn returning the ms ssim score for generated images.
Get a fn returning the ms ssim score for generated images .
def compute_msssim(generated_images, num_batches):
  """Get a fn returning the ms ssim score for generated images.

  Args:
    generated_images: TF Tensor of shape [batch_size, dim, dim, 3] which
      evaluates to a batch of generated images. Should be in range [0..255].
    num_batches: Number of batches to consider.

  Returns:
    eval_fn: a function which takes a session as an argument and returns the
      average ms ssim score among all the possible image pairs from
      generated_images.
  """
  batch_size = int(generated_images.get_shape()[0])
  assert batch_size > 1

  # Generate all possible image pairs from input set of imgs.
  pair1 = tf.tile(generated_images, [batch_size, 1, 1, 1])
  pair2 = tf.reshape(
      tf.tile(generated_images, [1, batch_size, 1, 1]), [
          batch_size * batch_size, generated_images.shape[1],
          generated_images.shape[2], generated_images.shape[3]
      ])

  # Compute the mean of the scores (but ignore the 'identical' images - which
  # should get 1.0 from the MultiscaleSSIM)
  score = tf.reduce_sum(image_similarity.multiscale_ssim(pair1, pair2))
  score -= batch_size
  score = tf.div(score, batch_size * batch_size - batch_size)

  # Define a function which wraps some session.run calls to generate a large
  # number of images and compute multiscale ssim metric on them.
  def _eval_fn(session):
    """Function which wraps session.run calls to compute given metric."""
    logging.info("Computing MS-SSIM score...")
    scores = []
    for _ in range(num_batches):
      scores.append(session.run(score))

    result = np.mean(scores)
    return result
  return _eval_fn
def compute_msssim ( generated_images , num_batches ) : batch_size = int ( generated_images . get_shape ( ) [ 0 ] ) assert batch_size > 1 # Generate all possible image pairs from input set of imgs. pair1 = tf . tile ( generated_images , [ batch_size , 1 , 1 , 1 ] ) pair2 = tf . reshape ( tf . tile ( generated_images , [ 1 , batch_size , 1 , 1 ] ) , [ batch_size * batch_size , generated_images . shape [ 1 ] , generated_images . shape [ 2 ] , generated_images . shape [ 3 ] ] ) # Compute the mean of the scores (but ignore the 'identical' images - which # should get 1.0 from the MultiscaleSSIM) score = tf . reduce_sum ( image_similarity . multiscale_ssim ( pair1 , pair2 ) ) score -= batch_size score = tf . div ( score , batch_size * batch_size - batch_size ) # Define a function which wraps some session.run calls to generate a large # number of images and compute multiscale ssim metric on them. def _eval_fn ( session ) : """Function which wraps session.run calls to compute given metric.""" logging . info ( "Computing MS-SSIM score..." ) scores = [ ] for _ in range ( num_batches ) : scores . append ( session . run ( score ) ) result = np . mean ( scores ) return result return _eval_fn