code: def train(
      opt, net, train_loader, criterion, trainer, batch_size, logger
  ):
      """train model"""
      for epoch in range(opt.start_epoch, opt.epochs):
          loss_total_val = 0
          loss_loc_val = 0
          loss_cls_val = 0
          batch_time = time.time()
          for i, data in enumerate(train_loader):
              (
                  template,
                  search,
                  label_cls,
                  label_loc,
                  label_loc_weight,
              ) = train_batch_fn(data, opt)
              cls_losses = []
              loc_losses = []
              total_losses = []
              with autograd.record():
                  for j in range(len(opt.ctx)):
                      cls, loc = net(template[j], search[j])
                      label_cls_temp = (
                          label_cls[j].reshape(-1).asnumpy()
                      )
                      pos_index = np.argwhere(
                          label_cls_temp == 1
                      ).reshape(-1)
                      neg_index = np.argwhere(
                          label_cls_temp == 0
                      ).reshape(-1)
                      if len(pos_index):
                          pos_index = nd.array(
                              pos_index, ctx=opt.ctx[j]
                          )
                      else:
                          pos_index = nd.array(
                              np.array([]), ctx=opt.ctx[j]
                          )
                      if len(neg_index):
                          neg_index = nd.array(
                              neg_index, ctx=opt.ctx[j]
                          )
                      else:
                          neg_index = nd.array(
                              np.array([]), ctx=opt.ctx[j]
                          )
                      cls_loss, loc_loss = criterion(
                          cls,
                          loc,
                          label_cls[j],
                          pos_index,
                          neg_index,
                          label_loc[j],
                          label_loc_weight[j],
                      )
                      total_loss = (
                          opt.cls_weight * cls_loss
                          + opt.loc_weight * loc_loss
                      )
                      cls_losses.append(cls_loss)
                      loc_losses.append(loc_loss)
                      total_losses.append(total_loss)
  
                  mx.nd.waitall()
                  if opt.use_amp:
                      with amp.scale_loss(
                          total_losses, trainer
                      ) as scaled_loss:
                          autograd.backward(scaled_loss)
                  else:
                      autograd.backward(total_losses)
              trainer.step(batch_size)
              loss_total_val += sum(
                  [l.mean().asscalar() for l in total_losses]
              ) / len(total_losses)
              loss_loc_val += sum(
                  [l.mean().asscalar() for l in loc_losses]
              ) / len(loc_losses)
              loss_cls_val += sum(
                  [l.mean().asscalar() for l in cls_losses]
              ) / len(cls_losses)
              if i % (opt.log_interval) == 0:
                  logger.info(
                      "Epoch %d iteration %04d/%04d: loc loss %.3f, cls loss %.3f, \
                               training loss %.3f, batch time %.3f"
                      % (
                          epoch,
                          i,
                          len(train_loader),
                          loss_loc_val / (i + 1),
                          loss_cls_val / (i + 1),
                          loss_total_val / (i + 1),
                          time.time() - batch_time,
                      )
                  )
                  batch_time = time.time()
              mx.nd.waitall()
          # save every epoch
          if opt.no_val:
              save_checkpoint(net, opt, epoch, False)
  
imports: from __future__ import absolute_import
  from __future__ import division
  from __future__ import print_function
  from __future__ import unicode_literals
  import argparse
  import logging
  import os
  import time
  import numpy
  import mxnet
  from mxnet import gluon, nd, autograd
  from mxnet.contrib import amp
  from gluoncv.utils import LRScheduler, LRSequential, split_and_load
  from gluoncv.data.tracking_data.track import TrkDataset
  from gluoncv.model_zoo import get_model
  from gluoncv.loss import SiamRPNLoss
label_desc: Use image node_id 6 for calling a global function with example usage: train(opt, net, train_loader, criterion, trainer, batch_size, logger) without return types