Skip to main content

This package provides measurement tools for Generative Adversarial Networks (GANs), including Inception Score (IS), Fréchet Inception Distance (FID), Kernel Inception Distance (KID), and Precision and Recall (PR). These metrics are used to evaluate the quality and diversity of generated images in GANs. The package streamlines the use of these metrics, making it easier to apply them to your work.

Project description

GANs evaluation metrics Pytorch version

This implementation covers all the current state-of-the-art evaluation metrics for Generative Adversarial Networks (GANs), including: Inception Score (IS), Fréchet Inception Distance (FID), Kernel Inception Distance (KID), and Precision and Recall (PR).

Although there are many existing implementations of these metrics in other repositories, they have different usage and requirements, which may cause inconvenience during the evaluation process. This package aims to simplify the usage by wrapping all the metrics into one setting.

Inception Score (IS) evaluates the reality and diversity of generated images based on the Kullback-Leibler (KL) divergence between the probability outputs of the Inception model for each fake image and the marginal distribution (the cumulative distribution of all samples). The original Tensorflow implementation can be found here.

Fréchet Inception Distance (FID) compares the Fréchet distance between two datasets by comparing the mean and covariance of the features extracted from the last average pooling layer of the Inception model. The original Tensorflow implementation can be found here.

Kernel Inception Distance (KID) compares the Maximum Mean Discrepancy (MMD) between two datasets by comparing the features extracted using the same method as FID. The original Tensorflow implementation can be found here.

Precision and Recall (PR) of GANs evaluate the quality and diversity of generated images, respectively. The method uses VGG16 as the feature extractor, and the real and fake domains are decided by k-nearest neighbor in the Euclidean space. The precision and recall values are calculated by the intersection between the two domains. The original Tensorflow implementation can be found here.

The Inception and FID models have been modified from the unofficial Pytorch FID implementation. The VGG model uses the timm package, and the implementation of IS, FID, and PR has been modified from the Pytorch StyleGAN2-ADA.

Installation

Install from pip:

pip install gans-eval

Requirements:

  • numpy
  • opencv-python
  • pillow
  • scipy
  • tqdm
  • timm
  • torch>=1.7.0
  • torchvision>=0.8.0

Usage

Except for IS, other metrics need two individual datasets to process, the simple usage:

python main.py --fake-dir path_to_syn_dataset --real-dir path_to_real_dataset --metrics is fid kid pr

All available arguments:

  • --fake-dir Synthesis dataset directory.

  • --real-dir Real dataset directory.

  • --data-name the statistic features of dataset will be save as pickle file in ['HOME']/.cache/gans_metrics/dataset_name.pkl. Default: default.

  • --save-json path to save result as json file. Default: None.

  • --metrics evaluation method. Available options is, fid, kid, pr. Default: fid.

  • --num-splits parameter to calculate IS, number of divisions to calculate statistics. This parameter together with the number of samples can cause the IS to change. Default: 10.

  • --max-real parameter to calculate KID, the maximum number of real samples. Default: 1000000.

  • --num-subsets parameter to calculate KID, the number of subsets while compute KID. Default: 100.

  • --max-subset-size parameter to calculate KID, the maximum number of sample in one subset. Default: 1000.

  • --k-nearest parameter to calculate PR, the kth nearest neighbor. Default: 3.

  • --row-batch-size parameter to calculate PR, number of samples per once Euclidean distance computing. Default: 10000.

  • --col-batch-size parameter to calculate PR, number of samples per once Euclidean distance computing. Default: 10000.

  • --dims as pytorch-fid package, there are four available positions to extract features from Inception module. Available options: 64, 192, 768, 2048. Default: 2048.

    • 64: first max pooling features.
    • 192: second max pooling features.
    • 768: pre-aux classifier features.
    • 2048: final average pooling features.
  • --batch-size Batch size. Default: 50.

  • --num-workers The number of workers use for dataloder. Default: 8.

  • --not-save-cache Store true parameter. Call it if you don't want to save dataset statistic as cache.

  • --verbose Store true parameter. Call it if you want to see the process bar while computing statistics information from the image folder.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

gans-eval-0.0.2.tar.gz (14.3 kB view details)

Uploaded Source

Built Distribution

gans_eval-0.0.2-py3-none-any.whl (14.4 kB view details)

Uploaded Python 3

File details

Details for the file gans-eval-0.0.2.tar.gz.

File metadata

  • Download URL: gans-eval-0.0.2.tar.gz
  • Upload date:
  • Size: 14.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.8.0 pkginfo/1.9.6 readme-renderer/34.0 requests/2.27.1 requests-toolbelt/0.10.1 urllib3/1.26.14 tqdm/4.64.1 importlib-metadata/4.8.3 keyring/23.4.1 rfc3986/1.5.0 colorama/0.4.5 CPython/3.6.13

File hashes

Hashes for gans-eval-0.0.2.tar.gz
Algorithm Hash digest
SHA256 4167b63ae3e9ef1fd9a9be23982b85789d7e9784187c477a3d335f0bc502211d
MD5 e3164bbe761ca4419d329710bcf9979e
BLAKE2b-256 4a66b538191cabe73ae9cd285ac09a67874446d9956dd08ad7b6a410f938cc33

See more details on using hashes here.

File details

Details for the file gans_eval-0.0.2-py3-none-any.whl.

File metadata

  • Download URL: gans_eval-0.0.2-py3-none-any.whl
  • Upload date:
  • Size: 14.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.8.0 pkginfo/1.9.6 readme-renderer/34.0 requests/2.27.1 requests-toolbelt/0.10.1 urllib3/1.26.14 tqdm/4.64.1 importlib-metadata/4.8.3 keyring/23.4.1 rfc3986/1.5.0 colorama/0.4.5 CPython/3.6.13

File hashes

Hashes for gans_eval-0.0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 4ab7be97f0725ffe5db3c823cee3b1c94441144ff2ae9ed7cfde3fecf51a9462
MD5 21910be5d3fbe14c65c5be12a1fd3504
BLAKE2b-256 2f1c4aecc1e5ef506706ed9a0ca8ceebecb9b4b34bfe0d5ee9afd66d2486c95c

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page