code: def main():
      parser = argparse.ArgumentParser(description="PyTorch Example")
      parser.add_argument("--dataset", type=str, help="path to dataset")
      parser.add_argument(
          "--cluster_mode",
          type=str,
          default="local",
          help="The cluster mode, such as local, yarn-client, yarn-cluster",
      )
      parser.add_argument(
          "--config", type=str, help="The path of config file"
      )
      parser.add_argument(
          "--cores",
          type=int,
          default=8,
          help="The number of cores on each node.",
      )
      parser.add_argument(
          "--num_nodes",
          type=int,
          default=1,
          help="The number of nodes to use.",
      )
      parser.add_argument(
          "--workers_per_node",
          default=1,
          type=int,
          help="The number of torch runners on each node.",
      )
      parser.add_argument(
          "--validate",
          default=True,
          type=bool,
          help="whether do validation during training",
      )
      parser.add_argument(
          "--load_from",
          default=None,
          type=str,
          help="checkpoint path to resume model",
      )
      args = parser.parse_args()
  
      if args.cluster_mode == "local":
          init_orca_context("local", cores=args.cores, memory="10g")
      elif args.cluster_mode.startswith("yarn"):
          additional = None
          if exists(join(args.dataset, "kitti_tiny.zip")):
              additional = join(
                  args.dataset, "kitti_tiny.zip#", args.dataset
              )
          init_orca_context(
              cluster_mode="yarn-client",
              cores=args.cores,
              memory="4g",
              num_nodes=args.num_nodes,
              driver_cores=4,
              driver_memory="2g",
              additional_archive=additional,
          )
      else:
          print(
              "init_orca_context failed. cluster_mode should be one of 'local', 'yarn-client', "
              "but got" + args.cluster_mode
          )
  
      cfg = Config.fromfile(args.config)
      cfg.distributed = True
      cfg.validate = args.validate
  
      # Modify dataset type and path
      cfg.dataset_type = "KittiTinyDataset"
      cfg.data_root = args.dataset
  
      cfg.data.test.type = "KittiTinyDataset"
      cfg.data.test.data_root = args.dataset
      cfg.data.test.ann_file = "train.txt"
      cfg.data.test.img_prefix = "training/image_2"
  
      cfg.data.train.type = "KittiTinyDataset"
      cfg.data.train.data_root = args.dataset
      cfg.data.train.ann_file = "train.txt"
      cfg.data.train.img_prefix = "training/image_2"
  
      cfg.data.val.type = "KittiTinyDataset"
      cfg.data.val.data_root = args.dataset
      cfg.data.val.ann_file = "val.txt"
      cfg.data.val.img_prefix = "training/image_2"
  
      # modify num classes of the model in box head
      cfg.model.roi_head.bbox_head.num_classes = 3
  
      # If we need to finetune a model based on a pre-trained detector, we need to
      # use load_from to set the path of checkpoints.
      cfg.load_from = args.load_from
  
      # Set up working dir to save files and logs.
      cfg.work_dir = "./tutorial_exps"
  
      cfg.optimizer.lr = 0.02 / 8
      cfg.lr_config.warmup = None
  
      cfg.runner.max_epochs = 1
      # Change the evaluation metric since we use customized dataset.
      cfg.evaluation.metric = "mAP"
      # We can set the evaluation interval to reduce the evaluation times
      cfg.evaluation.interval = 1
      # We can set the checkpoint saving interval to reduce the storage cost
      cfg.checkpoint_config.interval = 1
      cfg.log_config.interval = 10
  
      # Set seed thus the results are more reproducible
      cfg.seed = 0
      set_random_seed(0, deterministic=False)
      cfg.device = "cpu"
      cfg.gpu_ids = [0]
  
      # We can also use tensorboard to log the training process
      cfg.log_config.hooks = [
          dict(type="TextLoggerHook"),
          dict(type="TensorboardLoggerHook"),
      ]
  
      print(f"Config:\n{cfg.pretty_text}")
  
      estimator = MMCVRayEstimator(
          mmcv_runner_creator=mmcv_runner_creator,
          config=cfg,
          workers_per_node=args.workers_per_node,
      )
      estimator.run([dataloader_creator], cfg.workflow)
      stop_orca_context()
  
file_path: BigDL/python/orca/example/learn/mmcv/faster_rcnn/train.py
imports: import argparse
  import os
  import numpy
  import os.path
  from os.path import exists, join
  from bigdl.orca import init_orca_context, stop_orca_context
  from bigdl.orca.data.file import get_remote_dir_to_local
  from bigdl.orca.learn.pytorch.experimential.mmcv.mmcv_ray_estimator import MMCVRayEstimator
  import mmcv
  from mmcv import Config
  from mmdet.apis import set_random_seed
  from mmdet.datasets import build_dataloader, build_dataset, replace_ImageToTensor
label_desc: Use image node_id 3 for calling a global function with example usage: main() without return types