class_docstr: Saves layer histogram in a dict with layer names as keys and lists of NDArrays as
  values. The collected histogram will be used for calculating the optimal thresholds for
  quantization using KL divergence.
class_docstr_tok: ["Saves","layer","histogram","in","a","dict","with","layer","names","as","keys","and","lists","of","NDArrays","as","values",".","The","collected","histogram","will","be","used","for","calculating","the","optimal","thresholds","for","quantization","using","KL","divergence","."]
docstr: Given a ndarray dict, find the optimal threshold for quantizing each value of the key.
code: def get_optimal_thresholds(
      hist_dict, quantized_dtype, num_quantized_bins=255, logger=None
  ):
      """Given a ndarray dict, find the optimal threshold for quantizing each value of the key."""
      assert isinstance(hist_dict, dict)
      if logger is not None:
          logger.info(
              "Calculating optimal thresholds for quantization using KL divergence"
              f" with num_quantized_bins={num_quantized_bins}"
          )
      th_dict = {}
      # copy hist_dict keys since the keys() only returns a view in python3
      layer_names = list(hist_dict.keys())
      for name in layer_names:
          assert name in hist_dict
          (
              min_val,
              max_val,
              th,
              divergence,
          ) = _LayerHistogramCollector.get_optimal_threshold(
              hist_dict[name],
              quantized_dtype,
              num_quantized_bins=num_quantized_bins,
          )
          if min_val >= 0 and quantized_dtype in ["auto", "uint8"]:
              th_dict[name] = (0, th)
          else:
              th_dict[name] = (-th, th)
          del hist_dict[name]  # release the memory
          if logger:
              logger.debug(
                  f"layer={name}, min_val={min_val}, max_val={max_val}, th={th}, divergence={divergence}"
              )
      return th_dict
  
imports: import abc
  import ctypes
  import logging
  import os
  import warnings
  import numpy
  import mxnet
  from ..base import _LIB, check_call, py_str
  from ..base import c_array, c_str, mx_uint, mx_real_t, c_str_array
  from ..base import SymbolHandle
  from ..symbol import Symbol
  from ..None import ndarray
  from ..io import DataDesc
  from ..device import cpu, Device
  from ..util import is_np_array, wrap_ctx_to_device_func
label_desc: Use image node_id 6 for calling the _LayerHistogramCollector obj's underlying member method code with example usage: obj.get_optimal_thresholds(hist_dict, quantized_dtype, num_quantized_bins, logger) and returns: th_dict