code: def get_class_loss_weights(
      overall_sample_class_stats, temperature=0.1
  ):
      overall_class_stats = defaultdict(int)
      for _, value in overall_sample_class_stats.items():
          for c, n in value.items():
              c = int(c)
              overall_class_stats[c] += n
  
      overall_class_stats = {
          k: v
          for k, v in sorted(
              overall_class_stats.items(), key=lambda item: item[1]
          )
      }
  
      freq_num = np.asarray(
          list(overall_class_stats.values()), dtype="float32"
      )
      freq = freq_num / np.sum(freq_num)
      freq = 1 - freq
      freq = F.softmax(
          paddle.to_tensor(freq / temperature, place="cpu"), axis=-1
      )
  
      column_names = ["ClassID", *list(overall_class_stats.keys())]
      table = pt.PrettyTable(column_names)
  
      table.add_row(
          ["Frequency", *[int(num) for num in freq_num.tolist()]]
      )
      table.add_row(
          ["Weights", *["{:.2f}".format(num) for num in freq.tolist()]]
      )
      logger.info("Overall Class Frequency Matrix: \n" + str(table))
  
file_path: PaddleSeg/contrib/QualityInspector/tools/dataset/cal_class_weights.py
imports: import argparse
  import os
  import sys
  from collections import defaultdict
  from multiprocessing import Pool, cpu_count
  import cv2
  import numpy
  import prettytable
  import paddle
  import paddle.nn.functional
  from qinspector.utils.logger import setup_logger
label_desc: Use image node_id 2 for calling a global function with example usage: get_class_loss_weights(overall_sample_class_stats, temperature) without return types