Skip to main content

An sklearn-style FID metric class for Jax

Project description

FIDax

A JAX implementation of the Fréchet Inception Distance (FID) metric for evaluating generative models in form of a sklearn-compatible metric.

Features

  • Pure JAX Implementation: Leverages JAX's JIT compilation for fast computation
  • Pre-computed Statistics: Supports using pre-computed real image statistics for faster evaluation
  • GPU Accelerated: Optimized for CUDA-enabled GPUs
  • Torchmetrics Compatible: Results match torchmetrics implementation up to 1e-1 absolute tolerance with FP32 execution of the InceptionV3 model and FP64 for the metric computation on CIFAR10 tests

Installation

# Clone the repository
git clone git@github.com:wittenator/fidax.git
cd fidax

# Install dependencies using uv
uv sync --frozen

or install it directly as a dependency with e.g. uv:

uv add fidax

Quick Start

import jax 
jax.config.update("jax_enable_x64", True)
import jax.numpy as jnp
from fidax.fid import FrechetInceptionDistance

# Initialize FID metric
fid = FrechetInceptionDistance(max_samples=100)

# Update with real images (shape: [N, 299, 299, 3], range: [-1, 1])
real_images = jnp.random.uniform(-1, 1, (100, 299, 299, 3))
fid.update(real_images, real=True)

# Update with generated/fake images
fake_images = jnp.random.uniform(-1, 1, (100, 299, 299, 3))
fid.update(fake_images, real=False)

# Compute FID score
fid_score = fid.compute()
print(f"FID Score: {fid_score}")

Advanced Usage

Pre-computed Statistics

# Use pre-computed real statistics for faster evaluation
real_stats = {
    "mu": mu_real,      # Mean of real activations
    "sigma": sigma_real # Covariance of real activations
}

fid = FrechetInceptionDistance(max_samples=1000, real_stats=real_stats)
# Only need to update with fake images
fid.update(fake_images, real=False)

Requirements

  • Python ≥ 3.12
  • JAX with CUDA support
  • Flax
  • NumPy

See pyproject.toml for complete dependency list.

Development

This project uses a development container with GPU support. To set up the development environment:

# The dev container will automatically install dependencies
# Run tests
uv run pytest src/fidax/test_fid_metric.py

Testing

The implementation includes tests against torchmetrics:

uv run pytest src/fidax/test_fid_metric.py -v

Tests verify:

  • Equivalence with torchmetrics implementation
  • Pre-computed statistics functionality
  • Real-world performance on CIFAR-10 dataset

License

Apache 2.0 License - see LICENSE for details.

Related Projects

  • jax-fid-parallel - Parallel implementation of FID computation in JAX
  • jax-fid - Original JAX implementation of FID that inspired this project

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

fidax-0.1.1.tar.gz (72.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

fidax-0.1.1-py3-none-any.whl (16.8 kB view details)

Uploaded Python 3

File details

Details for the file fidax-0.1.1.tar.gz.

File metadata

  • Download URL: fidax-0.1.1.tar.gz
  • Upload date:
  • Size: 72.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.8.5

File hashes

Hashes for fidax-0.1.1.tar.gz
Algorithm Hash digest
SHA256 c8d2cccc2bc240bbfc846d09a77f6c98d6c96d332723a22373e1a65f6f6364d4
MD5 fbdc08fa47680beef93f3a0ae768e93b
BLAKE2b-256 34c861d3efeb3d07172f9bfcf67f666ac747f89fee8ffe24b7eb51b7fb6313b5

See more details on using hashes here.

File details

Details for the file fidax-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: fidax-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 16.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.8.5

File hashes

Hashes for fidax-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 7089826ca961b8c0c05f20456e5825c36ff22d155cba638d748e40708ff34c15
MD5 404a457b94942874a0ba570e445fc5b2
BLAKE2b-256 b0e5065d52c3ea43279a5c46739a17cc645a6a05ca4e36c12ed7581872a9b49c

See more details on using hashes here.

Supported by

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