TensorFlow implementation of focal loss.
Project description
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), # Used here like a tf.keras loss
metrics=...,
)
history = model.fit(...)
Documentation is available at Read the Docs.
Installation
Make sure that a CPU or GPU version of TensorFlow 2.0 or later is installed (see this link for installation instructions).
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 a recent release from the Python Package Index (PyPI):
pip install focal-loss
Note. To install the project for development (e.g., to make changes to the source code), clone the project repository from GitHub and run
make dev
:git clone https://github.com/artemmavrin/focal-loss.git cd focal-loss # Optional but recommended: create a new Python virtual environment first make dev
This will additionally install the requirements needed to run tests, check code coverage, and produce documentation.
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
Built Distribution
Hashes for focal_loss-0.0.4-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3e5f6b8025ae2d959b20c8f42fcb2921ef092677ed9b85d5e4f10ba81d31d366 |
|
MD5 | 992d1ffa3cb486b8e21f24778703d372 |
|
BLAKE2b-256 | 9da17f690e28b3a9e6b338cd03ffd3328fa3d1bbe87226554ce7ed452e51d73d |