class_docstr: 根据原文，对图像进行裁剪,该方法应放在ToTensor前
  Cropping for SSD, according to original paper
  Choose between following 3 conditions:
  1. Preserve the original image
  2. Random crop minimum IoU is among 0.1, 0.3, 0.5, 0.7, 0.9
  3. Random crop
  Reference to https://github.com/chauhan-utk/src.DomainAdaptation
class_docstr_tok: ["\u6839\u636e\u539f\u6587\uff0c\u5bf9\u56fe\u50cf\u8fdb\u884c\u88c1\u526a",",","\u8be5\u65b9\u6cd5\u5e94\u653e\u5728ToTensor\u524d","Cropping","for","SSD",",","according","to","original","paper","Choose","between","following","3","conditions",":","1",".","Preserve","the","original","image","2",".","Random","crop","minimum","IoU","is","among","0.1",",","0.3",",","0.5",",","0.7",",","0.9","3",".","Random","crop","Reference","to","https",":","\/\/github.com\/chauhan-utk\/src.DomainAdaptation"]
code: def __call__(self, image, target):
      # Ensure always return cropped image
      while True:
          mode = random.choice(self.sample_options)
          if mode is None:  # 不做随机裁剪处理
              return image, target
  
          htot, wtot = target["height_width"]
  
          min_iou, max_iou = mode
          min_iou = float("-inf") if min_iou is None else min_iou
          max_iou = float("+inf") if max_iou is None else max_iou
  
          # Implementation use 5 iteration to find possible candidate
          for _ in range(5):
              # 0.3*0.3 approx. 0.1
              w = random.uniform(0.3, 1.0)
              h = random.uniform(0.3, 1.0)
  
              if w / h < 0.5 or w / h > 2:  # 保证宽高比例在0.5-2之间
                  continue
  
              # left 0 ~ wtot - w, top 0 ~ htot - h
              left = random.uniform(0, 1.0 - w)
              top = random.uniform(0, 1.0 - h)
  
              right = left + w
              bottom = top + h
  
              # boxes的坐标是在0-1之间的
              bboxes = target["boxes"]
              ious = calc_iou_tensor(
                  bboxes, torch.tensor([[left, top, right, bottom]])
              )
  
              # tailor all the bboxes and return
              # all(): Returns True if all elements in the tensor are True, False otherwise.
              if not ((ious > min_iou) & (ious < max_iou)).all():
                  continue
  
              # discard any bboxes whose center not in the cropped image
              xc = 0.5 * (bboxes[:, 0] + bboxes[:, 2])
              yc = 0.5 * (bboxes[:, 1] + bboxes[:, 3])
  
              # 查找所有的gt box的中心点有没有在采样patch中的
              masks = (
                  (xc > left)
                  & (xc < right)
                  & (yc > top)
                  & (yc < bottom)
              )
  
              # if no such boxes, continue searching again
              # 如果所有的gt box的中心点都不在采样的patch中，则重新找
              if not masks.any():
                  continue
  
              # 修改采样patch中的所有gt box的坐标（防止出现越界的情况）
              bboxes[bboxes[:, 0] < left, 0] = left
              bboxes[bboxes[:, 1] < top, 1] = top
              bboxes[bboxes[:, 2] > right, 2] = right
              bboxes[bboxes[:, 3] > bottom, 3] = bottom
  
              # 虑除不在采样patch中的gt box
              bboxes = bboxes[masks, :]
              # 获取在采样patch中的gt box的标签
              labels = target["labels"]
              labels = labels[masks]
  
              # 裁剪patch
              left_idx = int(left * wtot)
              top_idx = int(top * htot)
              right_idx = int(right * wtot)
              bottom_idx = int(bottom * htot)
              image = image.crop(
                  (left_idx, top_idx, right_idx, bottom_idx)
              )
  
              # 调整裁剪后的bboxes坐标信息
              bboxes[:, 0] = (bboxes[:, 0] - left) / w
              bboxes[:, 1] = (bboxes[:, 1] - top) / h
              bboxes[:, 2] = (bboxes[:, 2] - left) / w
              bboxes[:, 3] = (bboxes[:, 3] - top) / h
  
              # 更新crop后的gt box坐标信息以及标签信息
              target["boxes"] = bboxes
              target["labels"] = labels
  
              return image, target
  
imports: import random
  import torch
  import torchvision.transforms
  from torchvision.transforms import functional
  from src import dboxes300_coco, calc_iou_tensor, Encoder
label_desc: Use image node_id 2 for calling the SSDCropping obj's underlying member method code with example usage: obj.__call__(image, target) and returns: image,  target, image,  target