Focal Loss
TensorFlow implementation of focal loss [1]: a loss function generalizing binary and multiclass cross-entropy loss that penalizes hard-to-classify examples.
The focal_loss package provides functions and classes that can be used as off-the-shelf 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(...)
The focal_loss package includes the functions
binary_focal_loss
sparse_categorical_focal_loss
and wrapper classes
BinaryFocalLoss (use like tf.keras.losses.BinaryCrossentropy)
SparseCategoricalFocalLoss (use like tf.keras.losses.SparseCategoricalCrossentropy)
Documentation is available at Read the Docs.
Installation
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 and activate a new environment first
make dev
This will additionally install the requirements needed to run tests, check code coverage, and produce documentation.
References
Metadata
Release files for focal-loss 0.0.7
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| focal-loss-0.0.7.tar.gz | 14.4 kB | Without provenance | Details for focal-loss-0.0.7.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| focal_loss-0.0.7-py3-none-any.whl | Python 3 | none | any | Details for focal_loss-0.0.7-py3-none-any.whl |
Total release size: 33.5 kB
Release files / focal-loss-0.0.7.tar.gz
| Download URL | focal-loss-0.0.7.tar.gz |
|---|---|
| Size | 14.4 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
52de3311fdd6e6ee8f746638fb949b8fc55e167acdfffc74a33ac852750c893c
|
|
BLAKE2b-256 checksum How to use checksums |
57b06e7497f3526cd4dd27826308d6822c25ce1405f683b17c2f515dbffb4752
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.4.1 importlib_metadata/4.3.0 pkginfo/1.5.0.1 requests/2.23.0 requests-toolbelt/0.9.1 tqdm/4.46.1 CPython/3.8.3
|
Release files / focal_loss-0.0.7-py3-none-any.whl
| Download URL | focal_loss-0.0.7-py3-none-any.whl |
|---|---|
| Size | 19.0 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
2dad215281050019eb0ffdb4903335de6ef614f5576b08d2961bf1f2493eba42
|
|
BLAKE2b-256 checksum How to use checksums |
3aa1e362a8b955a417a6b37ae31088ecc3ad0fc31b50265c0924a969487eacf6
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.4.1 importlib_metadata/4.3.0 pkginfo/1.5.0.1 requests/2.23.0 requests-toolbelt/0.9.1 tqdm/4.46.1 CPython/3.8.3
|
Security for focal-loss 0.0.7
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.