Project Icon

clean-fid

准确评估生成模型的标准化指标库

clean-fid是一个用于评估生成模型的开源工具库,致力于解决FID计算中的不一致问题。通过精确处理图像重采样和压缩等细节,该库确保了不同方法、论文和团队之间FID分数的可比性。clean-fid支持计算FID和KID指标,提供多个常用数据集的预计算统计数据,操作简便。它旨在为生成模型评估提供标准化和可靠的解决方案,提高了评估结果的准确性和可重复性。

clean-fid for Evaluating Generative Models


Downloads Downloads

Project | Paper | Slides | Colab-FID | Colab-Resize | Leaderboard Tables
Quick start: Calculate FID | Calculate KID

[New] Computing the FID using CLIP features [Kynkäänniemi et al, 2022] is now supported. See here for more details.

The FID calculation involves many steps that can produce inconsistencies in the final metric. As shown below, different implementations use different low-level image quantization and resizing functions, the latter of which are often implemented incorrectly.

We provide an easy-to-use library to address the above issues and make the FID scores comparable across different methods, papers, and groups.

FID Steps


Corresponding Manuscript

On Aliased Resizing and Surprising Subtleties in GAN Evaluation
Gaurav Parmar, Richard Zhang, Jun-Yan Zhu
CVPR, 2022
CMU and Adobe

If you find this repository useful for your research, please cite the following work.

@inproceedings{parmar2021cleanfid,
  title={On Aliased Resizing and Surprising Subtleties in GAN Evaluation},
  author={Parmar, Gaurav and Zhang, Richard and Zhu, Jun-Yan},
  booktitle={CVPR},
  year={2022}
}


Aliased Resizing Operations

The definitions of resizing functions are mathematical and should never be a function of the library being used. Unfortunately, implementations differ across commonly-used libraries. They are often implemented incorrectly by popular libraries. Try out the different resizing implementations in the Google colab notebook here.


The inconsistencies among implementations can have a drastic effect of the evaluations metrics. The table below shows that FFHQ dataset images resized with bicubic implementation from other libraries (OpenCV, PyTorch, TensorFlow, OpenCV) have a large FID score (≥ 6) when compared to the same images resized with the correctly implemented PIL-bicubic filter. Other correctly implemented filters from PIL (Lanczos, bilinear, box) all result in relatively smaller FID score (≤ 0.75). Note that since TF 2.0, the new flag antialias (default: False) can produce results close to PIL. However, it was not used in the existing TF-FID repo and set as False by default.

JPEG Image Compression

Image compression can have a surprisingly large effect on FID. Images are perceptually indistinguishable from each other but have a large FID score. The FID scores under the images are calculated between all FFHQ images saved using the corresponding JPEG format and the PNG format.

Below, we study the effect of JPEG compression for StyleGAN2 models trained on the FFHQ dataset (left) and LSUN outdoor Church dataset (right). Note that LSUN dataset images were collected with JPEG compression (quality 75), whereas FFHQ images were collected as PNG. Interestingly, for LSUN dataset, the best FID score (3.48) is obtained when the generated images are compressed with JPEG quality 87.


Quick Start

  • install the library
    pip install clean-fid
    

Computing FID

  • Compute FID between two image folders
    from cleanfid import fid
    score = fid.compute_fid(fdir1, fdir2)
    
  • Compute FID between one folder of images and pre-computed datasets statistics (e.g., FFHQ)
    from cleanfid import fid
    score = fid.compute_fid(fdir1, dataset_name="FFHQ", dataset_res=1024, dataset_split="trainval70k")
    
  • Compute FID using a generative model and pre-computed dataset statistics:
    from cleanfid import fid
    # function that accepts a latent and returns an image in range[0,255]
    gen = lambda z: GAN(latent=z, ... , <other_flags>)
    score = fid.compute_fid(gen=gen, dataset_name="FFHQ",
            dataset_res=256, num_gen=50_000, dataset_split="trainval70k")
    

Computing CLIP-FID

To use the CLIP features when computing the FID [Kynkäänniemi et al, 2022], specify the flag model_name="clip_vit_b_32"

  • e.g. to compute the CLIP-FID between two folders of images use the following commands.
    from cleanfid import fid
    score = fid.compute_fid(fdir1, fdir2, mode="clean", model_name="clip_vit_b_32")
    

Computing KID

The KID score can be computed using a similar interface as FID. The dataset statistics for KID are only precomputed for smaller datasets AFHQ, BreCaHAD, and MetFaces.

  • Compute KID between two image folders
    from cleanfid import fid
    score = fid.compute_kid(fdir1, fdir2)
    
  • Compute KID between one folder of images and pre-computed datasets statistics
    from cleanfid import fid
    score = fid.compute_kid(fdir1, dataset_name="brecahad", dataset_res=512, dataset_split="train")
    
  • Compute KID using a generative model and pre-computed dataset statistics:
    from cleanfid import fid
    # function that accepts a latent and returns an image in range[0,255]
    gen = lambda z: GAN(latent=z, ... , <other_flags>)
    score = fid.compute_kid(gen=gen, dataset_name="brecahad", dataset_res=512, num_gen=50_000, dataset_split="train")
    

Supported Precomputed Datasets

We provide precompute statistics for the following commonly used configurations. Please contact us if you want to add statistics for your new datasets.

TaskDatasetResolutionReference Split# Reference Imagesmode
Image Generationcifar1032train50,000clean, legacy_tensorflow, legacy_pytorch
Image Generationcifar1032test10,000clean, legacy_tensorflow, legacy_pytorch
Image Generationffhq1024, 256trainval50,000clean, legacy_tensorflow, legacy_pytorch
Image Generationffhq1024, 256trainval70k70,000clean, legacy_tensorflow, legacy_pytorch
Image Generationlsun_church256train50,000clean, legacy_tensorflow, legacy_pytorch
Image Generationlsun_church256trainfull126,227clean
Image Generationlsun_horse256train50,000clean, legacy_tensorflow, legacy_pytorch
Image Generationlsun_horse256trainfull2,000,340clean
Image Generationlsun_cat256train50,000clean, legacy_tensorflow, legacy_pytorch
Image Generationlsun_cat256trainfull1,657,264clean, legacy_tensorflow, legacy_pytorch
Few Shot Generationafhq_cat512train5153clean, legacy_tensorflow, legacy_pytorch
Few Shot Generationafhq_dog512train4739clean, legacy_tensorflow, legacy_pytorch
Few Shot Generationafhq_wild512train4738clean, legacy_tensorflow, legacy_pytorch
Few Shot Generationbrecahad512train1944clean, legacy_tensorflow, legacy_pytorch
Few Shot Generationmetfaces1024train1336clean, legacy_tensorflow, legacy_pytorch
Image to Imagehorse2zebra256test140clean, legacy_tensorflow, legacy_pytorch
Image to Imagecat2dog256test500clean, legacy_tensorflow, legacy_pytorch

Using precomputed statistics In order to compute the FID score with the precomputed dataset statistics, use the corresponding options. For instance, to compute the clean-fid score on generated 256x256 FFHQ images use the command:

fid_score = fid.compute_fid(fdir1, dataset_name="ffhq", dataset_res=256,  mode="clean", dataset_split="trainval70k")

Create Custom Dataset Statistics

  • dataset_path: folder where the dataset images are stored

  • custom_name: name to be used for the statistics

  • Generating custom statistics (saved to local cache)

    from cleanfid import fid
    fid.make_custom_stats(custom_name, dataset_path, mode="clean")
    
  • Using the generated custom statistics

    from cleanfid import fid
    score = fid.compute_fid("folder_fake", dataset_name=custom_name,
              mode="clean", dataset_split="custom")
    
  • Removing the custom stats

    from cleanfid import fid
    fid.remove_custom_stats(custom_name, mode="clean")
    
  • Check if a custom statistic already exists

    from cleanfid import fid
    fid.test_stats_exists(custom_name, mode)
    

Backwards Compatibility

We provide two flags to reproduce the legacy FID score.

  • mode="legacy_pytorch"
    This flag is equivalent to using the popular PyTorch FID implementation provided here
    The difference between using clean-fid with this option and code is ~2e-06
    See doc for how the methods are compared

  • mode="legacy_tensorflow"
    This flag is equivalent to using the official implementation of FID released by the authors.
    The difference between using clean-fid with this option and code is ~2e-05
    See doc for detailed steps for how the methods are compared


Building clean-fid locally from source

python setup.py bdist_wheel
pip install dist/*

CleanFID Leaderboard for common tasks

We compute the FID scores using the corresponding methods used in the original papers and using the Clean-FID proposed here. All values are computed using 10 evaluation runs. We provide an API to query the results shown in the tables below directly from the pip package.

If you would like to add new numbers and models to our leaderboard, feel free to contact us.

CIFAR-10 (few shot)

The test set is used as the reference distribution and compared to 10k generated images.

100% data (unconditional)

ModelLegacy-FID
(reported)
Legacy-FID
(reproduced)
Clean-FID
stylegan2 (+ada + tuning) [Karras et al, 2020]- †- †8.20 ± 0.10
stylegan2 (+ada) [Karras et al, 2020]- †- †9.26 ± 0.06
stylegan2 (diff-augment) [Zhao et al, 2020] [ckpt]9.899.90 ± 0.0910.85 ± 0.10
stylegan2 (mirror-flips) [Karras et al, 2020] [ckpt]11.0711.07 ± 0.1012.96 ± 0.07
stylegan2 (without-flips) [Karras et al, 2020]- †- †14.53 ± 0.13
AutoGAN (config A) [Gong et al, 2019]- †- †21.18 ± 0.12
AutoGAN (config B) [[Gong et al,
项目侧边栏1项目侧边栏2
推荐项目
Project Cover

豆包MarsCode

豆包 MarsCode 是一款革命性的编程助手,通过AI技术提供代码补全、单测生成、代码解释和智能问答等功能,支持100+编程语言,与主流编辑器无缝集成,显著提升开发效率和代码质量。

Project Cover

AI写歌

Suno AI是一个革命性的AI音乐创作平台,能在短短30秒内帮助用户创作出一首完整的歌曲。无论是寻找创作灵感还是需要快速制作音乐,Suno AI都是音乐爱好者和专业人士的理想选择。

Project Cover

有言AI

有言平台提供一站式AIGC视频创作解决方案,通过智能技术简化视频制作流程。无论是企业宣传还是个人分享,有言都能帮助用户快速、轻松地制作出专业级别的视频内容。

Project Cover

Kimi

Kimi AI助手提供多语言对话支持,能够阅读和理解用户上传的文件内容,解析网页信息,并结合搜索结果为用户提供详尽的答案。无论是日常咨询还是专业问题,Kimi都能以友好、专业的方式提供帮助。

Project Cover

阿里绘蛙

绘蛙是阿里巴巴集团推出的革命性AI电商营销平台。利用尖端人工智能技术,为商家提供一键生成商品图和营销文案的服务,显著提升内容创作效率和营销效果。适用于淘宝、天猫等电商平台,让商品第一时间被种草。

Project Cover

吐司

探索Tensor.Art平台的独特AI模型,免费访问各种图像生成与AI训练工具,从Stable Diffusion等基础模型开始,轻松实现创新图像生成。体验前沿的AI技术,推动个人和企业的创新发展。

Project Cover

SubCat字幕猫

SubCat字幕猫APP是一款创新的视频播放器,它将改变您观看视频的方式!SubCat结合了先进的人工智能技术,为您提供即时视频字幕翻译,无论是本地视频还是网络流媒体,让您轻松享受各种语言的内容。

Project Cover

美间AI

美间AI创意设计平台,利用前沿AI技术,为设计师和营销人员提供一站式设计解决方案。从智能海报到3D效果图,再到文案生成,美间让创意设计更简单、更高效。

Project Cover

AIWritePaper论文写作

AIWritePaper论文写作是一站式AI论文写作辅助工具,简化了选题、文献检索至论文撰写的整个过程。通过简单设定,平台可快速生成高质量论文大纲和全文,配合图表、参考文献等一应俱全,同时提供开题报告和答辩PPT等增值服务,保障数据安全,有效提升写作效率和论文质量。

投诉举报邮箱: service@vectorlightyear.com
@2024 懂AI·鲁ICP备2024100362号-6·鲁公网安备37021002001498号