code: def batch_intersection_union(output, target, nclass):
      """mIoU"""
      # inputs are NDarray, output 4D, target 3D
      # the category -1 is ignored class, typically for background / boundary
      mini = 1
      maxi = nclass
      nbins = nclass
      predict = np.argmax(output.asnumpy(), 1).astype("int64") + 1
      target = target.asnumpy().astype("int64") + 1
  
      predict = predict * (target > 0).astype(predict.dtype)
      intersection = predict * (predict == target)
      # areas of intersection and union
      area_inter, _ = np.histogram(
          intersection, bins=nbins, range=(mini, maxi)
      )
      area_pred, _ = np.histogram(
          predict, bins=nbins, range=(mini, maxi)
      )
      area_lab, _ = np.histogram(target, bins=nbins, range=(mini, maxi))
      area_union = area_pred + area_lab - area_inter
      assert (
          area_inter <= area_union
      ).all(), "Intersection area should be smaller than Union area"
      return area_inter, area_union
  
file_path: gluon-cv/gluoncv/utils/metrics/segmentation.py
imports: import threading
  import numpy
  import mxnet
label_desc: Use image node_id 2 for calling a global function with example usage: batch_intersection_union(output, target, nclass) and returns: area_inter,  area_union