Thank you for helping me, Ben!!
I completed implmentation of focal loss for semantic segmentation.

  
      github.com
  
  
    doiken23/pytorch_toolbox/blob/master/focalloss2d.py 1.1k
####################################################
##### This is focal loss class for multi class #####
##### University of Tokyo Doi Kento            #####
####################################################

import torch
import torch.nn as nn
import torch.nn.functional as F
from torch.autograd import Variable
# I refered https://github.com/c0nn3r/RetinaNet/blob/master/focal_loss.py

class FocalLoss2d(nn.Module):

    def __init__(self, gamma=0, weight=None, size_average=True):
        super(FocalLoss2d, self).__init__()

        self.gamma = gamma
        self.weight = weight
        self.size_average = size_average



  This file has been truncated. show original