class_docstr: This code was developed by jbpatel@mit.edu.
      
class_docstr_tok: ["This","code","was","developed","by","jbpatel","@","mit.edu","."]
code: def dice_coef(self, y_true, y_pred):
      from keras import backend as K
  
      y_true_f = K.flatten(y_true)
  
      # y_pred was one-hot encoded so take only the second channel
      y_pred_f = K.flatten(y_pred[..., 1])
      intersection = K.sum(y_true_f * y_pred_f)
      self.diceMetric = (2.0 * intersection + self.smooth) / (
          K.sum(y_true_f) + K.sum(y_pred_f) + self.smooth
      )
      diceLoss = 1 - self.diceMetric
  
      return diceLoss
  
imports: import numpy
  import itertools
label_desc: Use image node_id 9 for calling the WeightedCategoricalCrossEntropy obj's underlying member method code with example usage: obj.dice_coef(y_true, y_pred) and returns: diceLoss