code: def train(net, train_data, val_data, eval_metric, ctx, args):
      """Training pipeline"""
      net.collect_params().reset_ctx(ctx)
      # lr decay policy
      lr_decay = float(args.lr_decay)
      lr_steps = sorted(
          [
              int(ls)
              for ls in args.lr_decay_epoch.split(",")
              if ls.strip()
          ]
      )
      lr_decay_epoch = [e - args.warmup_epochs for e in lr_steps]
      num_batches = args.num_samples // args.batch_size
      lr_scheduler = LRSequential(
          [
              LRScheduler(
                  "linear",
                  base_lr=0,
                  target_lr=args.lr,
                  nepochs=args.warmup_epochs,
                  iters_per_epoch=num_batches,
              ),
              LRScheduler(
                  args.lr_mode,
                  base_lr=args.lr,
                  nepochs=args.epochs - args.warmup_epochs,
                  iters_per_epoch=num_batches,
                  step_epoch=lr_decay_epoch,
                  step_factor=args.lr_decay,
                  power=2,
              ),
          ]
      )
  
      for k, v in net.collect_params(".*bias").items():
          v.wd_mult = 0.0
      trainer = gluon.Trainer(
          net.collect_params(),
          "adam",
          {
              "learning_rate": args.lr,
              "wd": args.wd,
              "lr_scheduler": lr_scheduler,
          },
      )
  
      heatmap_loss = gcv.loss.HeatmapFocalLoss(from_logits=True)
      wh_loss = gcv.loss.MaskedL1Loss(weight=args.wh_weight)
      center_reg_loss = gcv.loss.MaskedL1Loss(
          weight=args.center_reg_weight
      )
      heatmap_loss_metric = mx.metric.Loss("HeatmapFocal")
      wh_metric = mx.metric.Loss("WHL1")
      center_reg_metric = mx.metric.Loss("CenterRegL1")
  
      # set up logger
      logging.basicConfig()
      logger = logging.getLogger()
      logger.setLevel(logging.INFO)
      log_file_path = args.save_prefix + "_train.log"
      log_dir = os.path.dirname(log_file_path)
      if log_dir and not os.path.exists(log_dir):
          os.makedirs(log_dir)
      fh = logging.FileHandler(log_file_path)
      logger.addHandler(fh)
      logger.info(args)
      logger.info(
          "Start training from [Epoch {}]".format(args.start_epoch)
      )
      best_map = [0]
  
      for epoch in range(args.start_epoch, args.epochs):
          wh_metric.reset()
          center_reg_metric.reset()
          tic = time.time()
          btic = time.time()
          net.hybridize()
  
          for i, batch in enumerate(train_data):
              split_data = [
                  gluon.utils.split_and_load(
                      batch[ind], ctx_list=ctx, batch_axis=0
                  )
                  for ind in range(6)
              ]
              (
                  data,
                  heatmap_targets,
                  wh_targets,
                  wh_masks,
                  center_reg_targets,
                  center_reg_masks,
              ) = split_data
              batch_size = args.batch_size
              with autograd.record():
                  sum_losses = []
                  heatmap_losses = []
                  wh_losses = []
                  center_reg_losses = []
                  wh_preds = []
                  center_reg_preds = []
                  for (
                      x,
                      heatmap_target,
                      wh_target,
                      wh_mask,
                      center_reg_target,
                      center_reg_mask,
                  ) in zip(*split_data):
                      heatmap_pred, wh_pred, center_reg_pred = net(x)
                      wh_preds.append(wh_pred)
                      center_reg_preds.append(center_reg_pred)
                      wh_losses.append(
                          wh_loss(wh_pred, wh_target, wh_mask)
                      )
                      center_reg_losses.append(
                          center_reg_loss(
                              center_reg_pred,
                              center_reg_target,
                              center_reg_mask,
                          )
                      )
                      heatmap_losses.append(
                          heatmap_loss(heatmap_pred, heatmap_target)
                      )
                      curr_loss = (
                          heatmap_losses[-1]
                          + wh_losses[-1]
                          + center_reg_losses[-1]
                      )
                      sum_losses.append(curr_loss)
                  autograd.backward(sum_losses)
              trainer.step(len(sum_losses))  # step with # gpus
  
              heatmap_loss_metric.update(0, heatmap_losses)
              wh_metric.update(0, wh_losses)
              center_reg_metric.update(0, center_reg_losses)
              if args.log_interval and not (i + 1) % args.log_interval:
                  name2, loss2 = wh_metric.get()
                  name3, loss3 = center_reg_metric.get()
                  name4, loss4 = heatmap_loss_metric.get()
                  logger.info(
                      "[Epoch {}][Batch {}], Speed: {:.3f} samples/sec, LR={}, {}={:.3f}, {}={:.3f}, {}={:.3f}".format(
                          epoch,
                          i,
                          batch_size / (time.time() - btic),
                          trainer.learning_rate,
                          name2,
                          loss2,
                          name3,
                          loss3,
                          name4,
                          loss4,
                      )
                  )
              btic = time.time()
  
          name2, loss2 = wh_metric.get()
          name3, loss3 = center_reg_metric.get()
          name4, loss4 = heatmap_loss_metric.get()
          logger.info(
              "[Epoch {}] Training cost: {:.3f}, {}={:.3f}, {}={:.3f}, {}={:.3f}".format(
                  epoch,
                  (time.time() - tic),
                  name2,
                  loss2,
                  name3,
                  loss3,
                  name4,
                  loss4,
              )
          )
          if (
              (epoch % args.val_interval == 0)
              or (
                  args.save_interval and epoch % args.save_interval == 0
              )
              or (epoch == args.epochs - 1)
          ):
              # consider reduce the frequency of validation to save time
              map_name, mean_ap = validate(
                  net,
                  val_data,
                  ctx,
                  eval_metric,
                  flip_test=args.flip_validation,
              )
              val_msg = "\n".join(
                  [
                      "{}={}".format(k, v)
                      for k, v in zip(map_name, mean_ap)
                  ]
              )
              logger.info(
                  "[Epoch {}] Validation: \n{}".format(epoch, val_msg)
              )
              current_map = float(mean_ap[-1])
          else:
              current_map = 0.0
          save_params(
              net,
              best_map,
              current_map,
              epoch,
              args.save_interval,
              args.save_prefix,
          )
  
imports: import argparse
  import os
  import logging
  import warnings
  import time
  import numpy
  import mxnet
  from mxnet import nd
  from mxnet import gluon
  from mxnet import autograd
  import gluoncv
  from gluoncv import data
  from gluoncv import utils
  from gluoncv.model_zoo import get_model
  from gluoncv.data.batchify import Tuple, Stack, Pad
  from gluoncv.data.transforms.presets.center_net import CenterNetDefaultTrainTransform
  from gluoncv.data.transforms.presets.center_net import CenterNetDefaultValTransform, get_post_transform
  from gluoncv.utils.metrics.voc_detection import VOC07MApMetric
  from gluoncv.utils.metrics.coco_detection import COCODetectionMetric
  from gluoncv.utils.metrics.accuracy import Accuracy
  from gluoncv.utils import LRScheduler, LRSequential
label_desc: Use image node_id 6 for calling a global function with example usage: train(net, train_data, val_data, eval_metric, ctx, args) without return types