code: def main():
      parser = argparse.ArgumentParser()
      parser.add_argument(
          "--model",
          choices=(
              "mask_rcnn_fpn_resnet50",
              "mask_rcnn_fpn_resnet101",
              "faster_rcnn_fpn_resnet50",
              "faster_rcnn_fpn_resnet101",
          ),
          default="faster_rcnn_fpn_resnet50",
      )
      parser.add_argument("--batchsize", type=int, default=16)
      parser.add_argument("--iteration", type=int, default=90000)
      parser.add_argument(
          "--step", type=int, nargs="*", default=[60000, 80000]
      )
      parser.add_argument("--out", default="result")
      parser.add_argument("--resume")
      args = parser.parse_args()
  
      # https://docs.chainer.org/en/stable/chainermn/tutorial/tips_faqs.html#using-multiprocessiterator
      if hasattr(multiprocessing, "set_start_method"):
          multiprocessing.set_start_method("forkserver")
          p = multiprocessing.Process()
          p.start()
          p.join()
  
      comm = chainermn.create_communicator("pure_nccl")
      device = comm.intra_rank
  
      if args.model == "faster_rcnn_fpn_resnet50":
          mode = "bbox"
          model = FasterRCNNFPNResNet50(
              n_fg_class=len(coco_bbox_label_names),
              pretrained_model="imagenet",
          )
      elif args.model == "faster_rcnn_fpn_resnet101":
          mode = "bbox"
          model = FasterRCNNFPNResNet101(
              n_fg_class=len(coco_bbox_label_names),
              pretrained_model="imagenet",
          )
      elif args.model == "mask_rcnn_fpn_resnet50":
          mode = "instance_segmentation"
          model = MaskRCNNFPNResNet50(
              n_fg_class=len(coco_instance_segmentation_label_names),
              pretrained_model="imagenet",
          )
      elif args.model == "mask_rcnn_fpn_resnet101":
          mode = "instance_segmentation"
          model = MaskRCNNFPNResNet101(
              n_fg_class=len(coco_instance_segmentation_label_names),
              pretrained_model="imagenet",
          )
  
      model.use_preset("evaluate")
      train_chain = TrainChain(model)
      chainer.cuda.get_device_from_id(device).use()
      train_chain.to_gpu()
  
      if mode == "bbox":
          train = TransformDataset(
              COCOBboxDataset(year="2017", split="train"),
              ("img", "bbox", "label"),
              Transform(800, 1333, model.extractor.mean),
          )
      elif mode == "instance_segmentation":
          train = TransformDataset(
              COCOInstanceSegmentationDataset(
                  split="train", return_bbox=True
              ),
              ("img", "bbox", "label", "mask"),
              Transform(800, 1333, model.extractor.mean),
          )
  
      if comm.rank == 0:
          indices = np.arange(len(train))
      else:
          indices = None
      indices = chainermn.scatter_dataset(indices, comm, shuffle=True)
      train = train.slice[indices]
  
      train_iter = chainer.iterators.MultiprocessIterator(
          train,
          args.batchsize // comm.size,
          n_processes=args.batchsize // comm.size,
          shared_mem=100 * 1000 * 1000 * 4,
      )
  
      optimizer = chainermn.create_multi_node_optimizer(
          chainer.optimizers.MomentumSGD(), comm
      )
      optimizer.setup(train_chain)
      optimizer.add_hook(WeightDecay(0.0001))
  
      model.extractor.base.conv1.disable_update()
      model.extractor.base.res2.disable_update()
      for link in model.links():
          if isinstance(link, L.BatchNormalization):
              link.disable_update()
  
      n_iteration = args.iteration * 16 / args.batchsize
      updater = training.updaters.StandardUpdater(
          train_iter, optimizer, converter=converter, device=device
      )
      trainer = training.Trainer(
          updater, (n_iteration, "iteration"), args.out
      )
  
      @make_shift("lr")
      def lr_schedule(trainer):
          base_lr = 0.02 * args.batchsize / 16
          warm_up_duration = 500
          warm_up_rate = 1 / 3
  
          iteration = trainer.updater.iteration
          if iteration < warm_up_duration:
              rate = (
                  warm_up_rate
                  + (1 - warm_up_rate) * iteration / warm_up_duration
              )
          else:
              rate = 1
              for step in args.step:
                  if iteration >= step * 16 / args.batchsize:
                      rate *= 0.1
  
          return base_lr * rate
  
      trainer.extend(lr_schedule)
  
      if comm.rank == 0:
          log_interval = 10, "iteration"
          trainer.extend(extensions.LogReport(trigger=log_interval))
          trainer.extend(extensions.observe_lr(), trigger=log_interval)
          trainer.extend(
              extensions.PrintReport(
                  [
                      "epoch",
                      "iteration",
                      "lr",
                      "main/loss",
                      "main/loss/rpn/loc",
                      "main/loss/rpn/conf",
                      "main/loss/bbox_head/loc",
                      "main/loss/bbox_head/conf",
                      "main/loss/mask_head",
                  ]
              ),
              trigger=log_interval,
          )
          trainer.extend(extensions.ProgressBar(update_interval=10))
  
          trainer.extend(
              extensions.snapshot(), trigger=(10000, "iteration")
          )
          trainer.extend(
              extensions.snapshot_object(
                  model, "model_iter_{.updater.iteration}"
              ),
              trigger=(n_iteration, "iteration"),
          )
  
      if args.resume:
          serializers.load_npz(args.resume, trainer, strict=False)
  
      trainer.run()
  
imports: from __future__ import division
  import argparse
  import multiprocessing
  import numpy
  import PIL
  import chainer
  import chainer.functions
  import chainer.links
  from chainer.optimizer_hooks import WeightDecay
  from chainer import serializers
  from chainer import training
  from chainer.training import extensions
  import chainermn
  from chainercv.chainer_experimental.datasets.sliceable import TransformDataset
  from chainercv.chainer_experimental.training.extensions import make_shift
  from chainercv.links.model.fpn.misc import scale_img
  from chainercv import transforms
  from chainercv.datasets import coco_instance_segmentation_label_names
  from chainercv.datasets import COCOInstanceSegmentationDataset
  from chainercv.links import MaskRCNNFPNResNet101
  from chainercv.links import MaskRCNNFPNResNet50
  from chainercv.datasets import coco_bbox_label_names
  from chainercv.datasets import COCOBboxDataset
  from chainercv.links import FasterRCNNFPNResNet101
  from chainercv.links import FasterRCNNFPNResNet50
  from chainercv.links.model.fpn import bbox_head_loss_post
  from chainercv.links.model.fpn import bbox_head_loss_pre
  from chainercv.links.model.fpn import mask_head_loss_post
  from chainercv.links.model.fpn import mask_head_loss_pre
  from chainercv.links.model.fpn import rpn_loss
label_desc: Use image node_id 2 for calling a global function with example usage: main() and returns: unknown