|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"""Inception Score (IS) from the paper "Improved techniques for training |
|
GANs". Matches the original implementation by Salimans et al. at |
|
https://github.com/openai/improved-gan/blob/master/inception_score/model.py""" |
|
|
|
import numpy as np |
|
from . import metric_utils |
|
|
|
|
|
|
|
def compute_is(opts, num_gen, num_splits): |
|
|
|
detector_url = 'https://nvlabs-fi-cdn.nvidia.com/stylegan2-ada-pytorch/pretrained/metrics/inception-2015-12-05.pt' |
|
detector_kwargs = dict(no_output_bias=True) |
|
|
|
gen_probs = metric_utils.compute_feature_stats_for_generator( |
|
opts=opts, detector_url=detector_url, detector_kwargs=detector_kwargs, |
|
capture_all=True, max_items=num_gen).get_all() |
|
|
|
if opts.rank != 0: |
|
return float('nan'), float('nan') |
|
|
|
scores = [] |
|
for i in range(num_splits): |
|
part = gen_probs[i * num_gen // num_splits : (i + 1) * num_gen // num_splits] |
|
kl = part * (np.log(part) - np.log(np.mean(part, axis=0, keepdims=True))) |
|
kl = np.mean(np.sum(kl, axis=1)) |
|
scores.append(np.exp(kl)) |
|
return float(np.mean(scores)), float(np.std(scores)) |
|
|
|
|
|
|