code: def visualization_bbox(args):
      if not osp.exists(args.save_path):
          os.makedirs(args.save_path)
  
      coco = COCO(args.json_path)
      coco_classes = dict(
          [(v["id"], v["name"]) for k, v in coco.cats.items()]
      )
      img_ids = list(sorted(coco.imgs.keys()))
      for img_id in img_ids:
          im_info = coco.loadImgs(img_id)[0]
          ann_ids = coco.getAnnIds(imgIds=img_id, iscrowd=None)
          annos = coco.loadAnns(ann_ids)
          # coco.showAnns(annos)
          if len(annos) == 0:
              continue
          image = Image.open(
              os.path.join(args.root_path, im_info["file_name"])
          ).convert("RGB")
          draw = ImageDraw.Draw(image)
          for anno in annos:
              x, y, w, h = anno["bbox"]
              draw.line(
                  [
                      (x, y),
                      (x, int(y + h)),
                      (int(x + w), int(y + h)),
                      (int(x + w), y),
                      (x, y),
                  ],
                  width=2,
                  fill=(255, 0, 0),
              )
              text = "class: {}".format(
                  str(coco_classes[anno["category_id"]])
              )
              _, th = draw.textsize(text)
              draw.text((x, y - th), text)
          image.save(
              osp.join(
                  args.save_path, osp.basename(im_info["file_name"])
              )
          )
  
imports: import argparse
  import os
  import os.path
  from PIL import Image, ImageDraw
  from pycocotools.coco import COCO
label_desc: Use image node_id 2 for calling a global function with example usage: visualization_bbox(args) without return types