PyTorch FID
raw JSON → 0.3.0 verified Mon Apr 27 auth: no python
A PyTorch implementation of the Frechet Inception Distance (FID) for evaluating generative models. Version 0.3.0 is the latest stable release. The package is mature with infrequent releases.
pip install pytorch-fid Common errors
error ModuleNotFoundError: No module named 'pytorch_fid' ↓
cause Package not installed or misspelled.
fix
Run
pip install pytorch-fid and verify with pip list | grep pytorch-fid. error AttributeError: module 'pytorch_fid' has no attribute 'calculate_fid_given_paths' ↓
cause Direct import of the function from the package root is incorrect.
fix
Import via
from pytorch_fid import fid_score then call fid_score.calculate_fid_given_paths(...). error RuntimeError: CUDA out of memory. Tried to allocate ... MiB (GPU 0; ... MiB total capacity) ↓
cause Batch size too large for GPU memory.
fix
Reduce batch_size parameter (e.g., to 16 or 8) or use CPU with device='cpu'.
error ValueError: Input path ... does not exist or is not a directory ↓
cause Incorrect path to image directory.
fix
Check that both paths exist and are directories containing images.
Warnings
breaking In version 0.4.0 (unreleased), the API will change; the function `calculate_fid_given_paths` will be renamed to `compute_fid` and its argument signature will change. Check the GitHub master branch for future compatibility. ↓
fix Use the current API (0.3.0) or monitor the repo for updates.
gotcha The Inception v3 model used by pytorch-fid is not the standard torchvision one; it uses pre-trained weights from the TensorFlow implementation. If you use your own Inception model, FID scores will be inconsistent. ↓
fix Always use the bundled weights (loaded automatically) from the pytorch_fid/inception.py file.
deprecated The `dims` parameter accepts values 64, 192, 768, 2048. Using dims other than 2048 produces incomplete FID (not the true FID). This is a leftover from older experiments. ↓
fix Always use dims=2048 for standard FID.
gotcha Image directories must contain only valid image files (jpg, png). Non-image files or corrupted images cause silent failures or crashes. ↓
fix Sanitize directories to contain only supported image formats.
Imports
- calculate_fid_given_paths wrong
from pytorch_fid.fid_score import calculate_fid_given_pathscorrectfrom pytorch_fid import fid_score; fid_score.calculate_fid_given_paths(paths, batch_size, device, dims, num_workers)
Quickstart
import torch
from pytorch_fid import fid_score
paths = ['path/to/real/images', 'path/to/fake/images']
# Use GPU if available
device = torch.device('cuda' if torch.cuda.is_available() else 'cpu')
# Calculate FID
fid_value = fid_score.calculate_fid_given_paths(paths, batch_size=50, device=device, dims=2048, num_workers=8)
print('FID:', fid_value)