FID JAX
Clean implementation of the Frechet Inception Distance in JAX.
- Reproduces OpenAI's TensorFlow implementation.
- Pure JAX implementation runs on CPU/GPU/TPU and inside JIT.
- Can load weights from GCS using
pathlibAPI. - Clean and simple code.
Instructions
1️⃣ FID JAX is a single file, so you can just copy it to your project directory. Or you can install the package:
pip install fidjax
2️⃣ Download the Inception weights (credits to Matthias Wright):
wget https://www.dropbox.com/s/xt6zvlvt22dcwck/inception_v3_weights_fid.pickle?dl=1
3️⃣ Download the ImageNet reference stats of the desired resolution (generate your own for other datasets):
wget https://openaipublic.blob.core.windows.net/diffusion/jul-2021/ref_batches/imagenet/64/VIRTUAL_imagenet64_labeled.npz
wget https://openaipublic.blob.core.windows.net/diffusion/jul-2021/ref_batches/imagenet/128/VIRTUAL_imagenet128_labeled.npz
wget https://openaipublic.blob.core.windows.net/diffusion/jul-2021/ref_batches/imagenet/256/VIRTUAL_imagenet256_labeled.npz
wget https://openaipublic.blob.core.windows.net/diffusion/jul-2021/ref_batches/imagenet/512/VIRTUAL_imagenet512.npz
4️⃣ Compute activations, statistics, and scores in JAX:
import fidjax
import numpy as np
weights = './inception_v3_weights_fid.pickle?dl=1'
reference = './VIRTUAL_imagenet128_labeled.npz'
fid = fidjax.FID(weights, reference)
fid_total = 50000
fid_batch = 1000
acts = []
for range(fid_total // fid_batch):
samples = ... # (B, H, W, 3) jnp.uint8
acts.append(fid.compute_acts(samples))
stats = fid.compute_stats(acts)
score = fid.compute_score(stats)
print(float(score)) # FID
Accuracy
| Dataset | Model | FID JAX | OpenAI TF |
|---|---|---|---|
| ImageNet 256 | ADM (guided, upsampled) | 3.937 | 3.943 |
Tutorials
Using Cloud Storage
Point to the files via a pathlib.Path implementation that support your
Cloud storage. For example for GCS:
import elements # pip install elements
import fidjax
weights = elements.Path('gs://bucket/fid/inception_v3_weights_fid.pickle')
reference = elements.Path('gs://bucket/fid/VIRTUAL_imagenet128_labeled.npz')
fid = fidjax.FID(weights, reference)
Custom Datasets
Generate reference statistics for custom datasets:
import fidjax
import numpy as np
weights = './inception_v3_weights_fid.pickle?dl=1'
fid = fidjax.FID(weights)
acts = fid.compute_acts(images)
mu, sigma = fid.compute_stats(acts)
np.savez('reference.npz', {'mu': mu, 'sigma': sigma})
Resources
Questions
Please file an issue on Github.
Metadata
Release files for fidjax 1.0.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| fidjax-1.0.1.tar.gz | 5.3 kB | Without provenance | Details for fidjax-1.0.1.tar.gz |
Release files / fidjax-1.0.1.tar.gz
| Download URL | fidjax-1.0.1.tar.gz |
|---|---|
| Size | 5.3 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
7772735343251fec87fdf631fc1b31a5809f6394066dd4ee513539f0cd14fced
|
|
BLAKE2b-256 checksum How to use checksums |
4789a0a21d023367d4ff321955ce9755f37936761dedf3fdf6e52a897a41aafc
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.2 CPython/3.11.8
|
Security for fidjax 1.0.1
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.