code: def deal_json(ds_type, img_path, json_path):
      data_coco = {}
      images_list = []
      annotations_list = []
      image_num = -1
      object_num = -1
      for img_file in os.listdir(img_path):
          img_label = os.path.splitext(img_file)[0]
          if img_file.split(".")[-1] not in [
              "bmp",
              "jpg",
              "jpeg",
              "png",
              "JPEG",
              "JPG",
              "PNG",
          ]:
              continue
          label_file = osp.join(json_path, img_label + ".json")
          print("Generating dataset from:", label_file)
          image_num = image_num + 1
          with open(label_file) as f:
              data = json.load(f)
              if ds_type == "labelme":
                  images_list.append(images_labelme(data, image_num))
              elif ds_type == "cityscape":
                  images_list.append(
                      images_cityscape(data, image_num, img_file)
                  )
              if ds_type == "labelme":
                  for shapes in data["shapes"]:
                      object_num = object_num + 1
                      label = shapes["label"]
                      if label not in labels_list:
                          categories_list.append(
                              categories(label, labels_list)
                          )
                          labels_list.append(label)
                          label_to_num[label] = len(labels_list)
                      p_type = shapes["shape_type"]
                      if p_type == "polygon":
                          points = shapes["points"]
                          annotations_list.append(
                              annotations_polygon(
                                  data["imageHeight"],
                                  data["imageWidth"],
                                  points,
                                  label,
                                  image_num,
                                  object_num,
                                  label_to_num,
                              )
                          )
  
                      if p_type == "rectangle":
                          (x1, y1), (x2, y2) = shapes["points"]
                          x1, x2 = sorted([x1, x2])
                          y1, y2 = sorted([y1, y2])
                          points = [
                              [x1, y1],
                              [x2, y2],
                              [x1, y2],
                              [x2, y1],
                          ]
                          annotations_list.append(
                              annotations_rectangle(
                                  points,
                                  label,
                                  image_num,
                                  object_num,
                                  label_to_num,
                              )
                          )
              elif ds_type == "cityscape":
                  for shapes in data["objects"]:
                      object_num = object_num + 1
                      label = shapes["label"]
                      if label not in labels_list:
                          categories_list.append(
                              categories(label, labels_list)
                          )
                          labels_list.append(label)
                          label_to_num[label] = len(labels_list)
                      points = shapes["polygon"]
                      annotations_list.append(
                          annotations_polygon(
                              data["imgHeight"],
                              data["imgWidth"],
                              points,
                              label,
                              image_num,
                              object_num,
                              label_to_num,
                          )
                      )
      data_coco["images"] = images_list
      data_coco["categories"] = categories_list
      data_coco["annotations"] = annotations_list
      return data_coco
  
imports: import argparse
  import glob
  import json
  import os
  import os.path
  import shutil
  import xml.etree.ElementTree
  import numpy
  import PIL.ImageDraw
  from tqdm import tqdm
  import cv2
label_desc: Use image node_id 7 for calling a global function with example usage: deal_json(ds_type, img_path, json_path) and returns: data_coco