class_docstr: Object detector based on https://github.com/open-mmlab/mmdetection.
class_docstr_tok: ["Object","detector","based","on","https",":","\/\/github.com\/open-mmlab\/mmdetection","."]
code: def __init__(
      self,
      config_file=None,
      checkpoint_file=None,
      image_dir=None,
      labels_file=None,
      score_threshold=0.5,
      device="cpu",
      **kwargs,
  ):
      super(MMDetection, self).__init__(**kwargs)
      config_file = config_file or os.environ["config_file"]
      checkpoint_file = checkpoint_file or os.environ["checkpoint_file"]
      self.config_file = config_file
      self.checkpoint_file = checkpoint_file
      self.labels_file = labels_file
      # default Label Studio image upload folder
      upload_dir = os.path.join(get_data_dir(), "media", "upload")
      self.image_dir = image_dir or upload_dir
      logger.debug(
          f"{self.__class__.__name__} reads images from {self.image_dir}"
      )
      if self.labels_file and os.path.exists(self.labels_file):
          self.label_map = json_load(self.labels_file)
      else:
          self.label_map = {}
  
      (
          self.from_name,
          self.to_name,
          self.value,
          self.labels_in_config,
      ) = get_single_tag_keys(  # noqa E501
          self.parsed_label_config, "RectangleLabels", "Image"
      )
      schema = list(self.parsed_label_config.values())[0]
      self.labels_in_config = set(self.labels_in_config)
  
      # Collect label maps from `predicted_values="airplane,car"` attribute in <Label> tag # noqa E501
      self.labels_attrs = schema.get("labels_attrs")
      if self.labels_attrs:
          for label_name, label_attrs in self.labels_attrs.items():
              for predicted_value in label_attrs.get(
                  "predicted_values", ""
              ).split(","):
                  self.label_map[predicted_value] = label_name
  
      print("Load new model from: ", config_file, checkpoint_file)
      self.model = init_detector(
          config_file, checkpoint_file, device=device
      )
      self.score_thresh = score_threshold
  
file_path: mmdetection/projects/LabelStudio/backend_template/mmdetection.py
imports: import io
  import json
  import logging
  import os
  from urllib.parse import urlparse
  import boto3
  from botocore.exceptions import ClientError
  from label_studio_ml.model import LabelStudioMLBase
  from label_studio_ml.utils import DATA_UNDEFINED_NAME, get_image_size, get_single_tag_keys
  from label_studio_tools.core.utils.io import get_data_dir
  from mmdet.apis import inference_detector, init_detector
label_desc: Use image node_id 1 to create a new MMDetection object from inherited base classes: LabelStudioMLBase with example: obj = MMDetection(config_file, checkpoint_file, image_dir, labels_file, score_threshold, device)