class_docstr: Mosaic augmentation.
  
  Given 4 images, mosaic transform combines them into
  one output image. The output image is composed of the parts from each sub-
  image.
  
  .. code:: text
  
                      mosaic transform
                      center_x
              +------------------------------+
              |       pad        |  pad      |
              |      +-----------+           |
              |      |           |           |
              |      |  image1   |--------+  |
              |      |           |        |  |
              |      |           | image2 |  |
  center_y   |----+-------------+-----------|
              |    |   cropped   |           |
              |pad |   image3    |  image4   |
              |    |             |           |
              +----|-------------+-----------+
                  |             |
                  +-------------+
  
  The mosaic transform steps are as follows:
  
      1. Choose the mosaic center as the intersections of 4 images
      2. Get the left top image according to the index, and randomly
          sample another 3 images from the custom dataset.
      3. Sub image will be cropped if image is larger than mosaic patch
  
  Required Keys:
  
  - img
  - gt_bboxes (BaseBoxes[torch.float32]) (optional)
  - gt_bboxes_labels (np.int64) (optional)
  - gt_ignore_flags (bool) (optional)
  - mix_results (List[dict])
  
  Modified Keys:
  
  - img
  - img_shape
  - gt_bboxes (optional)
  - gt_bboxes_labels (optional)
  - gt_ignore_flags (optional)
  
  Args:
      img_scale (Sequence[int]): Image size after mosaic pipeline of single
          image. The shape order should be (width, height).
          Defaults to (640, 640).
      center_ratio_range (Sequence[float]): Center ratio range of mosaic
          output. Defaults to (0.5, 1.5).
      bbox_clip_border (bool, optional): Whether to clip the objects outside
          the border of the image. In some dataset like MOT17, the gt bboxes
          are allowed to cross the border of images. Therefore, we don't
          need to clip the gt bboxes in these cases. Defaults to True.
      pad_val (int): Pad value. Defaults to 114.
      prob (float): Probability of applying this transformation.
          Defaults to 1.0.
class_docstr_tok: ["Mosaic","augmentation",".","Given","4","images",",","mosaic","transform","combines","them","into","one","output","image",".","The","output","image","is","composed","of","the","parts","from","each","sub-","image",".","..","code",":",":","text","mosaic","transform","center_x","+","--","--","--","--","--","--","--","--","--","--","--","--","--","--","--","+","|","pad","|","pad","|","|","+","--","--","--","--","--","-+","|","|","|","|","|","|","|","image1","|","--","--","--","--","+","|","|","|","|","|","|","|","|","|","image2","|","|","center_y","|","--","--","+","--","--","--","--","--","--","-+","--","--","--","--","--","-|","|","|","cropped","|","|","|pad","|","image3","|","image4","|","|","|","|","|","+","--","--","|","--","--","--","--","--","--","-+","--","--","--","--","--","-+","|","|","+","--","--","--","--","--","--","-+","The","mosaic","transform","steps","are","as","follows",":","1",".","Choose","the","mosaic","center","as","the","intersections","of","4","images","2",".","Get","the","left","top","image","according","to","the","index",",","and","randomly","sample","another","3","images","from","the","custom","dataset",".","3",".","Sub","image","will","be","cropped","if","image","is","larger","than","mosaic","patch","Required","Keys",":","-","img","-","gt_bboxes","(","BaseBoxes","[","torch.float32","]",")","(","optional",")","-","gt_bboxes_labels","(","np.int64",")","(","optional",")","-","gt_ignore_flags","(","bool",")","(","optional",")","-","mix_results","(","List","[","dict","]",")","Modified","Keys",":","-","img","-","img_shape","-","gt_bboxes","(","optional",")","-","gt_bboxes_labels","(","optional",")","-","gt_ignore_flags","(","optional",")","Args",":","img_scale","(","Sequence","[","int","]",")",":","Image","size","after","mosaic","pipeline","of","single","image",".","The","shape","order","should","be","(","width",",","height",")",".","Defaults","to","(","640",",","640",")",".","center_ratio_range","(","Sequence","[","float","]",")",":","Center","ratio","range","of","mosaic","output",".","Defaults","to","(","0.5",",","1.5",")",".","bbox_clip_border","(","bool",",","optional",")",":","Whether","to","clip","the","objects","outside","the","border","of","the","image",".","In","some","dataset","like","MOT17",",","the","gt","bboxes","are","allowed","to","cross","the","border","of","images",".","Therefore",",","we","don't","need","to","clip","the","gt","bboxes","in","these","cases",".","Defaults","to","True",".","pad_val","(","int",")",":","Pad","value",".","Defaults","to","114.","prob","(","float",")",":","Probability","of","applying","this","transformation",".","Defaults","to","1.0","."]
code: def __init__(
      self,
      img_scale: Tuple[int, int] = (640, 640),
      center_ratio_range: Tuple[float, float] = (0.5, 1.5),
      bbox_clip_border: bool = True,
      pad_val: float = 114.0,
      prob: float = 1.0,
  ) -> None:
      assert isinstance(img_scale, tuple)
      assert 0 <= prob <= 1.0, (
          "The probability should be in range [0,1]. " f"got {prob}."
      )
  
      log_img_scale(img_scale, skip_square=True, shape_order="wh")
      self.img_scale = img_scale
      self.center_ratio_range = center_ratio_range
      self.bbox_clip_border = bbox_clip_border
      self.pad_val = pad_val
      self.prob = prob
  
imports: import collections
  import copy
  import logging
  import math
  from typing import Dict, List, Optional, Sequence, Tuple, Union
  import mmcv
  import numpy
  import pandas
  import torch
  from mmcv.transforms import BaseTransform
  from mmcv.transforms.utils import cache_randomness
  from mmdet.structures.bbox import autocast_box_type
  from mmdet.utils import log_img_scale
  from mmengine.config import Config
  from mmengine.dataset import BaseDataset
  from numpy import random
  from ...constants import GET_ITEM_ERROR_RETRY, MULTI_IMAGE_MIX_DATASET, ROIS
  from ..preprocess_dataframe import MultiModalFeaturePreprocessor
  from ..utils import apply_data_processor, apply_df_preprocessor, get_per_sample_features
label_desc: Use image node_id 1 to create a new Mosaic object from inherited base classes: BaseTransform with example: obj = Mosaic(img_scale, center_ratio_range, bbox_clip_border, pad_val, prob)