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()
# 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(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
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file fidax-0.3.1.tar.gz.
File metadata
- Download URL: fidax-0.3.1.tar.gz
- Upload date:
- Size: 115.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.9.18 {"installer":{"name":"uv","version":"0.9.18","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
0bf252a897acdc27cac322d789cd7f2e89d348a8f050db57d91fa3c77aaf7eee
|
|
| MD5 |
e396084d9d28b6b274e99831f1e9b3dd
|
|
| BLAKE2b-256 |
51b7887628a9eda21837c2195fa8e586aa8937a8383e1e98f2a2ed4885119b12
|
File details
Details for the file fidax-0.3.1-py3-none-any.whl.
File metadata
- Download URL: fidax-0.3.1-py3-none-any.whl
- Upload date:
- Size: 19.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.9.18 {"installer":{"name":"uv","version":"0.9.18","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
01bd0e97ba76b7d98b06664dc14e3dfc45d983fe780dd86a100a753597cb81c4
|
|
| MD5 |
cb286ef70a8a2aeefb8c353dcddc7d9a
|
|
| BLAKE2b-256 |
1703ea3ee78eeec04f046065e8ad003178eba853ede6bb419d4ddaafddf9e188
|