code: def _transform_chip2image_bboxes(self, results, records):
      # 1. Transform chip dets to image dets;
      # 2. Filter valid range;
      # 3. Reformat and Aggregate chip dets to Get scale_cls_dets
      img_id2bbox = defaultdict(list)
      for result in results:
          bbox_locs = result["bbox"]
          bbox_nums = result["bbox_num"]
          if (
              len(bbox_locs) == 1 and bbox_locs[0][0] == -1
          ):  # current batch has no detections
              # bbox_locs = array([[-1.]], dtype=float32); bbox_nums = [[1]]
              # MultiClassNMS output: If there is no detected boxes for all images, lod will be set to {1} and Out only contains one value which is -1.
              continue
          im_ids = result["im_id"]  # replace with range(len(bbox_nums))
  
          last_bbox_num = 0
          for idx, im_id in enumerate(im_ids):
              cur_bbox_len = bbox_nums[idx]
              bboxes = bbox_locs[
                  last_bbox_num : last_bbox_num + cur_bbox_len
              ]
              last_bbox_num += cur_bbox_len
              # box: [num_id, score, xmin, ymin, xmax, ymax]
              if len(bboxes) == 0:  # current image has no detections
                  continue
  
              chip_rec = records[
                  int(im_id) - 1
              ]  # im_id starts from 1, type is np.int64
              image_size = max(
                  chip_rec["ori_im_h"], chip_rec["ori_im_w"]
              )
  
              bboxes = transform_chip_boxes2image_boxes(
                  bboxes,
                  chip_rec["chip"],
                  chip_rec["ori_im_h"],
                  chip_rec["ori_im_w"],
              )
  
              scale_i = chip_rec["scale_i"]
              cur_scale = self._get_current_scale(
                  self.target_sizes[scale_i], image_size
              )
              _, valid_boxes_idx = self._validate_boxes(
                  self.valid_box_ratio_ranges[scale_i],
                  image_size,
                  bboxes[:, 2:],
                  cur_scale,
              )
              ori_img_id = self._global_chip_id2img_id[int(im_id)]
  
              img_id2bbox[ori_img_id].append(bboxes[valid_boxes_idx])
  
      return img_id2bbox
  
imports: import copy
  import math
  import random
  import numpy
  from copy import deepcopy
  from typing import List, Tuple
  from collections import defaultdict
  from .chip_box_utils import nms, transform_chip_boxes2image_boxes
  from .chip_box_utils import find_chips_to_cover_overlaped_boxes
  from .chip_box_utils import transform_chip_box
  from .chip_box_utils import intersection_over_box
label_desc: Use image node_id 22 for calling the AnnoCropper obj's underlying member method code with example usage: obj._transform_chip2image_bboxes(results, records) and returns: img_id2bbox