class_docstr: Random crop the input image according to constraints.
  
  Args:
      scales(list): The value of the cutting area relative to the original area, expressed in the form of                       [min, max]. The default value is [.3, 1.].
      max_ratio(float): Max ratio of the original area relative to the cutting area, default is 2.0.
      constraints(list): The value of min and max iou values, default is None.
      max_trial(int): The max trial for finding a valid crop area. The default value is 50.
  
  Returns:
      img(np.ndarray): Distorted image.
      data(dict): Image info and label info.
class_docstr_tok: ["Random","crop","the","input","image","according","to","constraints",".","Args",":","scales","(","list",")",":","The","value","of","the","cutting","area","relative","to","the","original","area",",","expressed","in","the","form","of","[","min",",","max","]",".","The","default","value","is","[",".3",",","1.","]",".","max_ratio","(","float",")",":","Max","ratio","of","the","original","area","relative","to","the","cutting","area",",","default","is","2.0.","constraints","(","list",")",":","The","value","of","min","and","max","iou","values",",","default","is","None",".","max_trial","(","int",")",":","The","max","trial","for","finding","a","valid","crop","area",".","The","default","value","is","50",".","Returns",":","img","(","np.ndarray",")",":","Distorted","image",".","data","(","dict",")",":","Image","info","and","label","info","."]
code: def __call__(self, img: np.ndarray, data: dict):
      boxes = data["gt_boxes"]
      labels = data["gt_labels"]
      scores = data["gt_scores"]
  
      if len(boxes) == 0:
          return img, data
      if not self.constraints:
          self.constraints = [
              (0.1, 1.0),
              (0.3, 1.0),
              (0.5, 1.0),
              (0.7, 1.0),
              (0.9, 1.0),
              (0.0, 1.0),
          ]
  
      img = PIL.Image.fromarray(img)
      w, h = img.size
      crops = [(0, 0, w, h)]
      for min_iou, max_iou in self.constraints:
          for _ in range(self.max_trial):
              scale = random.uniform(self.scales[0], self.scales[1])
              aspect_ratio = random.uniform(
                  max(1 / self.max_ratio, scale * scale),
                  min(self.max_ratio, 1 / scale / scale),
              )
              crop_h = int(h * scale / np.sqrt(aspect_ratio))
              crop_w = int(w * scale * np.sqrt(aspect_ratio))
              crop_x = random.randrange(w - crop_w)
              crop_y = random.randrange(h - crop_h)
              crop_box = np.array(
                  [
                      [
                          (crop_x + crop_w / 2.0) / w,
                          (crop_y + crop_h / 2.0) / h,
                          crop_w / float(w),
                          crop_h / float(h),
                      ]
                  ]
              )
              iou = box_iou_xywh(crop_box, boxes)
              if min_iou <= iou.min() and max_iou >= iou.max():
                  crops.append((crop_x, crop_y, crop_w, crop_h))
                  break
  
      while crops:
          crop = crops.pop(np.random.randint(0, len(crops)))
          crop_boxes, crop_labels, crop_scores, box_num = box_crop(
              boxes, labels, scores, crop, (w, h)
          )
  
          if box_num < 1:
              continue
          img = img.crop(
              (crop[0], crop[1], crop[0] + crop[2], crop[1] + crop[3])
          ).resize(img.size, PIL.Image.LANCZOS)
          img = np.asarray(img)
          data["gt_boxes"] = crop_boxes
          data["gt_labels"] = crop_labels
          data["gt_scores"] = crop_scores
          return img, data
  
      img = np.asarray(img)
      data["gt_boxes"] = boxes
      data["gt_labels"] = labels
      data["gt_scores"] = scores
      return img, data
  
imports: import os
  import random
  from typing import Callable
  import cv2
  import PIL
  import numpy
  import paddlehub.vision.transforms.functional
  from paddlehub.vision.utils import box_crop, box_iou_xywh
label_desc: Use image node_id 2 for calling the RandomCrop obj's underlying member method code with example usage: obj.__call__(img, data) and returns: img,  data, img,  data, img,  data