(num_subsets,
              subset_size,
              netG,
              device,
              seed,
              dataset_name,
              batch_size=50,
              verbose=True,
              feat_file=None,
              log_dir='./log')
Computes KID score.

    Args:
        num_subsets (int): Number of subsets to compute average MMD.
        subset_size (int): Size of subset for computing MMD.
        netG (Module): Torch Module object representing the generator model.
        device (str): Device identifier to use for computation.
        seed (int): The random seed to use.
        dataset_name (str): The name of the dataset to load.
        batch_size (int): The batch size to feedforward for inference.
        feat_file (str): The path to specific inception features for real images.
        log_dir (str): Directory where features can be stored.
        verbose (bool): If True, prints progress.

    Returns:
        tuple: Scalar mean and std of KID scores computed.
Computes KID score.
Computes KID score .
def kid_score(num_subsets,
              subset_size,
              netG,
              device,
              seed,
              dataset_name,
              batch_size=50,
              verbose=True,
              feat_file=None,
              log_dir='./log'):
    """
    Computes KID score.

    Args:
        num_subsets (int): Number of subsets to compute average MMD.
        subset_size (int): Size of subset for computing MMD.
        netG (Module): Torch Module object representing the generator model.
        device (str): Device identifier to use for computation.
        seed (int): The random seed to use.
        dataset_name (str): The name of the dataset to load.
        batch_size (int): The batch size to feedforward for inference.
        feat_file (str): The path to specific inception features for real images.
        log_dir (str): Directory where features can be stored.
        verbose (bool): If True, prints progress.

    Returns:
        tuple: Scalar mean and std of KID scores computed.
    """
    start_time = time.time()

    # Make sure the random seeds are fixed
    random.seed(seed)
    np.random.seed(seed)

    # Directories
    inception_path = os.path.join(log_dir, 'metrics', 'inception_model')

    # Setup the inception graph
    inception_utils.create_inception_graph(inception_path)

    # Decide sample size
    num_samples = int(num_subsets * subset_size)

    # Start producing features for real and fake images
    if device is not None:
        # Avoid unbounded memory usage
        gpu_options = tf.compat.v1.GPUOptions(allow_growth=True,
                                    per_process_gpu_memory_fraction=0.15,
                                    visible_device_list=str(device))
        config = tf.compat.v1.ConfigProto(gpu_options=gpu_options)

    else:
        config = tf.compat.v1.ConfigProto(device_count={'GPU': 0})

    with tf.compat.v1.Session(config=config) as sess:
        sess.run(tf.compat.v1.global_variables_initializer())

        real_feat = compute_real_dist_feat(num_samples=num_samples,
                                           sess=sess,
                                           dataset_name=dataset_name,
                                           batch_size=batch_size,
                                           verbose=verbose,
                                           feat_file=feat_file,
                                           log_dir=log_dir,
                                           seed=seed)

        fake_feat = compute_gen_dist_feat(netG=netG,
                                          num_samples=num_samples,
                                          sess=sess,
                                          device=device,
                                          seed=seed,
                                          batch_size=batch_size,
                                          verbose=verbose)

        # Compute the KID score
        scores = kid_utils.polynomial_mmd_averages(real_feat,
                                                   fake_feat,
                                                   n_subsets=num_subsets,
                                                   subset_size=subset_size)

        mmd_score, mmd_std = float(np.mean(scores)), float(np.std(scores))

        print("INFO: KID: {:.4f} ± {:.4f} [Time Taken: {:.4f} secs]".format(
            mmd_score, mmd_std,
            time.time() - start_time))

        return mmd_score, mmd_std
def kid_score ( num_subsets , subset_size , netG , device , seed , dataset_name , batch_size = 50 , verbose = True , feat_file = None , log_dir = './log' ) : start_time = time . time ( ) # Make sure the random seeds are fixed random . seed ( seed ) np . random . seed ( seed ) # Directories inception_path = os . path . join ( log_dir , 'metrics' , 'inception_model' ) # Setup the inception graph inception_utils . create_inception_graph ( inception_path ) # Decide sample size num_samples = int ( num_subsets * subset_size ) # Start producing features for real and fake images if device is not None : # Avoid unbounded memory usage gpu_options = tf . compat . v1 . GPUOptions ( allow_growth = True , per_process_gpu_memory_fraction = 0.15 , visible_device_list = str ( device ) ) config = tf . compat . v1 . ConfigProto ( gpu_options = gpu_options ) else : config = tf . compat . v1 . ConfigProto ( device_count = { 'GPU' : 0 } ) with tf . compat . v1 . Session ( config = config ) as sess : sess . run ( tf . compat . v1 . global_variables_initializer ( ) ) real_feat = compute_real_dist_feat ( num_samples = num_samples , sess = sess , dataset_name = dataset_name , batch_size = batch_size , verbose = verbose , feat_file = feat_file , log_dir = log_dir , seed = seed ) fake_feat = compute_gen_dist_feat ( netG = netG , num_samples = num_samples , sess = sess , device = device , seed = seed , batch_size = batch_size , verbose = verbose ) # Compute the KID score scores = kid_utils . polynomial_mmd_averages ( real_feat , fake_feat , n_subsets = num_subsets , subset_size = subset_size ) mmd_score , mmd_std = float ( np . mean ( scores ) ) , float ( np . std ( scores ) ) print ( "INFO: KID: {:.4f} ± {:.4f} [Time Taken: {:.4f} secs]". f ormat( mmd_score , mmd_std , time . time ( ) - start_time ) ) return mmd_score , mmd_std