### Install clean-fid Library Source: https://github.com/gaparmar/clean-fid/blob/main/README.md Install the clean-fid library using pip. This is the first step to using the library for FID calculations. ```bash pip install clean-fid ``` -------------------------------- ### Install Clean-FID Locally Source: https://github.com/gaparmar/clean-fid/blob/main/docs/build.md These commands uninstall any existing version of Clean-FID and then install the locally built wheel file. This ensures you are testing the latest local changes. ```bash pip uninstall clean-fid pip install dist/clean_fid-0.1.35-py3-none-any.whl ``` -------------------------------- ### Compile Clean-FID to a Wheel File Source: https://github.com/gaparmar/clean-fid/blob/main/docs/build.md Use this command to build a wheel distribution of the Clean-FID package locally. This is a prerequisite for local installation and testing. ```bash python setup.py bdist_wheel ``` -------------------------------- ### Install Dependencies and Compute FID using TensorFlow-legacy-FID Source: https://github.com/gaparmar/clean-fid/blob/main/docs/tensorflow_fid.md Install TensorFlow 1.14 and imageio, clone the TTUR repository, and run the fid.py script to compute FID scores using the legacy TensorFlow implementation. This method is sensitive to the TensorFlow version. ```bash pip install tensorflow-gpu==1.14 pip install imageio cd test && git clone https://github.com/bioinf-jku/TTUR python fid.py test_fake/ test_real/ ``` -------------------------------- ### Push Clean-FID to PyPI Source: https://github.com/gaparmar/clean-fid/blob/main/docs/build.md This command uploads the built wheel file to the Python Package Index (PyPI), making it available for public installation. Ensure you have the necessary credentials and have built the wheel file first. ```bash python -m twine upload dist/clean_fid-0.1.35-py3-none-any.whl ``` -------------------------------- ### Compute FID using PyTorch-FID (legacy) Source: https://github.com/gaparmar/clean-fid/blob/main/docs/pytorch_fid.md Calculates the FID score using the legacy PyTorch-FID implementation. Requires installation of 'pytorch-fid' and specifies device and batch size. ```bash pip install pytorch-fid python -m pytorch_fid docs/test_fake/ docs/test_real/ \ --device "cuda" --batch-size 128 ``` -------------------------------- ### Compute FID using CleanFID (legacy PyTorch mode) Source: https://github.com/gaparmar/clean-fid/blob/main/docs/pytorch_fid.md Calculates the FID score using CleanFID with the 'legacy_pytorch' mode. Ensure 'cleanfid' is installed. ```python from cleanfid import fid score = fid.compare_folders("test_fake/", "test_real/", mode="legacy_pytorch") ``` -------------------------------- ### Compute FID using CleanFID (legacy TensorFlow mode) Source: https://github.com/gaparmar/clean-fid/blob/main/docs/tensorflow_fid.md Compute the FID score using CleanFID by specifying the 'legacy_tensorflow' mode. This method requires the 'cleanfid' library to be installed. ```python from cleanfid import fid score = fid.compare_folders("test_fake/", "test_real/", mode="legacy_tensorflow") ``` -------------------------------- ### Build Clean-FID Locally Source: https://github.com/gaparmar/clean-fid/blob/main/README.md Instructions to build the clean-fid package locally from source using setup.py. ```bash python setup.py bdist_wheel pip install dist/* ``` -------------------------------- ### Download Sample Images Source: https://github.com/gaparmar/clean-fid/blob/main/docs/tensorflow_fid.md Use wget to download a zipped file containing sample images generated by a StyleGAN2 model and randomly sampled from the FFHQ dataset. ```bash wget .zip ``` -------------------------------- ### Generate FFHQ Statistics (1024x1024, Sampled) Source: https://github.com/gaparmar/clean-fid/blob/main/docs/datasets.md Generates statistics for a randomly sampled 50k subset of the FFHQ dataset at 1024x1024 resolution. ```bash python scripts/process_dataset_folder.py \ --input_folder ~/datasets/FFHQ/images1024x1024/ \ --num_images 50000 --seed 0 --mode legacy_tensorflow \ --output_file stats/ffhq_legacy_tensorflow_trainval_1024.npz \ python scripts/process_dataset_folder.py \ --input_folder ~/datasets/FFHQ/images1024x1024/ \ --num_images 50000 --seed 0 --mode clean \ --output_file stats/ffhq_clean_trainval_1024.npz ``` -------------------------------- ### Generate FFHQ Statistics (1024x1024, Full Dataset) Source: https://github.com/gaparmar/clean-fid/blob/main/docs/datasets.md Generates statistics for the full 70k FFHQ dataset at 1024x1024 resolution using legacy TensorFlow and clean modes. ```bash python scripts/process_dataset_folder.py \ --input_folder ~/datasets/FFHQ/images1024x1024/ \ --output_file stats/ffhq_legacy_tensorflow_trainval70k_1024.npz \ --mode legacy_tensorflow python scripts/process_dataset_folder.py \ --input_folder ~/datasets/FFHQ/images1024x1024/ \ --output_file stats/ffhq_clean_trainval70k_1024.npz \ --mode clean ``` -------------------------------- ### Compute KID Using Pre-computed Dataset Statistics Source: https://github.com/gaparmar/clean-fid/blob/main/README.md Calculate KID by comparing a folder of images against pre-computed statistics for smaller datasets like AFHQ, BreCaHAD, or MetFaces. ```python from cleanfid import fid score = fid.compute_kid(fdir1, dataset_name="brecahad", dataset_res=512, dataset_split="train") ``` -------------------------------- ### Generate FFHQ Statistics (256x256) Source: https://github.com/gaparmar/clean-fid/blob/main/docs/datasets.md Generates statistics for the FFHQ dataset at 256x256 resolution using tfrecord files and legacy TensorFlow/clean modes. ```bash python scripts/process_dataset_folder.py \ --input_folder ~/datasets/FFHQ/images256_tfdir/ \ --output_file stats/ffhq_legacy_tensorflow_trainval70k_256.npz \ --mode legacy_tensorflow python scripts/process_dataset_folder.py \ --input_folder ~/datasets/FFHQ/images256_tfdir/ \ --output_file stats/ffhq_clean_trainval70k_256.npz \ --mode clean ``` -------------------------------- ### Process LSUN-cat Dataset for Statistics Source: https://github.com/gaparmar/clean-fid/blob/main/docs/datasets.md Transforms LSUN-cat lmdb files into a folder of images, then generates statistics for a sampled subset. ```bash python dataset_tool.py --source=~/datasets/lsun/lmdb/cat \ --dest= lsuncat200k.zip --transform=center-crop \ --width=256 --height=256 --max_images=200000 python scripts/process_dataset_folder.py \ --input_folder ~/cleanfid_images/LSUN_CAT/lsuncat200k \ --num_images 50000 --seed 0 --mode legacy_tensorflow \ --output_file stats/lsuncat_legacy_tensorflow_train_256.npz python scripts/process_dataset_folder.py \ --input_folder ~/cleanfid_images/LSUN_CAT/lsuncat200k \ --num_images 50000 --seed 2 --mode legacy_tensorflow \ --output_file stats/lsuncat_legacy_tensorflow_train2_256.npz ``` -------------------------------- ### Generate Custom Dataset Statistics Source: https://github.com/gaparmar/clean-fid/blob/main/README.md Create custom statistics for a dataset stored in a local folder. The generated statistics are saved to a local cache. Specify a custom name for the statistics and the path to the dataset images. ```python from cleanfid import fid fid.make_custom_stats(custom_name, dataset_path, mode="clean") ``` -------------------------------- ### Compute FID Using Pre-computed Dataset Statistics Source: https://github.com/gaparmar/clean-fid/blob/main/README.md Calculate FID by comparing a folder of images against pre-computed statistics for a known dataset like FFHQ. ```python from cleanfid import fid score = fid.compute_fid(fdir1, dataset_name="FFHQ", dataset_res=1024, dataset_split="trainval70k") ``` -------------------------------- ### Compute KID Between Two Image Folders Source: https://github.com/gaparmar/clean-fid/blob/main/README.md Use this snippet to calculate the KID score by comparing two directories containing images. ```python from cleanfid import fid score = fid.compute_kid(fdir1, fdir2) ``` -------------------------------- ### Compute CLIP-FID Between Two Image Folders Source: https://github.com/gaparmar/clean-fid/blob/main/README.md Calculate CLIP-FID by comparing two directories of images using CLIP features. Specify `model_name='clip_vit_b_32'` for CLIP features. ```python from cleanfid import fid score = fid.compute_fid(fdir1, fdir2, mode="clean", model_name="clip_vit_b_32") ``` -------------------------------- ### Compute FID Score with Precomputed Statistics Source: https://github.com/gaparmar/clean-fid/blob/main/README.md Use this command to compute the FID score on generated images using precomputed statistics for a specified dataset. Ensure the dataset name, resolution, mode, and split match the precomputed statistics. ```bash fid_score = fid.compute_fid(fdir1, dataset_name="ffhq", dataset_res=256, mode="clean", dataset_split="trainval70k") ``` -------------------------------- ### Compute FID Between Two Image Folders Source: https://github.com/gaparmar/clean-fid/blob/main/README.md Use this snippet to calculate the FID score by comparing two directories containing images. ```python from cleanfid import fid score = fid.compute_fid(fdir1, fdir2) ``` -------------------------------- ### Check for Existing Custom Statistics Source: https://github.com/gaparmar/clean-fid/blob/main/README.md Verify if custom statistics for a given name and mode already exist in the local cache. This function returns a boolean value. ```python from cleanfid import fid fid.test_stats_exists(custom_name, mode) ``` -------------------------------- ### Generate Cifar-10 Statistics Source: https://github.com/gaparmar/clean-fid/blob/main/docs/datasets.md Generates statistics for Cifar-10 train and test splits using legacy TensorFlow and clean modes. ```bash python scripts/process_dataset_folder.py \ --input_folder ~/datasets/cifar10_train_images \ --mode legacy_tensorflow \ --output_file stats/cifar10_legacy_tensorflow_train_32.npz python scripts/process_dataset_folder.py \ --input_folder ~/datasets/cifar10_train_images \ --mode clean \ --output_file stats/cifar10_clean_train_32.npz python scripts/process_dataset_folder.py \ --input_folder ~/datasets/cifar10_test_images \ --mode legacy_tensorflow \ --output_file stats/cifar10_legacy_tensorflow_test_32.npz python scripts/process_dataset_folder.py \ --input_folder ~/datasets/cifar10_test_images \ --mode clean \ --output_file stats/cifar10_clean_test_32.npz ``` -------------------------------- ### Compute KID Using a Generative Model Source: https://github.com/gaparmar/clean-fid/blob/main/README.md Compute KID by comparing images generated by a model against pre-computed dataset statistics. The generator function should accept a latent vector and return an image in the range [0, 255]. ```python from cleanfid import fid # function that accepts a latent and returns an image in range[0,255] gen = lambda z: GAN(latent=z, ... , ) score = fid.compute_kid(gen=gen, dataset_name="brecahad", dataset_res=512, num_gen=50_000, dataset_split="train") ``` -------------------------------- ### Compute FID Score with Custom Statistics Source: https://github.com/gaparmar/clean-fid/blob/main/README.md Calculate the FID score using custom-generated statistics. Provide the path to the generated images, the custom dataset name, and the mode. The dataset split should be set to 'custom'. ```python from cleanfid import fid score = fid.compute_fid("folder_fake", dataset_name=custom_name, mode="clean", dataset_split="custom") ``` -------------------------------- ### Compute FID Using a Generative Model Source: https://github.com/gaparmar/clean-fid/blob/main/README.md Compute FID by comparing images generated by a model against pre-computed dataset statistics. The generator function should accept a latent vector and return an image in the range [0, 255]. ```python from cleanfid import fid # function that accepts a latent and returns an image in range[0,255] gen = lambda z: GAN(latent=z, ... , ) score = fid.compute_fid(gen=gen, dataset_name="FFHQ", dataset_res=256, num_gen=50_000, dataset_split="trainval70k") ``` -------------------------------- ### Remove Custom Dataset Statistics Source: https://github.com/gaparmar/clean-fid/blob/main/README.md Delete custom dataset statistics from the local cache. Provide the custom name and the mode for the statistics to be removed. ```python from cleanfid import fid fid.remove_custom_stats(custom_name, mode="clean") ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.