Is this a correct implementation for focal loss in pytorch?

Hi, just to clarify this is not my implementation, I found it somewhere in kaggle, I cant find the link now. I will try to answer your questions nonetheless:

  1. Alpha is hyperparameter that you can tune to assign more importance to samples from class A or B. I dont know anything about binary segmentation so correct me if i am wrong, but I assume that it must have at least 2 classes. The class you are trying to segment and background.
  2. The epsilon is used to avoid numerical instability if probability equals 0. In this case torch.exp() will deal with that.

You can find another, perhaps more clear, implementation here