code: def generate_labels(args, src_dir, label_dir, image_set, mode):
      os.makedirs(
          os.path.join(args.root, src_dir, label_dir), exist_ok=True
      )
      label_file = open(
          os.path.join(args.root, src_dir, "{}_list.txt".format(mode)),
          "w",
      )
      for json_name in image_set:
          with open(
              os.path.join(args.root, src_dir, json_name)
          ) as jsonfile:
              for jsonline in jsonfile:
                  label = json.loads(jsonline)
                  seg_img = generate_seg_label_image(label)
                  img_path = label["raw_file"]
                  seg_path = img_path.split("/")
                  seg_path, img_name = (
                      os.path.join(
                          args.root,
                          src_dir,
                          label_dir,
                          seg_path[1],
                          seg_path[2],
                      ),
                      seg_path[3],
                  )
                  os.makedirs(seg_path, exist_ok=True)
                  seg_path = os.path.join(
                      seg_path, img_name[:-3] + "png"
                  )
                  cv2.imwrite(seg_path, seg_img)
  
                  img_path = "/".join([src_dir, img_path])
                  seg_path = "/".join(
                      [
                          src_dir,
                          label_dir,
                          *img_path.split("/")[2:4],
                          img_name[:-3] + "png",
                      ]
                  )
                  if seg_path[0] != "/":
                      seg_path = "/" + seg_path
                  if img_path[0] != "/":
                      img_path = "/" + img_path
  
                  label_str = []
                  label_str.insert(0, seg_path)
                  label_str.insert(0, img_path)
                  label_str = " ".join(label_str) + "\n"
                  label_file.write(label_str)
  
file_path: PaddleSeg/contrib/LaneSeg/third_party/generate_tusimple_dataset.py
imports: import os
  import cv2
  import json
  import argparse
  import numpy
label_desc: Use image node_id 2 for calling a global function with example usage: generate_labels(args, src_dir, label_dir, image_set, mode) without return types