code: def forward(self, pred, true):
      loss = self.loss_fcn(pred, true)
      # p_t = torch.exp(-loss)
      # loss *= self.alpha * (1.000001 - p_t) ** self.gamma  # non-zero power for gradient stability
  
      # TF implementation https://github.com/tensorflow/addons/blob/v0.7.1/tensorflow_addons/losses/focal_loss.py
      pred_prob = torch.sigmoid(pred)  # prob from logits
      p_t = true * pred_prob + (1 - true) * (1 - pred_prob)
      alpha_factor = true * self.alpha + (1 - true) * (1 - self.alpha)
      modulating_factor = (1.0 - p_t) ** self.gamma
      loss *= alpha_factor * modulating_factor
  
      if self.reduction == "mean":
          return loss.mean()
      elif self.reduction == "sum":
          return loss.sum()
      else:  # 'none'
          return loss
  
imports: import glob
  import math
  import os
  import random
  import time
  import cv2
  import matplotlib
  import numpy
  import torch
  import torch.nn
  import torchvision
  from tqdm import tqdm
  from build_utils import torch_utils
label_desc: Use image node_id 2 for calling the FocalLoss obj's underlying member method code with example usage: obj.forward(pred, true) and returns: loss, loss, loss