code: def fast_histogram(a, b, na, nb):
      """
      fast histogram calculation
      ---
      * a, b: non negative label ids, a.shape == b.shape, a in [0, ... na-1], b in [0, ..., nb-1]
      """
      assert a.shape == b.shape
      assert np.all((a >= 0) & (a < na) & (b >= 0) & (b < nb))
      # k = (a >= 0) & (a < na) & (b >= 0) & (b < nb)
      hist = np.bincount(
          nb * a.reshape([-1]).astype(int)
          + b.reshape([-1]).astype(int),
          minlength=na * nb,
      ).reshape(na, nb)
      assert np.sum(hist) == a.size
      return hist
  
file_path: insightface/parsing/dml_csr/utils/miou.py
imports: from __future__ import absolute_import
  from __future__ import division
  from __future__ import print_function
  import argparse
  import cv2
  import json
  import numpy
  import os
  from collections import OrderedDict
  from PIL import Image
  from utils.transforms import transform_parsing
label_desc: Use image node_id 3 for calling a global function with example usage: fast_histogram(a, b, na, nb) and returns: hist