code: def class_weights(tensor):
      # normalize the input first
      tensor = paddle.nn.functional.softmax(tensor, axis=1)
      flattened = flatten(tensor)
      nominator = (1.0 - flattened).sum(-1)
      denominator = flattened.sum(-1)
      class_weights = nominator / denominator
      class_weights.stop_gradient = True
  
      return class_weights
  
label_desc: Use image node_id 2 for calling a global function with example usage: class_weights(tensor) and returns: class_weights