Skip to main content

Focal Frequency Loss - Tensorflow Implementation

Maintenance notice: This package is no longer actively developed. The final release is v0.2.0 (March 2026), which fixes a bug in the ave_spectrum path (keepdim → keepdims) and updates minimum requirements to Python ≥ 3.8 and TensorFlow ≥ 2.10.0. This repository will be archived on 2026-09-30. For active development and the official implementation, use the PyTorch version.

PyPI version

teaser

This repository provides the Tensorflow implementation for the following paper:

Focal Frequency Loss for Image Reconstruction and Synthesis by Liming Jiang, Bo Dai, Wayne Wu and Chen Change Loy in ICCV 2021.

Project Page | Paper | Poster | Slides | YouTube Demo | Official PyTorch Implementation

Abstract: Image reconstruction and synthesis have witnessed remarkable progress thanks to the development of generative models. Nonetheless, gaps could still exist between the real and generated images, especially in the frequency domain. In this study, we show that narrowing gaps in the frequency domain can ameliorate image reconstruction and synthesis quality further. We propose a novel focal frequency loss, which allows a model to adaptively focus on frequency components that are hard to synthesize by down-weighting the easy ones. This objective function is complementary to existing spatial losses, offering great impedance against the loss of important frequency information due to the inherent bias of neural networks. We demonstrate the versatility and effectiveness of focal frequency loss to improve popular models, such as VAE, pix2pix, and SPADE, in both perceptual quality and quantitative performance. We further show its potential on StyleGAN2.

Quick Start

Run pip install tf-focal-frequency-loss for installation. Then, the following code is all you need.

import tensorflow as tf
from tf_focal_frequency_loss import FocalFrequencyLoss as FFL
ffl = FFL(loss_weight=1.0, alpha=1.0)  # initialize tf.keras.layers.Layer class

fake = tf.random.normal((4, 3, 64, 64))  # replace it with the predicted tensor of shape (N, C, H, W)
real = tf.random.normal((4, 3, 64, 64))  # replace it with the target tensor of shape (N, C, H, W)

loss = ffl(fake, real)  # calculate focal frequency loss

Notebook

Pix2Pix

License

All rights reserved. The code is released under the MIT License.

Metadata

Release files for tf-focal-frequency-loss 0.2.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for tf-focal-frequency-loss 0.2.0
File Size Uploaded
tf_focal_frequency_loss-0.2.0.tar.gz 5.6 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for tf-focal-frequency-loss 0.2.0
File Interpreter ABI Platform
tf_focal_frequency_loss-0.2.0-py3-none-any.whl Python 3 none any Details

Total release size: 11.1 kB

Release files / tf_focal_frequency_loss-0.2.0.tar.gz

Download URL tf_focal_frequency_loss-0.2.0.tar.gz
Size 5.6 kB
Tags Source
SHA-256 checksum
How to use checksums
4fb5a363dc0993b8955fa1b988b6224775a9aa0920e19711a3ab4c6230fbc31b
BLAKE2b-256 checksum
How to use checksums
3808f7831bc3984dc07a4f917b87fda2e45523299b613518558ace9c102f6cc5
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via python-requests/2.32.5

Release files / tf_focal_frequency_loss-0.2.0-py3-none-any.whl

Download URL tf_focal_frequency_loss-0.2.0-py3-none-any.whl
Size 5.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
9d4daea5bf9d263fae25bda477aa21274d0713b0d4ef1bab8aafdc796a466a60
BLAKE2b-256 checksum
How to use checksums
1e100b04599245ac990ecc42db957d652be16f1817fc51597a16bd22288efc44
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via python-requests/2.32.5

Release history Release notifications | RSS feed

This release

0.2.0 This release

2 release files

0.1.2

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page