This is the keras implementation of focal loss with the backend of tensorflow. The Focal Loss is proposed for dealing with foreground-backgrou class
imbalance.
Compile your model with focal loss as sample:
model.compile(optimizer = Adam(lr = 1e-4), loss = [focal_loss(gamma=2,alpha=0.6)], metrics = ['accuracy'])
We implement U-Net: Convolutional Networks for Biomedical Image Segmentation with Focal Loss and get the results of different parameters as follows:
fig1
fig2
From fig2, we found the improvement of focal is not ideal. And different parameters have a greater impact.
We found that the Focal Loss is not stable and I think the main reason is parameters initialization. I wil try to fix it.
The implemented code is based @zhixuhao' code