Skip to main content

Frechet Audio Distance evaluation in PyTorch

Project description

fad_pytorch

Original FAD paper (PDF)

Install

pip install fad_pytorch

About

(Intended) Features:

  • runs in parallel on multiple GPUs
  • supports 48kHz sample rates and stereo when possible
  • supports CLAP embeddings, in addition to VGGish and PANN
  • favors ops in PyTorch instead of numpy
  • allows dataset access via WebDataset (over s3://)
  • runs on CPU, CUDA, or MPS

This is designed to be run as 3 command-line scripts in succession. The latter 2 (fad_embed and fad_score) are probably what most people will want:

  1. fad_gen: produces directories of real & fake audio
  2. fad_embed <real_audio_dir> <fake_audio_dir>: produces directories of embeddings of real & fake audio
  3. fad_score <real_emb_dir> <fake_emb_dir>: reads the embeddings & generates FAD score, for real (“$r$”) and fake (“$f$”):

$$ FAD = || \mu_r - \mu_f ||^2 + tr\left(\Sigma_r + \Sigma_f - 2 \sqrt{\Sigma_r \Sigma_f}\right)$$

FAQ / Troubleshooting

  • RuntimeError: CUDA error: invalid device ordinal”: This happens when you have a “bad node” on an AWS cluster. Haven’t yet figured out what causes it or how to fix it. Workaround: Just add the current node to your SLURM --exclude list, exit and retry. Note: it may take as many as 5 to 7 retries before you get a “good node”.

Contributing

This repo is still fairly “bare bones” and will benefit from more documentation and features as time goes on. Note that it is written using nbdev, so the things to are:

  1. fork this repo
  2. clone your fork to your (local) machine
  3. Install nbdev: python3 -m pip install -U nbdev
  4. Make changes by editing the notebooks in nbs/, not the .py files in fad_pytorch/.
  5. Run nbdev_export to export notebook changes to .py files
  6. For good measure, run nbdev_install_hooks and nbdev_clean - especially if you’ve added any notebooks.
  7. Do a git status to see all the .ipynb and .py files that need to be added & committed
  8. git add those files and then git commit, and then git push
  9. Take a look in your GitHub Actions tab, and see if the “test” and “deploy” CI runs finish properly (green light) or fail (red light)
  10. One you get green lights, send in a Pull Request!

Feel free to ask me for tips with nbdev, it has quite a learning curve. You can also ask on fast.ai forums and/or fast.ai Discord

Related Repos

There are [several] others, but this one is mine. These repos didn’t have all the features I wanted, but I used them for inspiration:

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

fad_pytorch-0.0.4.tar.gz (31.0 kB view details)

Uploaded Source

Built Distribution

fad_pytorch-0.0.4-py3-none-any.whl (31.6 kB view details)

Uploaded Python 3

File details

Details for the file fad_pytorch-0.0.4.tar.gz.

File metadata

  • Download URL: fad_pytorch-0.0.4.tar.gz
  • Upload date:
  • Size: 31.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.10.11

File hashes

Hashes for fad_pytorch-0.0.4.tar.gz
Algorithm Hash digest
SHA256 b7a4282b491a5c7700073a4a9f683f22d5f286d2900cb7fe6eaae33dc614dacb
MD5 7bbd4ad3249b6c3f688cf370f40af9c4
BLAKE2b-256 dddc42afe243bb0d10ce82e911bd5f538845b256edceaf6e032e31f0156b16ce

See more details on using hashes here.

File details

Details for the file fad_pytorch-0.0.4-py3-none-any.whl.

File metadata

  • Download URL: fad_pytorch-0.0.4-py3-none-any.whl
  • Upload date:
  • Size: 31.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.10.11

File hashes

Hashes for fad_pytorch-0.0.4-py3-none-any.whl
Algorithm Hash digest
SHA256 4e6e3721f8358f7bf91d7eaa7583c03855238f1ab151adb09159abc1cf9b49d6
MD5 23136fae3db800ce3756548ba285af8f
BLAKE2b-256 0106be1a267e601e0774146a6d9b4d12b2dfc6a9837b1440166b5c4a5554a058

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