The interface is localized. Skill descriptions and documents are machine-translated by AI into your language; code, commands, paths and technical terms stay in the original, and the author's document governs.
Explore skills
Productivity · SKILL.md

pytorch-fid

pytorch-fid

Use pytorch-fid to compute Frechet Inception Distance for image directories or saved activation statistics, precompute .npz stats, validate inputs, and troubleshoot PyTorch Inception FID workflows.

Independent GitHub snapshot · Automated classification · Original documentation governs

Skill documentation

GitHub

name: pytorch-fid description: "Use pytorch-fid to compute Frechet Inception Distance for image directories or saved activation statistics, precompute .npz stats, validate inputs, and troubleshoot PyTorch Inception FID workflows." disable-model-invocation: true metadata: disco-role: operating license: Apache 2.0

pytorch-fid

Use this repo skill when a task involves pytorch-fid, the pytorch_fid Python package, Frechet Inception Distance (FID), image dataset quality comparison, GAN or diffusion sample evaluation, Inception feature dimensions, or .npz activation-statistics files produced by this package.

First checks

  1. Confirm the public package and import name:
    • package/distribution: pytorch-fid
    • import package: pytorch_fid
    • console script: pytorch-fid
    • module CLI: python -m pytorch_fid
  2. Run the safe environment probe before giving install or runtime advice:
    python scripts/check_pytorch_fid_env.py
    
    Add --json when a machine-readable report is needed.
  3. If the task depends on the source snapshot, read references/repo-provenance.md.
  4. If the task is about router selection or when this skill should load, read references/repo-routing-metadata.json.
  5. For first-run or failure diagnosis, start with references/troubleshooting.md.

Minimal import smoke:

from pytorch_fid.fid_score import calculate_fid_given_paths
from pytorch_fid.inception import InceptionV3

The import smoke must not construct InceptionV3 unless a model download/cache check is explicitly allowed. The bundled scripts avoid model construction.

When to read this skill

Read this skill when the user asks to:

  • compute FID between two image directories;
  • precompute one dataset's Inception statistics for later comparisons;
  • compare an image directory against a saved .npz statistics file;
  • call the pytorch_fid.fid_score APIs from Python;
  • select --dims values 64, 192, 768, or 2048;
  • choose CPU, CUDA device strings, batch size, or DataLoader worker count;
  • validate whether directories and .npz files are compatible before running;
  • troubleshoot unsupported image files, empty directories, CUDA/OOM, missing weights, shape mismatches, singular covariances, or non-comparable scores.

Avoid this skill when the task is only generic image preprocessing, generic PyTorch model training, TensorFlow FID code, CLIP-based image metrics, or repo maintenance unrelated to using the packaged FID workflows.

Route map

Use the bundled references instead of returning long inline explanations:

Use bundled scripts for safe checks:

Core operating workflow

  1. Identify the two comparison inputs. Each input can be an image directory or a .npz file containing saved activation statistics. If both are directories, the package computes statistics for both in the same run.
  2. Validate inputs before constructing a model:
    python scripts/validate_fid_inputs.py INPUT_A INPUT_B --expected-dims 2048
    
    Omit --expected-dims when the intended feature dimension is not known yet.
  3. Choose the feature dimension. Default is 2048; lower dimensions (64, 192, 768) are faster but not directly comparable to 2048 scores.
  4. Choose device and batch parameters. Start with CPU or --device cuda:0 only after verifying CUDA availability; reduce --batch-size for memory errors.
  5. Run via CLI for ordinary comparisons:
    python -m pytorch_fid PATH_A PATH_B --dims 2048 --batch-size 50
    
  6. Precompute reusable reference statistics when one dataset is reused often:
    python -m pytorch_fid --save-stats DATASET_DIR reference_stats.npz
    
  7. Compare generated images against saved stats:
    python -m pytorch_fid GENERATED_DIR reference_stats.npz --dims 2048
    
  8. For Python integration, prefer the public functions in references/api-reference.md and keep path, dimension, and device checks explicit in the calling code.

Important constraints

  • Supported image extensions are bmp, jpg, jpeg, pgm, png, ppm, tif, tiff, and webp; use lowercase suffixes for reliable source matching across platforms.
  • Saved stats must contain finite mu and sigma arrays; sigma must be a square covariance matrix whose side length matches mu length.
  • The first real FID run may download Inception weights unless they are already available in the PyTorch cache. Do not treat a network failure as an input validation failure.
  • Scores are comparable only when the same package/version, preprocessing, Inception weights, feature dimension, and dataset conventions are used.
  • The README warns that scores are not exactly comparable with the official TensorFlow FID implementation.
  • CPU is a valid backend for correctness checks; CUDA is optional acceleration.
  • With torch builds that are not compatible with NumPy 2, use a NumPy 1.x runtime such as numpy<2 to avoid ABI warnings or import failures.

Troubleshooting entry points

Saved skills