Skip to main content

Focal Frequency Loss for Image Reconstruction and Synthesis - Tensorflow Implementation

Project description

Focal Frequency Loss - Tensorflow Implementation

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

License

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

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

tf-focal-frequency-loss-0.1.2.tar.gz (5.2 kB view details)

Uploaded Source

Built Distribution

tf_focal_frequency_loss-0.1.2-py3-none-any.whl (5.2 kB view details)

Uploaded Python 3

File details

Details for the file tf-focal-frequency-loss-0.1.2.tar.gz.

File metadata

File hashes

Hashes for tf-focal-frequency-loss-0.1.2.tar.gz
Algorithm Hash digest
SHA256 d51a8d697bec9ebe15f41525767e9173babf1d1c92fb8dca7e4f72b6c3fd9534
MD5 4aa89267f4bfa76675a451a14373dec4
BLAKE2b-256 f2ef24db106f0cebc0a50e52410256bf96c82f8c99dd13ee2f6d89e71e103500

See more details on using hashes here.

File details

Details for the file tf_focal_frequency_loss-0.1.2-py3-none-any.whl.

File metadata

File hashes

Hashes for tf_focal_frequency_loss-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 6740d24ec67445de4fcd60d906d77605e12517df0c565640ab29655c33060584
MD5 07b2f1b553e52f4da45252ff04b4d1eb
BLAKE2b-256 0f4817e1afc63fde4b573725d64a1ca13be17b1bc48aa33e429cf548c153ab6a

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