code: def generate_segment_id_from_index(index):
      if check_is_tensor(index):
          zeros = paddle.zeros(index[-1] + 1, dtype="int32")
          index = index[:-1]
          segments = paddle.scatter(
              zeros, index, paddle.ones_like(index, dtype="int32")
          )
          segments = paddle.cumsum(segments)[:-1] - 1
          return segments
      else:
          segments = np.zeros(index[-1] + 1, dtype="int32")
          index = index[:-1]
          segments[index] += 1
          segments = np.cumsum(segments)[:-1] - 1
          return segments
  
file_path: PGL/pgl/utils/helper.py
imports: import numpy
  import paddle
  from paddle.common_ops_import import Variable
  from paddle.framework import core
  from pgl.utils import op
label_desc: Use image node_id 4 for calling a global function with example usage: generate_segment_id_from_index(index) and returns: segments, segments