JackAndCole / focal-loss-implementation-in-keras

Binary and Categorical Focal loss implementation in Keras.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Focal Loss

This is the keras implementation of focal loss proposed by Lin et. al. in their Focal Loss for Dense Object Detection paper.

focal loss

Usage

Compile your model with focal loss as follows:

for binary

model.compile(loss=[binary_focal_loss(gamma=2)], metrics=["accuracy"], optimizer="adam")

for categorical

model.compile(loss=[categorical_focal_loss(gamma=2)], metrics=["accuracy"], optimizer="adam")

alpha setting:

model.fit(class_weight={0:alpha0, 1:alpha1, ...}, ...) the class_weight is the alpha of focal loss.

References

The implementation is based @umbertogriffo

About

Binary and Categorical Focal loss implementation in Keras.

License:Apache License 2.0


Languages

Language:Python 100.0%