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 details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

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

Uploaded Python 3

File details

Details for the file focal-loss-0.0.1.tar.gz.

File metadata

  • Download URL: focal-loss-0.0.1.tar.gz
  • Upload date:
  • Size: 11.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.15.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.2.0 requests-toolbelt/0.9.1 tqdm/4.36.1 CPython/3.7.2

File hashes

Hashes for focal-loss-0.0.1.tar.gz
Algorithm Hash digest
SHA256 27b7a26dc618918e130b5d2d60eac27f0a9c50d58b18ffa03a7e7b0d81d375bb
MD5 64756d0d3261177c6b725e0f8a085440
BLAKE2b-256 fab6d989de4741f5ec840a0f5104fa42373e8529d5de2b94ccf9715a0c3f94a8

See more details on using hashes here.

File details

Details for the file focal_loss-0.0.1-py3-none-any.whl.

File metadata

  • Download URL: focal_loss-0.0.1-py3-none-any.whl
  • Upload date:
  • Size: 14.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.15.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.2.0 requests-toolbelt/0.9.1 tqdm/4.36.1 CPython/3.7.2

File hashes

Hashes for focal_loss-0.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 d36749b514290c06cc9b373a2a1835da91fa60dc20943676044f4303ffdda359
MD5 7ec31ba04089d5f03f9f3605c39ab7b6
BLAKE2b-256 aa52001d60921313c26ffcc75662d776b4b6c3bcd2965066705e9cdd21f69bc8

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page