TensorFlow implementation of focal loss.
Project description
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 the functions
binary_focal_loss
sparse_categorical_focal_loss
and wrapper classes
BinaryFocalLoss
SparseCategoricalFocalLoss
that can be used as stand-in replacements for tf.keras.losses functions and classes, respectively. For example,
# 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.gitAlternatively, install a recent release from the Python Package Index (PyPI):
pip install focal-lossNote. 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 devThis 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
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file focal-loss-0.0.5.tar.gz.
File metadata
- Download URL: focal-loss-0.0.5.tar.gz
- Upload date:
- Size: 13.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/47.1.1 requests-toolbelt/0.9.1 tqdm/4.46.1 CPython/3.8.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
553a57f9039fb971b649b473a12f543ea44629651e9f5455419d52b98a8c9b4c
|
|
| MD5 |
7c3beee3e5268cefec69d1e23dac6012
|
|
| BLAKE2b-256 |
5ba8ea989166d7fd7d2379d01c29bc2fe842701e199547e8ab594395e8471ed4
|
File details
Details for the file focal_loss-0.0.5-py3-none-any.whl.
File metadata
- Download URL: focal_loss-0.0.5-py3-none-any.whl
- Upload date:
- Size: 18.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/47.1.1 requests-toolbelt/0.9.1 tqdm/4.46.1 CPython/3.8.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
ecff3b6331cd60dd9ce189f8f63d9a06f6693e07d96fd6244da948791b0d6c82
|
|
| MD5 |
06323ef65a153f525f51038924e3a5e7
|
|
| BLAKE2b-256 |
2ea82fcf3420d28754b7df2ddb0e06f44bcae66ad6c18a8dea12268c1d52f210
|