code: def compute_class_weights(
      class_weights, class_counts, n_total=None, multilabel=False
  ):
      """
      Optionally compute class weights based on target distribution
      """
      if class_weights is None:
          return
  
      options = {"linear", "log", "sqrt"}
  
      if isinstance(class_weights, str) and class_weights in options:
          counts = class_counts
          max_count = max(counts.values())
          computed_ratios = _compute_ratios(
              counts, n_total, multilabel=multilabel
          )
          computed_weights = {}
          for class_name, ratio in computed_ratios.items():
              if class_weights == "linear":
                  computed_weights[class_name] = ratio
              elif class_weights == "sqrt":
                  computed_weights[class_name] = np.sqrt(ratio)
              elif class_weights == "log":
                  computed_weights[class_name] = np.log(ratio) + 1
          class_weights = computed_weights
  
      if not isinstance(class_weights, dict):
          raise FinetuneError(
              "Invalid value for config.class_weights: {}. "
              "Expected dictionary mapping from class name to weight or one of {}".format(
                  class_weights, list(options)
              )
          )
      return class_weights
  
file_path: finetune/finetune/util/imbalance.py
imports: import tensorflow
  import numpy
  from collections import Counter
  from finetune.encoding.target_encoders import LabelEncoder
  from finetune.errors import FinetuneError
label_desc: Use image node_id 1 for calling a global function with example usage: compute_class_weights(class_weights, class_counts, n_total, multilabel) and returns: class_weights