text: import tensorflow.keras.backend as K
  
  #------------------------------- LOSSES ----------------------------------#
  def jaccard_distance(y_true, y_pred, smooth=100):
      intersection = K.sum(K.abs(y_true * y_pred), axis=-1)
      sum_ = K.sum(K.square(y_true), axis = -1) + K.sum(K.square(y_pred), axis=-1)
      jac = (intersection + smooth) / (sum_ - intersection + smooth)
      return (1 - jac)
  
  
  #------------------------------- METRICS -----------------------------------#
  def iou(y_true, y_pred, smooth = 100):
      intersection = K.sum(K.abs(y_true * y_pred), axis=-1)
      sum_ = K.sum(K.square(y_true), axis = -1) + K.sum(K.square(y_pred), axis=-1)
      jac = (intersection + smooth) / (sum_ - intersection + smooth)
      return jac
  
  
  def dice_coe(y_true, y_pred, smooth = 100):
      y_true_f = K.flatten(y_true)
      y_pred_f = K.flatten(y_pred)
      intersection = K.sum(y_true_f * y_pred_f)
      return (2. * intersection + smooth) / (K.sum(y_true_f) + K.sum(y_pred_f) + smooth)
  
  
  def precision(y_true, y_pred):
      '''Calculates the precision, a metric for multi-label classification of
      how many selected items are relevant.
      '''
      true_positives = K.sum(K.round(K.clip(y_true * y_pred, 0, 1)))
      predicted_positives = K.sum(K.round(K.clip(y_pred, 0, 1)))
      precision = true_positives / (predicted_positives + K.epsilon())
      return precision
  
  
  def recall(y_true, y_pred):
      '''Calculates the recall, a metric for multi-label classification of
      how many relevant items are selected.
      '''
      true_positives = K.sum(K.round(K.clip(y_true * y_pred, 0, 1)))
      possible_positives = K.sum(K.round(K.clip(y_true, 0, 1)))
      recall = true_positives / (possible_positives + K.epsilon())
      return recall
  
  
  def accuracy(y_true, y_pred):
      '''Calculates the mean accuracy rate across all predictions for binary
      classification problems.
      '''
      return K.mean(K.equal(y_true, K.round(y_pred)))