Skip to main content

TensorFlow implementation of focal loss.

Project description

Python Version PyPI Package Version Build Status Code Coverage Documentation Status License

TensorFlow implementation of focal loss [1]: a loss function generalizing binary cross-entropy loss that penalizes hard-to-classify examples.

The focal_loss package provides a function binary_focal_loss and a class BinaryFocalLoss that can be used as stand-in replacements for tf.keras.losses functions and classes, respectively.

# Typical tf.keras API usage
import tensorflow as tf
from focal_loss import BinaryFocalLoss

model = tf.keras.Model(...)
model.compile(
    optimizer=...,
    loss=BinaryFocalLoss(gamma=2)
    metrics=...,
)
history = model.fit(...)
Focal loss plot

Installation

  1. Make sure that a CPU or GPU version of TensorFlow 2.0 or later is installed (see this link for installation instructions).

  2. The focal_loss package can be installed using the pip utility. For the latest version, install directly from the package’s GitHub page:

    pip install git+https://github.com/artemmavrin/focal-loss.git

    Alternatively, install the a recent release from the Python Package Index (PyPI):

    pip install focal-loss

References

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

focal-loss-0.0.1.tar.gz (11.1 kB view hashes)

Uploaded Source

Built Distribution

focal_loss-0.0.1-py3-none-any.whl (14.1 kB view hashes)

Uploaded Python 3

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