code: def __init__(self, img_folder, annotate_file, transform=None):
      self.img_folder = img_folder
      self.annotate_file = annotate_file
  
      # Start processing annotation
      with open(annotate_file) as fin:
          self.data = json.load(fin)
  
      self.images = {}
  
      self.label_map = {}
      self.label_info = {}
      # print("Parsing COCO data...")
      start_time = time.time()
      # 0 stand for the background
      cnt = 0
      self.label_info[cnt] = "background"
      for cat in self.data["categories"]:
          cnt += 1
          self.label_map[cat["id"]] = cnt
          self.label_info[cnt] = cat["name"]
  
      # build inference for images
      for img in self.data["images"]:
          img_id = img["id"]
          img_name = img["file_name"]
          img_size = (img["height"], img["width"])
          # print(img_name)
          if img_id in self.images:
              raise Exception("dulpicated image record")
          self.images[img_id] = (img_name, img_size, [])
  
      # read bboxes
      for bboxes in self.data["annotations"]:
          img_id = bboxes["image_id"]
          category_id = bboxes["category_id"]
          bbox = bboxes["bbox"]
          bbox_label = self.label_map[bboxes["category_id"]]
          self.images[img_id][2].append((bbox, bbox_label))
  
      for k, v in list(self.images.items()):
          if len(v[2]) == 0:
              # print("empty image: {}".format(k))
              self.images.pop(k)
  
      self.img_keys = list(self.images.keys())
      self.transform = transform
  
imports: import torch
  import torchvision.transforms
  import torch.utils.data
  from PIL import Image
  import os
  import numpy
  import random
  import itertools
  import torch.nn.functional
  import json
  import time
  import bz2
  import pickle
  from math import sqrt
label_desc: Use image node_id 1 to create a new COCODetection object from inherited base classes: data with example: obj = COCODetection(img_folder, annotate_file, transform)