code: def coco_to_multilabel_format(args):
      coco = COCO(args.ann_input)
      cat_id_map = {
          old_cat_id: new_cat_id
          for new_cat_id, old_cat_id in enumerate(coco.getCatIds())
      }
      num_classes = len(list(cat_id_map.keys()))
  
      assert (
          "annotations" in coco.dataset
      ), "Annotation file: {} does not contains ground truth!!!".format(
          args.ann_input
      )
  
      total_img_id_list = sorted(list(coco.imgToAnns.keys()))
      train_img_id_list = random.sample(
          total_img_id_list,
          int(len(total_img_id_list) * args.train_proportion),
      )
      val_img_id_list = np.setdiff1d(
          total_img_id_list, train_img_id_list
      )
  
      pbar = tqdm(total=len(total_img_id_list))
      for img_id_list, split in zip(
          [train_img_id_list, val_img_id_list], ["train", "val"]
      ):
          txt_lines = []
          for img_id in img_id_list:
              img_info = coco.loadImgs([img_id])[0]
              img_filename = img_info["file_name"]
              img_w = img_info["width"]
              img_h = img_info["height"]
  
              img_filepath = os.path.join(args.img_input, img_filename)
              if not os.path.exists(img_filepath):
                  print(
                      "Illegal image file: {}, "
                      "and it will be ignored".format(img_filepath)
                  )
                  continue
  
              if img_w < 0 or img_h < 0:
                  print(
                      "Illegal width: {} or height: {} in annotation, "
                      "and im_id: {} will be ignored".format(
                          img_w, img_h, img_id
                      )
                  )
                  continue
  
              ann_ids = coco.getAnnIds(imgIds=[img_id])
              anns = coco.loadAnns(ann_ids)
  
              mask = np.zeros(
                  [img_h, num_classes * img_w], dtype="uint8"
              )
              for ann in anns:
                  cat_id = cat_id_map[ann["category_id"]]
                  one_cls_mask = coco.annToMask(ann)
                  mask[
                      :, cat_id * img_w : (cat_id + 1) * img_w
                  ] = np.where(
                      one_cls_mask,
                      one_cls_mask,
                      mask[:, cat_id * img_w : (cat_id + 1) * img_w],
                  )
  
              image = cv2.imread(img_filepath, cv2.IMREAD_COLOR)
              cv2.imwrite(
                  os.path.join(
                      args.output,
                      "images",
                      split,
                      os.path.splitext(img_filename)[0] + ".jpg",
                  ),
                  image,
              )
              cv2.imwrite(
                  os.path.join(
                      args.output,
                      "annotations",
                      split,
                      os.path.splitext(img_filename)[0] + ".png",
                  ),
                  mask,
              )
              txt_lines.append(
                  os.path.join(
                      "images",
                      split,
                      os.path.splitext(img_filename)[0] + ".jpg",
                  )
                  + " "
                  + os.path.join(
                      "annotations",
                      split,
                      os.path.splitext(img_filename)[0] + ".png",
                  )
              )
              pbar.update()
  
          with open(
              os.path.join(args.output, split + ".txt"), "w"
          ) as fp:
              fp.write("\n".join(txt_lines))
  
file_path: PaddleSeg/tools/data/convert_multilabel.py
imports: import argparse
  import os
  import random
  import zipfile
  import cv2
  import numpy
  import pandas
  from PIL import Image
  from pycocotools.coco import COCO
  from tqdm import tqdm
label_desc: Use image node_id 5 for calling a global function with example usage: coco_to_multilabel_format(args) without return types