This is the keras implementation of focal loss proposed by Lin et. al. in their Focal Loss for Dense Object Detection paper.
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")
model.fit(class_weight={0:alpha0, 1:alpha1, ...}, ...)
the class_weight is the alpha of focal loss.
The implementation is based @umbertogriffo