class_docstr: 读取解析PASCAL VOC2007/2012数据集
class_docstr_tok: ["\u8bfb\u53d6\u89e3\u6790PASCAL","VOC2007\/2012\u6570\u636e\u96c6"]
code: def __getitem__(self, idx):
      # read xml
      xml_path = self.xml_list[idx]
      with open(xml_path) as fid:
          xml_str = fid.read()
      xml = etree.fromstring(xml_str)
      data = self.parse_xml_to_dict(xml)["annotation"]
      img_path = os.path.join(self.img_root, data["filename"])
      image = Image.open(img_path)
      if image.format != "JPEG":
          raise ValueError(
              "Image '{}' format not JPEG".format(img_path)
          )
  
      boxes = []
      labels = []
      iscrowd = []
      assert "object" in data, "{} lack of object information.".format(
          xml_path
      )
      for obj in data["object"]:
          xmin = float(obj["bndbox"]["xmin"])
          xmax = float(obj["bndbox"]["xmax"])
          ymin = float(obj["bndbox"]["ymin"])
          ymax = float(obj["bndbox"]["ymax"])
          boxes.append([xmin, ymin, xmax, ymax])
          labels.append(self.class_dict[obj["name"]])
          if "difficult" in obj:
              iscrowd.append(int(obj["difficult"]))
          else:
              iscrowd.append(0)
  
      # convert everything into a torch.Tensor
      boxes = torch.as_tensor(boxes, dtype=torch.float32)
      labels = torch.as_tensor(labels, dtype=torch.int64)
      iscrowd = torch.as_tensor(iscrowd, dtype=torch.int64)
      image_id = torch.tensor([idx])
      area = (boxes[:, 3] - boxes[:, 1]) * (boxes[:, 2] - boxes[:, 0])
  
      target = {}
      target["boxes"] = boxes
      target["labels"] = labels
      target["image_id"] = image_id
      target["area"] = area
      target["iscrowd"] = iscrowd
  
      if self.transforms is not None:
          image, target = self.transforms(image, target)
  
      return image, target
  
file_path: deep-learning-for-image-processing/pytorch_object_detection/retinaNet/my_dataset.py
imports: from torch.utils.data import Dataset
  import os
  import torch
  import json
  from PIL import Image
  from lxml import etree
label_desc: Use image node_id 3 for calling the VOCDataSet obj's underlying member method code with example usage: obj.__getitem__(idx) and returns: image,  target