code: def lovasz_grad(gt_sorted):
      """
      Computes gradient of the Lovasz extension w.r.t sorted errors.
      See Alg. 1 in paper.
      """
      gts = paddle.sum(gt_sorted)
      p = len(gt_sorted)
  
      intersection = gts - paddle.cumsum(gt_sorted, axis=0)
      union = gts + paddle.cumsum(1 - gt_sorted, axis=0)
      jaccard = 1.0 - intersection.cast("float32") / union.cast(
          "float32"
      )
  
      if p > 1:  # cover 1-pixel case
          jaccard[1:p] = jaccard[1:p] - jaccard[0:-1]
      return jaccard
  
imports: from __future__ import absolute_import
  from __future__ import division
  from __future__ import print_function
  import numpy
  import paddle
  from paddle import nn
  import paddle.nn.functional
  from paddleseg.cvlibs import manager
label_desc: Use image node_id 1 for calling a global function with example usage: lovasz_grad(gt_sorted) and returns: jaccard