(num_samples,
                            sess,
                            dataset_name,
                            batch_size,
                            stats_file=None,
                            seed=0,
                            verbose=True,
                            log_dir='./log')
return m_real, s_real
Reads the image data and compute the FID mean and cov statistics
    for real images.

    Args:
        num_samples (int): Number of real images to compute statistics.
        sess (Session): TensorFlow session to use.
        dataset_name (str): The name of the dataset to load.
        batch_size (int): The batch size to feedforward for inference.
        stats_file (str): The statistics file to load from if there is already one.
        verbose (bool): If True, prints progress of computation.
        log_dir (str): Directory where feature statistics can be stored.

    Returns:
        ndarray: Mean features stored as np array.
        ndarray: Covariance of features stored as np array.
Reads the image data and compute the FID mean and cov statistics
    for real images.
Reads the image data and compute the FID mean and cov statistics for real images .
def compute_real_dist_stats(num_samples,
                            sess,
                            dataset_name,
                            batch_size,
                            stats_file=None,
                            seed=0,
                            verbose=True,
                            log_dir='./log'):
    """
    Reads the image data and compute the FID mean and cov statistics
    for real images.

    Args:
        num_samples (int): Number of real images to compute statistics.
        sess (Session): TensorFlow session to use.
        dataset_name (str): The name of the dataset to load.
        batch_size (int): The batch size to feedforward for inference.
        stats_file (str): The statistics file to load from if there is already one.
        verbose (bool): If True, prints progress of computation.
        log_dir (str): Directory where feature statistics can be stored.

    Returns:
        ndarray: Mean features stored as np array.
        ndarray: Covariance of features stored as np array.
    """
    # Create custom stats file name
    if stats_file is None:
        stats_dir = os.path.join(log_dir, 'metrics', 'fid', 'statistics')
        if not os.path.exists(stats_dir):
            os.makedirs(stats_dir)

        stats_file = os.path.join(
            stats_dir,
            "fid_stats_{}_{}k_run_{}.npz".format(dataset_name,
                                                 num_samples // 1000, seed))

    if stats_file and os.path.exists(stats_file):
        print("INFO: Loading existing statistics for real images...")
        f = np.load(stats_file)
        m_real, s_real = f['mu'][:], f['sigma'][:]
        f.close()

    else:
        # Obtain the numpy format data
        print("INFO: Obtaining images...")
        images = get_dataset_images(dataset_name, num_samples=num_samples)
        images = images[:, :, :, ::-1]  # NOTE: opencv image convert to RGB

        # Compute the mean and cov
        print("INFO: Computing statistics for real images...")
        m_real, s_real = fid_utils.calculate_activation_statistics(
            images=images, sess=sess, batch_size=batch_size, verbose=verbose)

        if not os.path.exists(stats_file):
            print("INFO: Saving statistics for real images...")
            np.savez(stats_file, mu=m_real, sigma=s_real)

    return m_real, s_real
def compute_real_dist_stats ( num_samples , sess , dataset_name , batch_size , stats_file = None , seed = 0 , verbose = True , log_dir = './log' ) : # Create custom stats file name if stats_file is None : stats_dir = os . path . join ( log_dir , 'metrics' , 'fid' , 'statistics' ) if not os . path . exists ( stats_dir ) : os . makedirs ( stats_dir ) stats_file = os . path . join ( stats_dir , "fid_stats_{}_{}k_run_{}.npz" . format ( dataset_name , num_samples // 1000 , seed ) ) if stats_file and os . path . exists ( stats_file ) : print ( "INFO: Loading existing statistics for real images..." ) f = np . load ( stats_file ) m_real , s_real = f [ 'mu' ] [ : ] , f [ 'sigma' ] [ : ] f . close ( ) else : # Obtain the numpy format data print ( "INFO: Obtaining images..." ) images = get_dataset_images ( dataset_name , num_samples = num_samples ) images = images [ : , : , : , : : - 1 ] # NOTE: opencv image convert to RGB # Compute the mean and cov print ( "INFO: Computing statistics for real images..." ) m_real , s_real = fid_utils . calculate_activation_statistics ( images = images , sess = sess , batch_size = batch_size , verbose = verbose ) if not os . path . exists ( stats_file ) : print ( "INFO: Saving statistics for real images..." ) np . savez ( stats_file , mu = m_real , sigma = s_real ) return m_real , s_real