← all repositories
EndlessSora/focal-frequency-loss

Fixing generative models by nagging them in frequency space

A drop-in PyTorch loss that penalizes image generators for missing hard-to-synthesize frequencies, showing gains on VAEs, pix2pix, SPADE, and StyleGAN2.

focal-frequency-loss
Not currently ranked — collecting fresh signals.
star history

What it does Neural networks have an inherent bias toward certain frequencies, which means generated images often lose fine spectral detail even when spatial losses look happy. Focal Frequency Loss (FFL) steps into the frequency domain via FFT, compares the amplitude spectra of real and fake images, and applies a dynamic weighting scheme that down-weights easy frequencies and hounds the model on the hard ones. It is designed to complement standard spatial losses rather than replace them.

The interesting bit The loss is embarrassingly simple to bolt on—initialize FocalFrequencyLoss and add it to your existing pipeline—but it claims to improve everything from vanilla autoencoders to StyleGAN2 by treating frequency gaps as a first-class citizen. The authors also provide a full evaluation suite and a Vanilla AE example on CelebA so you can watch the spectra converge.

Key highlights

  • Drop-in nn.Module that runs on torch>=1.1.0 with a few tunable knobs (loss_weight, alpha, patch_factor, etc.)
  • Demonstrated on VAE, pix2pix, SPADE, and StyleGAN2 (256×256 and 1024×1024)
  • Includes evaluation metrics (LPIPS, FID) and training/testing scripts for the Vanilla AE example
  • MIT licensed with an unofficial TensorFlow port floating around

Caveats

  • The paper’s experiments were locked to torch<=1.7.1,>=1.1.0, so behavior on newer PyTorch releases is officially untested.
  • Only the Vanilla AE example includes full training and testing scripts; other models are represented by result images rather than turnkey code.

Verdict Worth a look if you train image generators and suspect your outputs are missing textural crispness that pixel-level losses cannot catch. Skip it if you are not working in the image domain or already have a frequency-aware training pipeline.

Frequently asked

What is EndlessSora/focal-frequency-loss?
A drop-in PyTorch loss that penalizes image generators for missing hard-to-synthesize frequencies, showing gains on VAEs, pix2pix, SPADE, and StyleGAN2.
Is focal-frequency-loss open source?
Yes — EndlessSora/focal-frequency-loss is open source, released under the MIT license.
What language is focal-frequency-loss written in?
EndlessSora/focal-frequency-loss is primarily written in Python.
How popular is focal-frequency-loss?
EndlessSora/focal-frequency-loss has 710 stars on GitHub.
Where can I find focal-frequency-loss?
EndlessSora/focal-frequency-loss is on GitHub at https://github.com/EndlessSora/focal-frequency-loss.

heatdrop uses Google Analytics to see which pages get read — nothing else. Your call. How we handle data.