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.
- License 许可
- Apache-2.0
- 最近更新
- 2026-09-03
- Stars
- ★ 351
- Forks
- 27
01 前言 Front Matter
- name
- pytorch-fid
- license
- Apache 2.0
- metadata
- { "disco-role": "operating" }
- 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
02 资源文件 10
- 参考文档references/api-reference.md6.7 KB
- 参考文档references/cli-reference.md4.3 KB
- 参考文档references/data-formats.md5.0 KB
- 参考文档references/repo-provenance.md3.0 KB
- 参考文档references/repo-routing-metadata.json335 B
- 参考文档references/troubleshooting.md7.5 KB
- 参考文档references/workflows.md5.8 KB
- 脚本scripts/check_pytorch_fid_env.py8.0 KB
- 脚本scripts/inspect_stats_npz.py7.7 KB
- 脚本scripts/validate_fid_inputs.py11.5 KB
03 SKILL.md 正文
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
- 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
- package/distribution:
- Run the safe environment probe before giving install or runtime advice:
Addpython scripts/check_pytorch_fid_env.py--jsonwhen a machine-readable report is needed. - If the task depends on the source snapshot, read
references/repo-provenance.md. - If the task is about router selection or when this skill should load, read
references/repo-routing-metadata.json. - 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
.npzstatistics file; - call the
pytorch_fid.fid_scoreAPIs from Python; - select
--dimsvalues64,192,768, or2048; - choose CPU, CUDA device strings, batch size, or DataLoader worker count;
- validate whether directories and
.npzfiles 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:
- CLI commands, flags, positional path combinations, output, and gotchas:
references/cli-reference.md - Python API signatures, return shapes, and Inception layer selection:
references/api-reference.md - Input directory and
.npzdata contract:references/data-formats.md - End-to-end operating recipes and validation-first flows:
references/workflows.md - Cross-cutting failure symptoms, causes, and recoveries:
references/troubleshooting.md - Provenance and evidence snapshot:
references/repo-provenance.md
Use bundled scripts for safe checks:
scripts/check_pytorch_fid_env.py: import, package metadata, CLI help, torch/torchvision, and optional CUDA availability.scripts/validate_fid_inputs.py: validate two FID input paths as image directories or.npzstatistics files.scripts/inspect_stats_npz.py: summarize saved statistics files and check theirmu/sigmaarrays.
Core operating workflow
- Identify the two comparison inputs. Each input can be an image directory or a
.npzfile containing saved activation statistics. If both are directories, the package computes statistics for both in the same run. - Validate inputs before constructing a model:
Omitpython scripts/validate_fid_inputs.py INPUT_A INPUT_B --expected-dims 2048--expected-dimswhen the intended feature dimension is not known yet. - Choose the feature dimension. Default is
2048; lower dimensions (64,192,768) are faster but not directly comparable to2048scores. - Choose device and batch parameters. Start with CPU or
--device cuda:0only after verifying CUDA availability; reduce--batch-sizefor memory errors. - Run via CLI for ordinary comparisons:
python -m pytorch_fid PATH_A PATH_B --dims 2048 --batch-size 50 - Precompute reusable reference statistics when one dataset is reused often:
python -m pytorch_fid --save-stats DATASET_DIR reference_stats.npz - Compare generated images against saved stats:
python -m pytorch_fid GENERATED_DIR reference_stats.npz --dims 2048 - For Python integration, prefer the public functions in
references/api-reference.mdand 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, andwebp; use lowercase suffixes for reliable source matching across platforms. - Saved stats must contain finite
muandsigmaarrays;sigmamust be a square covariance matrix whose side length matchesmulength. - 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<2to avoid ABI warnings or import failures.
Troubleshooting entry points
- Install/import, CLI discovery, torch/torchvision, NumPy ABI, or CUDA probe:
run
scripts/check_pytorch_fid_env.py, then readreferences/troubleshooting.md. - Empty or mixed input directories, missing
.npzkeys, non-finite stats, or dimension mismatches: runscripts/validate_fid_inputs.py. - Saved-statistics uncertainty: run
scripts/inspect_stats_npz.py. - Unexpected FID values: verify dimension, stats provenance, input preprocessing, package/version, and whether the comparison is being made against TensorFlow or another implementation.
04 同仓库更多 Skills
passnet-triton-opt
Make a single PassNet Triton kernel fast AND numerically faithful: performance model (when a replacement can win at all), block/grid/warp tuning, autotune policy, launch overhead, and per-op numeric recipes to pass the dtype baseline tolerances. Use when a pass matches and is correct but speedup below expected, or when correctness fails by small numeric margins.
passnet-solve
END-TO-END playbook for solving one PassNet sample: analyze the computation graphs, decide the optimization strategy (what to fuse, what to replace, what to leave alone), drive the iteration loop, and maximize the sample score. This is the ENTRY skill — invoke it first for any PassNet optimization task; it tells you when to use passnet-pattern-fusion, passnet-triton-opt and passnet-feedback.
passnet-skill
PassNet GPU kernel optimization via compiler passes. Design and implement Triton-based optimization passes, create pass files under ./pass_dir/, self-evaluate with pass_evaluator, and iterate to maximize GPU speedup.
passnet-pattern-fusion
Author PassNet pass files: write patterns that actually MATCH the FX graph, pick fusion regions (which ops to absorb into one Triton kernel), and structure multi-pass submissions with the mandatory shared-dispatch architecture. Use when creating or fixing pattern()/replacement_args()/replacement_func() files, when a pass "failed to match", or when deciding how to fuse multiple kernels/ops.
passnet-orchestrate
Round/batch planning and decision support for PassNet graph optimization. Use for multi-sample triage, worker allocation, eval-budget policy, and post-eval keep/revert decisions. For solving one concrete sample end to end, use passnet-solve as the entry skill; consult this skill only when you need broader planning or a specific decision gate.
passnet-feedback
Fast, deterministic feedback for PassNet work: pre-flight pattern/match verification WITHOUT burning a GPU evaluation, per-node bottleneck analysis of a sample's graphs, and eval-log parsing into per-variant status + estimated score + failure classification. Use BEFORE every GPU evaluation (check_pattern), at the START of a sample (analyze_graph), and AFTER every evaluation (parse_eval_log).