class_docstr: Base class for anchor optimizer.
  
  Args:
      dataset (obj:`Dataset`): Dataset object.
      input_shape (list[int]): Input image shape of the model.
          Format in [width, height].
      logger (obj:`logging.Logger`): The logger for logging.
      device (str, optional): Device used for calculating.
          Default: 'cuda:0'
      out_dir (str, optional): Path to save anchor optimize result.
          Default: None
class_docstr_tok: ["Base","class","for","anchor","optimizer",".","Args",":","dataset","(","obj",":","`","Dataset","`",")",":","Dataset","object",".","input_shape","(","list","[","int","]",")",":","Input","image","shape","of","the","model",".","Format","in","[","width",",","height","]",".","logger","(","obj",":","`","logging.Logger","`",")",":","The","logger","for","logging",".","device","(","str",",","optional",")",":","Device","used","for","calculating",".","Default",":","'cuda:0'","out_dir","(","str",",","optional",")",":","Path","to","save","anchor","optimize","result",".","Default",":","None"]
docstr: Get widths and heights of bboxes and shapes of images.
  
  Returns:
      tuple[np.ndarray]: Array of bbox shapes and array of image
      shapes with shape (num_bboxes, 2) in [width, height] format.
docstr_tok: ["Get","widths","and","heights","of","bboxes","and","shapes","of","images",".","Returns",":","tuple","[","np.ndarray","]",":","Array","of","bbox","shapes","and","array","of","image","shapes","with","shape","(","num_bboxes",",","2",")","in","[","width",",","height","]","format","."]
code: def get_whs_and_shapes(self):
      """Get widths and heights of bboxes and shapes of images.
  
      Returns:
          tuple[np.ndarray]: Array of bbox shapes and array of image
          shapes with shape (num_bboxes, 2) in [width, height] format.
      """
      self.logger.info("Collecting bboxes from annotation...")
      bbox_whs = []
      img_shapes = []
      prog_bar = ProgressBar(len(self.dataset))
      for idx in range(len(self.dataset)):
          data_info = self.dataset.get_data_info(idx)
          img_shape = np.array(
              [data_info["width"], data_info["height"]]
          )
          gt_instances = data_info["instances"]
          for instance in gt_instances:
              bbox = np.array(instance["bbox"])
              wh = bbox[2:4] - bbox[0:2]
              img_shapes.append(img_shape)
              bbox_whs.append(wh)
  
          prog_bar.update()
      print("\n")
      bbox_whs = np.array(bbox_whs)
      img_shapes = np.array(img_shapes)
      self.logger.info(f"Collected {bbox_whs.shape[0]} bboxes.")
      return bbox_whs, img_shapes
  
imports: import argparse
  import os.path
  import numpy
  import torch
  from mmengine.config import Config
  from mmengine.fileio import dump
  from mmengine.logging import MMLogger
  from mmengine.registry import init_default_scope
  from mmengine.utils import ProgressBar
  from scipy.optimize import differential_evolution
  from mmdet.registry import DATASETS
  from mmdet.structures.bbox import bbox_cxcywh_to_xyxy, bbox_overlaps, bbox_xyxy_to_cxcywh
  from mmdet.utils import replace_cfg_vals, update_data_root
label_desc: Use image node_id 2 for calling the BaseAnchorOptimizer obj's underlying member method code with example usage: obj.get_whs_and_shapes() and returns: bbox_whs,  img_shapes