class_docstr: `MS Coco Detection <https://cocodataset.org/>`_ Dataset.
  
  Args:
      root (string): Root directory where images are downloaded to.
      dataset (string): train or val.
      transforms (callable, optional): A function/transform that takes input sample and its target as entry
          and returns a transformed version.
class_docstr_tok: ["`","MS","Coco","Detection","<","https",":","\/\/cocodataset.org\/",">","`","_","Dataset",".","Args",":","root","(","string",")",":","Root","directory","where","images","are","downloaded","to",".","dataset","(","string",")",":","train","or","val",".","transforms","(","callable",",","optional",")",":","A","function\/transform","that","takes","input","sample","and","its","target","as","entry","and","returns","a","transformed","version","."]
code: def parse_targets(
      self,
      img_id: int,
      coco_targets: list,
      w: int = None,
      h: int = None,
  ):
      assert w > 0
      assert h > 0
  
      # 只筛选出单个对象的情况
      anno = [obj for obj in coco_targets if obj["iscrowd"] == 0]
  
      boxes = [obj["bbox"] for obj in anno]
  
      # guard against no boxes via resizing
      boxes = torch.as_tensor(boxes, dtype=torch.float32).reshape(-1, 4)
      # [xmin, ymin, w, h] -> [xmin, ymin, xmax, ymax]
      boxes[:, 2:] += boxes[:, :2]
      boxes[:, 0::2].clamp_(min=0, max=w)
      boxes[:, 1::2].clamp_(min=0, max=h)
  
      classes = [obj["category_id"] for obj in anno]
      classes = torch.tensor(classes, dtype=torch.int64)
  
      area = torch.tensor([obj["area"] for obj in anno])
      iscrowd = torch.tensor([obj["iscrowd"] for obj in anno])
  
      segmentations = [obj["segmentation"] for obj in anno]
      masks = convert_coco_poly_mask(segmentations, h, w)
  
      # 筛选出合法的目标，即x_max>x_min且y_max>y_min
      keep = (boxes[:, 3] > boxes[:, 1]) & (boxes[:, 2] > boxes[:, 0])
      boxes = boxes[keep]
      classes = classes[keep]
      masks = masks[keep]
      area = area[keep]
      iscrowd = iscrowd[keep]
  
      target = {}
      target["boxes"] = boxes
      target["labels"] = classes
      target["masks"] = masks
      target["image_id"] = torch.tensor([img_id])
  
      # for conversion to coco api
      target["area"] = area
      target["iscrowd"] = iscrowd
  
      return target
  
file_path: deep-learning-for-image-processing/pytorch_object_detection/mask_rcnn/my_dataset_coco.py
imports: import os
  import json
  import torch
  from PIL import Image
  import torch.utils.data
  from pycocotools.coco import COCO
  from train_utils import coco_remove_images_without_annotations, convert_coco_poly_mask
label_desc: Use image node_id 2 for calling the CocoDetection obj's underlying member method code with example usage: obj.parse_targets(img_id, coco_targets, w, h) and returns: target