Skip to main content

Compute frecet wavelet distances

Project description

Lokesh Veeramacheneni1, Moritz Wolter1, Hilde Kuehne1,2, and Juergen Gall1

1. University of Bonn,
2. University of Tübingen, MIT-IBM Watson AI Lab.

[Archive] [Project Page]

Workflow License CodeStyle

Keywords: Frechet Distance, Wavelet Packet Transform, Frechet Inception Distance, Diffusion, GAN, ImageNet, Image generation metrics.

Abstract: Modern metrics for generative learning like Fréchet Inception Distance (FID) demonstrate impressive performance. However, they suffer from various shortcomings, like a bias towards specific generators and datasets. To address this problem, we propose the Fréchet Wavelet Distance (FWD) as a domain-agnostic metric based on Wavelet Packet Transform (\(W_p\)). FWD provides a sight across a broad spectrum of frequencies in images with a high resolution, along with preserving both spatial and textural aspects. Specifically, we use \(W_p\) to project generated and dataset images to packet coefficient space. Further, we compute Fréchet distance with the resultant coefficients to evaluate the quality of a generator. This metric is general-purpose and dataset-domain agnostic, as it does not rely on any pre-trained network while being more interpretable because of frequency band transparency. We conclude with an extensive evaluation of a wide variety of generators across various datasets that the proposed FWD is able to generalize and improve robustness to domain shift and various corruptions compared to other metrics.

Alternative text

Installation

Clone the repository using

git clone git@github.com:Uni-Bonn-Attention-Research/frechet_wavelet_distance.git
cd ./frechet_wavelet_distance
pip install .

Requirements

All the requirements are specified in requirements.txt file.

Usage

python -m fwd <path to dataset> <path to generated images>

Here are the other arguments and defaults used.

python -m fwd --help

usage: fwd.py [-h] [--batch-size BATCH_SIZE] [--num-processes NUM_PROCESSES] [--save-packets] [--wavelet WAVELET] [--max_level MAX_LEVEL] [--log_scale] path path

positional arguments:
  path                  Path to the generated images or path to .npz statistics file.

options:
  -h, --help            show this help message and exit
  --batch-size          Batch size for wavelet packet transform. (default: 128)
  --num-processes       Number of multiprocess. (default: None)
  --save-packets        Save the packets as npz file. (default: False)
  --wavelet             Choice of wavelet. (default: sym5)
  --max_level           wavelet decomposition level (default: 4)
  --log_scale           Use log scaling for wavelets. (default: False)

We conduct all the experiments with Haar wavelet with transformation/decomposition level of 4 for 256x256 image. In future, we plan to release the jax-version of this code.

Citation

If you use this work, please cite using following bibtex entry

@misc{veeramacheneni2024fwd,
   title={Fr\'echet Wavelet Distance: A Domain-Agnostic Metric for Image Generation},
   author={Lokesh Veeramacheneni and Moritz Wolter and Hildegard Kuehne and Juergen Gall},
   year={2024},
   eprint={2312.15289},
   archivePrefix={arXiv},
   primaryClass={cs.CV},
   url={https://arxiv.org/abs/2312.15289},
}

Acknowledgments

The code is built with inspiration from Pytorch-FID. We use PyTorch Wavelet Toolbox for Wavelet Packet Transform implementation. We recommend to have a look at these repositories.

Testing

The tests folder contains tests to conduct independent verification of FWD. Github workflow executes all these tests. To run tests on your local system install nox, as well as this package via pip install ., and run

nox -s test

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pytorchfwd-0.0.3.tar.gz (19.2 kB view details)

Uploaded Source

Built Distribution

pytorchfwd-0.0.3-py3-none-any.whl (14.1 kB view details)

Uploaded Python 3

File details

Details for the file pytorchfwd-0.0.3.tar.gz.

File metadata

  • Download URL: pytorchfwd-0.0.3.tar.gz
  • Upload date:
  • Size: 19.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.10.12

File hashes

Hashes for pytorchfwd-0.0.3.tar.gz
Algorithm Hash digest
SHA256 2419950c1973636056579df5f0c356f0c2cf1e90957553ccda05e96ecdbb92a7
MD5 6e9cf930931689fe90f4189214f4ee4a
BLAKE2b-256 103666c5d4deba86d342b21bb39847e5eaa5e00f8cd7aac97aebc31c28deb170

See more details on using hashes here.

File details

Details for the file pytorchfwd-0.0.3-py3-none-any.whl.

File metadata

  • Download URL: pytorchfwd-0.0.3-py3-none-any.whl
  • Upload date:
  • Size: 14.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.10.12

File hashes

Hashes for pytorchfwd-0.0.3-py3-none-any.whl
Algorithm Hash digest
SHA256 45b5a6f55a3365575dfab743e4297b226d225342a9c763eaf5f1463e2b706237
MD5 25b336894eda7206366d9d2307c86fa4
BLAKE2b-256 1e85c4c1c57664a22ff5ed32ad58834dffb3b8be76b2138149f43c734082d1cb

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page