English | ็ฎไฝไธญๆ
Compute LPIPS, FID, ArtFID, and CFSD for image style transfer. Provide content images, style references, and stylized outputs, then run the Python entry points to evaluate them.
evaluate.pycomputes all four metrics.eval_lpips.py,eval_fid.py,eval_artfid.py, andeval_cfsd.pycompute individual metrics.- Images in a sample can use different file formats.
- Input images can have different resolutions and rectangular shapes. The default evaluation size is 512ร512; use
--size Nto change it, for example--size 256or--size 1024. - Supports CPU and NVIDIA CUDA. CPU is used automatically when CUDA is unavailable.
Required packages: torch, torchvision, numpy, scipy, Pillow, lpips, and tqdm.
python -m pip install -r requirements.txtDownload the weights from Google Drive and place the required .pth files in the project's weights/ directory. Keep the original filenames.
| Filename | Required for | Approx. size | Download |
|---|---|---|---|
alexnet-owt-7be5be79.pth |
LPIPS, ArtFID | 244 MB | Google Drive |
lpips_alex_v0.1.pth |
LPIPS, ArtFID | 6 KB | Google Drive |
art_inception.pth |
FID, ArtFID | 108 MB | Google Drive |
vgg19-dcbb9e9d.pth |
CFSD | 575 MB | Google Drive |
Computing all four metrics requires these four files, totaling approximately 927 MB. For a single metric, download only its listed weights. ArtFID reuses the LPIPS and FID weights.
weights/
โโโ alexnet-owt-7be5be79.pth
โโโ lpips_alex_v0.1.pth
โโโ art_inception.pth
โโโ vgg19-dcbb9e9d.pth
Use --weights-dir /path/to/weights to select another directory. Evaluation automatically checks the local files and reports missing or corrupted weights.
Each subdirectory in data/ represents one sample with three images:
| Filename stem | Meaning |
|---|---|
c |
Content image |
s |
Style reference |
cs |
Stylized output |
For example:
data/
โโโ 001/
โ โโโ c.jpg
โ โโโ s.jpg
โ โโโ cs.jpg
โโโ 002/
โ โโโ c.png
โ โโโ s.png
โ โโโ cs.jpg
โโโ 003/
โโโ 004/
โโโ 005/
โโโ 006/
Directories 003โ006 also contain c.jpg, s.jpg, and cs.jpg. You can choose your own directory names. The program reads immediate subdirectories in name order. Extra files and hidden entries are ignored, but every non-hidden subdirectory must contain a complete sample.
Extensions may differ, and filenames are case-insensitive. For example, c.jpeg, s.webp, and cs.PNG form a valid sample. Images are paired by their filename stems, not by file order.
Having both c.jpg and c.png in one sample produces an ambiguity error. Missing images also produce an error; samples are not silently skipped.
The six bundled samples, 001โ006, are 512ร512 images with StyTRยฒ outputs as cs. They demonstrate the layout and evaluation workflow. Place your own outputs in the same structure and use a fixed test set for formal evaluation.
| Sample | Content c | Style s | StyTRยฒ output cs |
|---|---|---|---|
| 001 | ![]() |
![]() |
![]() |
| 002 | ![]() |
![]() |
![]() |
| 003 | ![]() |
![]() |
![]() |
| 004 | ![]() |
![]() |
![]() |
| 005 | ![]() |
![]() |
![]() |
| 006 | ![]() |
![]() |
![]() |
Run these commands from the project root.
Check image pairing and decoding without loading weights:
python evaluate.py --data-dir ./data --check-dataCompute all four metrics:
python evaluate.py --data-dir ./data --output ./results/allCompute individual metrics:
python eval_lpips.py --data-dir ./data --output ./results/lpips
python eval_fid.py --data-dir ./data --output ./results/fid
python eval_artfid.py --data-dir ./data --output ./results/artfid
python eval_cfsd.py --data-dir ./data --output ./results/cfsdeval_artfid.py also reports LPIPS and FID because ArtFID depends on them. The combined entry point reuses these results. All entry points use the same image loading, weights, and metric definitions.
Choose the device and data/weight locations:
python evaluate.py --data-dir /path/to/my_data --weights-dir /path/to/weights --device cuda:0 --output ./results/my_model
python evaluate.py --data-dir ./data --device cpu --output ./results/cpu_democuda:0 is the first NVIDIA GPU visible to the process, respecting CUDA_VISIBLE_DEVICES. The program does not automatically select an idle GPU.
Running python evaluate.py without arguments uses the project's data/ and weights/ directories and creates a timestamped results directory. An explicitly specified output directory must not already exist. For another run, choose a new directory or omit --output.
| Option | Default | Description |
|---|---|---|
--data-dir |
Project data directory | Parent directory of the sample folders |
--weights-dir |
Project weights directory | Location of the weight files |
--output |
Timestamped directory | Location for this run's results |
--device |
auto | Uses cuda:0 when available, otherwise CPU; can be set explicitly |
--preprocess |
fixed | fixed or styleid |
--size |
512 | Square side length N for fixed preprocessing; evaluates at NรN |
--batch-size |
4 | Batch size for FID feature extraction |
--cfsd-chunk-size |
256 | CFSD rows per chunk; use 64/128 to reduce memory use |
--fid-style-pool |
paired | paired counts one reference per sample; unique deduplicates style files by SHA-256 |
--cpu-threads |
4 | Number of PyTorch CPU threads |
--save-features |
Off | Save FID features for further inspection |
--check-data |
Off | Check the data without computing metrics |
Lower is better for all four metrics.
| Metric | Definition |
|---|---|
| LPIPS | Compares cs with c using AlexNet and LPIPS v0.1 calibration weights, then averages over images |
| FID | Compares the distributions of all cs images and style references s using 2048-dimensional Art-Inception features |
| ArtFID | (1 + mean LPIPS) ร (1 + FID), using statistics from the evaluation set |
| CFSD | Compares cs with c following StyleID: VGG19 features[11] and KL divergence from the content patch-relation distribution to the stylized distribution |
FID here uses the art-domain Art-Inception weights, rather than the weights used by standard ImageNet/Inception FID implementations. ArtFID uses finite-sample FID, not ArtFID-infinity. Before comparing published scores, match the feature network, weights, preprocessing, and evaluation samples.
FID aggregates features across the selected evaluation set and computes one score; it does not average per-batch FID scores. FID/ArtFID require at least two samples, with at least two style references after deduplication in unique mode. This is only a computational minimum and does not imply a reliable estimate.
Input images do not need to be 512ร512 or square. Sizes such as 256ร256, 768ร1024, and 1024ร1024 are supported, and resolutions can vary within the input set. Style references s can differ in size from content images c; each content image and its stylized output cs should depict the same scene and crop.
- Default
--preprocess fixed: Apply EXIF orientation, convert to RGB, then resize proportionally and center-crop to NรN, as specified by--size N. The default is 512ร512, even for larger input images. Rectangular inputs may lose their outer edges through cropping. Original files are unchanged. - Custom evaluation sizes: Use
--size 256,--size 768, or--size 1024, for example. N must be an integer: Nโฅ75 when computing FID/ArtFID or all metrics, and Nโฅ32 for LPIPS or CFSD alone.--sizeaccepts one side length, not a width-height pair such as768x1024. --preprocess styleid: LPIPS/FID resize the shorter edge to 512 while preserving the aspect ratio. CFSD uses the original dimensions, with both axes at least 32 pixels. Leave--sizeat its default of 512 in this mode. LPIPS requires matching processed dimensions forcandcs; CFSD requires matching original dimensions after orientation correction. This mode does not evaluate every metric at the original resolution.
Evaluate all four metrics at 256ร256:
python evaluate.py --data-dir ./data --size 256 --output ./results/size256Evaluate CFSD at the original image dimensions, including rectangular sizes:
python eval_cfsd.py --data-dir ./data --preprocess styleid --output ./results/cfsd_nativeLarger sizes require more memory and compute, especially for CFSD. Lower --cfsd-chunk-size to reduce memory used by its chunked computation. The largest supported input also depends on the decoder and available memory. Use the same preprocessing and evaluation sizes when comparing methods.
CFSD sums over all patch rows for each image, then averages over images. CFSD_per_patch is an additional diagnostic value. Changing the resolution changes the scale of the main CFSD score. Chunking controls memory use without sampling patches or changing the formula.
Files are decoded by their contents with Pillow; there is no hard-coded extension whitelist. Common formats include JPEG/JPG, PNG, BMP, TIFF, WebP, GIF, and PPM. Support depends on the installed Pillow version and decoder plugins.
- Grayscale images are converted to RGB; transparent images are composited onto white.
- Only frame 0 is used for animated GIFs and multi-page TIFFs.
- Install
pillow-heiffor HEIC/HEIF support; it is registered automatically when available. - Undecodable, corrupted, or truncated files produce an error.
- High-bit-depth or floating-point HDR modes I, I;16, and F must first be converted to 8-bit RGB using an explicit conversion rule. RAW and SVG files may need another decoder or prior conversion.
Accepting arbitrary extensions does not mean that every encoding is supported. All preprocessing happens in memory; source images are unchanged.
Each successful run creates:
results/run_name/
โโโ summary.json # Overall scores, evaluation settings, and elapsed time
โโโ per_image.csv # Per-image LPIPS / CFSD, depending on the selected metrics
--save-features also saves fid_features.npz. FID has no per-image score, so a FID-only CSV contains pairing information. Failed runs exit with a nonzero status and, if the output directory has already been created, write failed.json instead of a success report.
Compare methods using the same data, evaluation settings, and weights. Hardware and numerical libraries may cause differences in the scores.
styleeval/
โโโ evaluate.py # Combined entry point and shared evaluation flow
โโโ eval_lpips.py # LPIPS implementation and entry point
โโโ eval_fid.py # FID implementation and entry point
โโโ eval_artfid.py # ArtFID implementation and entry point
โโโ eval_cfsd.py # CFSD implementation and entry point
โโโ common.py # Pairing, image loading, and weight checks
โโโ art_inception.py # Art-Inception network architecture
โโโ requirements.txt
โโโ README.md # English documentation
โโโ README_zh.md # Chinese documentation
โโโ LICENSE
โโโ data/
โโโ weights/
Common issues:
- torch/torchvision not found: Install dependencies with the same Python interpreter used to run evaluation, using
python -m pip. - Missing weights or checksum mismatch: Download the files from Google Drive above, keep their original filenames, and check
--weights-dir. - CUDA unavailable: Use
--device cpuor install a compatible CUDA build of PyTorch. - Out of memory: Reduce
--batch-size, then--cfsd-chunk-size. Changing the evaluation size also changes the scores. - Pairing errors: Keep exactly one
c, ones, and onecsimage in each sample directory. Pairing is based on names, not file order.
The implementations follow LPIPS, ArtFID, and StyleID. Cite the relevant original papers when using these metrics in research.
This project's own code is released under the MIT license; see LICENSE. Upstream code, weights, and images retain their respective terms.

















