Giter Site home page Giter Site logo

gan-metrics-pytorch's Introduction

Metrics for Evaluating GANs (Pytorch)

The following GAN metrics are implemented:

  1. Fréchet Inception Distance (FID)
  2. Kernel Inception Distance (KID)

Usage

Requirements:

  • python3
  • pytorch
  • torchvision
  • numpy
  • scipy
  • scikit-learn
  • Pillow

To compute the FID or KID score between two datasets with features extracted from inception net:

  • Ensure that you have saved both datasets as numpy files (.npy) in channels-first format, i.e. (no. of images, channels, height, width)
python fid_score.py --true path/to/real/images.npy --fake path/to/gan/generated.npy --gpu ID
python kid_score.py --true path/to/real/images.npy --fake path/to/gan/generated.npy --gpu ID

Using different layers for feature maps

In difference to the official implementation, you can choose to use a different feature layer of the Inception network instead of the default pool3 layer. As the lower layer features still have spatial extent, the features are first global average pooled to a vector before estimating mean and covariance.

This might be useful if the datasets you want to compare have less than the otherwise required 2048 images. Note that this changes the magnitude of the FID score and you can not compare them against scores calculated on another dimensionality. The resulting scores might also no longer correlate with visual quality.

You can select the dimensionality of features to use with the flag --dims N, where N is the dimensionality of features. The choices are:

  • 64: first max pooling features
  • 192: second max pooling featurs
  • 768: pre-aux classifier features
  • 2048: final average pooling features (this is the default)

MNIST

The repo also contains a LeNet (modified from activatedgeek/LeNet-5) pretrained on MNIST which can be used for evaluating MNIST samples. Just set the model to LeNet using --model_type lenet.

python fid_score.py --true path/to/real/images.npy --fake path/to/gan/generated.npy --gpu ID --model_type lenet
python kid_score.py --true path/to/real/images.npy --fake path/to/gan/generated.npy --gpu ID --model_type lenet

This implementation is licensed under the Apache License 2.0.

FID was introduced by Martin Heusel, Hubert Ramsauer, Thomas Unterthiner, Bernhard Nessler and Sepp Hochreiter in "GANs Trained by a Two Time-Scale Update Rule Converge to a Local Nash Equilibrium", see https://arxiv.org/abs/1706.08500

The original implementation is by the Institute of Bioinformatics, JKU Linz, licensed under the Apache License 2.0. See https://github.com/bioinf-jku/TTUR.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.