code: def load_model(self):
      from detectron2.config import get_cfg
      from detectron2.data import MetadataCatalog
      from detectron2.engine import DefaultPredictor
      from detectron2.model_zoo import model_zoo
  
      cfg = get_cfg()
  
      try:  # try to load from model zoo
          config_file = model_zoo.get_config_file(self.config_path)
          cfg.merge_from_file(config_file)
          cfg.MODEL.WEIGHTS = model_zoo.get_checkpoint_url(
              self.config_path
          )
      except Exception as e:  # try to load from local
          print(e)
          if self.config_path is not None:
              cfg.merge_from_file(self.config_path)
          cfg.MODEL.WEIGHTS = self.model_path
  
      # set model device
      cfg.MODEL.DEVICE = self.device.type
      # set input image size
      if self.image_size is not None:
          cfg.INPUT.MIN_SIZE_TEST = self.image_size
          cfg.INPUT.MAX_SIZE_TEST = self.image_size
      # init predictor
      model = DefaultPredictor(cfg)
  
      self.model = model
  
      # detectron2 category mapping
      if self.category_mapping is None:
          try:  # try to parse category names from metadata
              metadata = MetadataCatalog.get(cfg.DATASETS.TRAIN[0])
              category_names = metadata.thing_classes
              self.category_names = category_names
              self.category_mapping = {
                  str(ind): category_name
                  for ind, category_name in enumerate(
                      self.category_names
                  )
              }
          except Exception as e:
              logger.warning(e)
              # https://detectron2.readthedocs.io/en/latest/tutorials/datasets.html#update-the-config-for-new-datasets
              if cfg.MODEL.META_ARCHITECTURE == "RetinaNet":
                  num_categories = cfg.MODEL.RETINANET.NUM_CLASSES
              else:  # fasterrcnn/maskrcnn etc
                  num_categories = cfg.MODEL.ROI_HEADS.NUM_CLASSES
              self.category_names = [
                  str(category_id)
                  for category_id in range(num_categories)
              ]
              self.category_mapping = {
                  str(ind): category_name
                  for ind, category_name in enumerate(
                      self.category_names
                  )
              }
      else:
          self.category_names = list(self.category_mapping.values())
  
file_path: sahi/sahi/models/detectron2.py
imports: import logging
  from typing import List, Optional
  import numpy
  from sahi.models.base import DetectionModel
  from sahi.prediction import ObjectPrediction
  from sahi.utils.cv import get_bbox_from_bool_mask
  from sahi.utils.import_utils import check_requirements
label_desc: Use image node_id 2 for calling the Detectron2DetectionModel obj's underlying member method code with example usage: obj.load_model() without return types