code: def dice_hard_coe(
      output, target, threshold=0.5, axis=(1, 2, 3), smooth=1e-5
  ):
      """Non-differentiable Sørensen–Dice coefficient for comparing the similarity
      of two batch of data, usually be used for binary image segmentation i.e. labels are binary.
      The coefficient between 0 to 1, 1 if totally match.
  
      Parameters
      -----------
      output : tensor
          A distribution with shape: [batch_size, ....], (any dimensions).
      target : tensor
          The target distribution, format the same with `output`.
      threshold : float
          The threshold value to be true.
      axis : tuple of integer
          All dimensions are reduced, default ``(1,2,3)``.
      smooth : float
          This small value will be added to the numerator and denominator, see ``dice_coe``.
  
      References
      -----------
      - `Wiki-Dice <https://en.wikipedia.org/wiki/Sørensen–Dice_coefficient>`__
  
      """
      output = tf.cast(output > threshold, dtype=tf.float32)
      target = tf.cast(target > threshold, dtype=tf.float32)
      inse = tf.reduce_sum(tf.multiply(output, target), axis=axis)
      l = tf.reduce_sum(output, axis=axis)
      r = tf.reduce_sum(target, axis=axis)
      # old axis=[0,1,2,3]
      # hard_dice = 2 * (inse) / (l + r)
      # epsilon = 1e-5
      # hard_dice = tf.clip_by_value(hard_dice, 0, 1.0-epsilon)
      # new haodong
      hard_dice = (2.0 * inse + smooth) / (l + r + smooth)
      ##
      hard_dice = tf.reduce_mean(hard_dice, name="hard_dice")
      return hard_dice
  
imports: import numbers
  import tensorflow
  from tensorflow.python.framework import ops
  from tensorflow.python.ops import array_ops, math_ops, nn_ops, standard_ops
  from tensorlayer import logging
label_desc: Use image node_id 8 for calling a global function with example usage: dice_hard_coe(output, target, threshold, axis, smooth) and returns: hard_dice