-
Notifications
You must be signed in to change notification settings - Fork 62
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Tensorflow Implementation of Focal Frequency Loss #8
Comments
Thank you so much for the nice TensorFlow implementation! Have you tested the code and its performance compared with this official repo? |
I have tested the code for sure. The Tensorflow version gives an exact numerical answer as the Pytorch version. Code for test attached below: from focal_frequency_loss import FocalFrequencyLoss as FFL
from tf_focal_frequency_loss import FocalFrequencyLoss as TFFL
# Pytorch
import torch
ffl = FFL(loss_weight=1.0, alpha=1.0) # initialize nn.Module class
fake = torch.randn(4, 3, 64, 64)
real = torch.randn(4, 3, 64, 64)
pt_loss = ffl(fake, real) # calculate focal frequency loss
# Tensorflow
import tensorflow as tf
tffl = TFFL(loss_weight=1.0, alpha=1.0) # initialize tf.keras.layers.Layer class
fake = tf.convert_to_tensor(fake.numpy(), tf.float32)
real = tf.convert_to_tensor(real.numpy(), tf.float32)
tf_loss = tffl(fake, real) # calculate focal frequency loss
# Check
import numpy as np
assert np.isclose(pt_loss.numpy(), tf_loss.numpy()) , "Results don't match" I have trained a Pix2Pix model using this tensorflow implementation and it does give better results (compared to training without it), but I haven't recreated the official repo results to compare its performance. |
Thanks a lot for the nice support. I have already mentioned this unofficial TensorFlow implementation in our README. |
Thanks a lot for the support. |
As I couldn't find a tensorflow implementation of Focal Frequency Loss, so I created it.
Please visit the Github Repo and PyPi Project.
Use case notebook is included in the Repo. Any feedback is appreciated.
@EndlessSora If you find this implementation useful, kindly do mention it on your README.
Thanks for releasing this.
The text was updated successfully, but these errors were encountered: