code: def finalize_configs(is_training):
      """
      Run some sanity checks, and populate some configs from others
      """
      _C.freeze(False)  # populate new keys now
      if isinstance(
          _C.DATA.VAL, six.string_types
      ):  # support single string (the typical case) as well
          _C.DATA.VAL = (_C.DATA.VAL,)
      if isinstance(
          _C.DATA.TRAIN, six.string_types
      ):  # support single string
          _C.DATA.TRAIN = (_C.DATA.TRAIN,)
  
      # finalize dataset definitions ...
      from dataset import DatasetRegistry
  
      datasets = list(_C.DATA.TRAIN) + list(_C.DATA.VAL)
      _C.DATA.CLASS_NAMES = DatasetRegistry.get_metadata(
          datasets[0], "class_names"
      )
      _C.DATA.NUM_CATEGORY = len(_C.DATA.CLASS_NAMES) - 1
  
      assert _C.BACKBONE.NORM in [
          "FreezeBN",
          "SyncBN",
          "GN",
          "None",
      ], _C.BACKBONE.NORM
      if _C.BACKBONE.NORM != "FreezeBN":
          assert not _C.BACKBONE.FREEZE_AFFINE
      assert _C.BACKBONE.FREEZE_AT in [0, 1, 2]
  
      _C.RPN.NUM_ANCHOR = len(_C.RPN.ANCHOR_SIZES) * len(
          _C.RPN.ANCHOR_RATIOS
      )
      assert len(_C.FPN.ANCHOR_STRIDES) == len(_C.RPN.ANCHOR_SIZES)
      # image size into the backbone has to be multiple of this number
      _C.FPN.RESOLUTION_REQUIREMENT = _C.FPN.ANCHOR_STRIDES[
          3
      ]  # [3] because we build FPN with features r2,r3,r4,r5
  
      if _C.MODE_FPN:
          size_mult = _C.FPN.RESOLUTION_REQUIREMENT * 1.0
          _C.PREPROC.MAX_SIZE = (
              np.ceil(_C.PREPROC.MAX_SIZE / size_mult) * size_mult
          )
          assert _C.FPN.PROPOSAL_MODE in ["Level", "Joint"]
          assert _C.FPN.FRCNN_HEAD_FUNC.endswith("_head")
          assert _C.FPN.MRCNN_HEAD_FUNC.endswith("_head")
          assert _C.FPN.NORM in ["None", "GN"]
  
          if _C.FPN.CASCADE:
              # the first threshold is the proposal sampling threshold
              assert _C.CASCADE.IOUS[0] == _C.FRCNN.FG_THRESH
              assert len(_C.CASCADE.BBOX_REG_WEIGHTS) == len(
                  _C.CASCADE.IOUS
              )
  
      if is_training:
          train_scales = _C.PREPROC.TRAIN_SHORT_EDGE_SIZE
          if (
              isinstance(train_scales, (list, tuple))
              and train_scales[1] - train_scales[0] > 100
          ):
              # don't autotune if augmentation is on
              os.environ["TF_CUDNN_USE_AUTOTUNE"] = "0"
          os.environ["TF_AUTOTUNE_THRESHOLD"] = "1"
          assert _C.TRAINER in ["horovod", "replicated"], _C.TRAINER
  
          lr = _C.TRAIN.LR_SCHEDULE
          if isinstance(lr, six.string_types):
              if lr.endswith("x"):
                  LR_SCHEDULE_KITER = {
                      "{}x".format(k): [
                          180 * k - 120,
                          180 * k - 40,
                          180 * k,
                      ]
                      for k in range(2, 10)
                  }
                  LR_SCHEDULE_KITER["1x"] = [120, 160, 180]
                  _C.TRAIN.LR_SCHEDULE = [
                      x * 1000 for x in LR_SCHEDULE_KITER[lr]
                  ]
              else:
                  _C.TRAIN.LR_SCHEDULE = eval(lr)
  
          # setup NUM_GPUS
          if _C.TRAINER == "horovod":
              import horovod.tensorflow as hvd
  
              ngpu = hvd.size()
              logger.info(
                  "Horovod Rank={}, Size={}, LocalRank={}".format(
                      hvd.rank(), hvd.size(), hvd.local_rank()
                  )
              )
          else:
              assert "OMPI_COMM_WORLD_SIZE" not in os.environ
              ngpu = get_num_gpu()
          assert ngpu > 0, "Has to train with GPU!"
          assert (
              ngpu % 8 == 0 or 8 % ngpu == 0
          ), "Can only train with 1,2,4 or >=8 GPUs, but found {} GPUs".format(
              ngpu
          )
      else:
          # autotune is too slow for inference
          os.environ["TF_CUDNN_USE_AUTOTUNE"] = "0"
          ngpu = get_num_gpu()
  
      if _C.TRAIN.NUM_GPUS is None:
          _C.TRAIN.NUM_GPUS = ngpu
      else:
          if _C.TRAINER == "horovod":
              assert _C.TRAIN.NUM_GPUS == ngpu
          else:
              assert _C.TRAIN.NUM_GPUS <= ngpu
  
      _C.freeze()
      logger.info(
          "Config: ------------------------------------------\n"
          + str(_C)
      )
  
file_path: tensorpack/examples/FasterRCNN/config.py
imports: import numpy
  import os
  import pprint
  import six
  from tensorpack.utils import logger
  from tensorpack.utils.gpu import get_num_gpu
label_desc: Use image node_id 1 for calling a global function with example usage: finalize_configs(is_training) without return types