code: def main(net, batch_size, epochs, opt, ctx):
      train_data, val_data = get_data_iters(batch_size)
      if opt.hybridize:
          net.hybridize()
  
      trainer = gluon.Trainer(
          net.collect_params(),
          "adam",
          {"learning_rate": opt.lr, "wd": opt.wd},
      )
      criterion = gluon.loss.SoftmaxCrossEntropyLoss()
  
      lr = opt.lr
      if opt.warmup:
          minlr = lr * 0.01
          dlr = (lr - minlr) / (epochs[0] - 1)
  
      prev_time = datetime.datetime.now()
      for epoch in range(epochs[-1]):
          _loss = 0.0
          if opt.warmup:
              if epoch < epochs[0]:
                  lr = minlr + dlr * epoch
          if epoch in epochs[1:]:
              lr = lr * opt.lr_decay
          trainer.set_learning_rate(lr)
  
          for data, label in train_data:
              data_list = gluon.utils.split_and_load(data, ctx)
              label_list = gluon.utils.split_and_load(label, ctx)
              with autograd.record():
                  output = [net(X) for X in data_list]
                  losses = [
                      criterion(X, y)
                      for X, y in zip(output, label_list)
                  ]
  
              for l in losses:
                  l.backward()
              trainer.step(batch_size)
              _loss_list = [l.mean().asscalar() for l in losses]
              _loss += sum(_loss_list) / len(_loss_list)
  
          cur_time = datetime.datetime.now()
          h, remainder = divmod((cur_time - prev_time).seconds, 3600)
          m, s = divmod(remainder, 60)
          time_str = "Time %02d:%02d:%02d" % (h, m, s)
          __loss = _loss / len(train_data)
  
          if val_data is not None:
              val_loss, val_accuracy = validate(
                  val_data, net, criterion, ctx
              )
              epoch_str = (
                  "Epoch %d. Train loss: %f, Val loss %f, Val accuracy %f, "
                  % (epoch, __loss, val_loss, val_accuracy)
              )
          else:
              epoch_str = "Epoch %d. Train loss: %f, " % (epoch, __loss)
  
          prev_time = cur_time
          print(
              epoch_str
              + time_str
              + ", lr "
              + str(trainer.learning_rate)
          )
  
      if not os.path.exists("params"):
          os.mkdir("params")
      net.save_parameters("params/resnet50.params")
  
file_path: gluon-cv/scripts/re-id/baseline/train.py
imports: from __future__ import division
  import argparse, datetime, os
  import logging
  import mxnet
  from mxnet import gluon, nd
  from mxnet.gluon.model_zoo import vision
  from mxnet.gluon.data.vision import transforms
  from mxnet import autograd
  from networks import resnet18, resnet34, resnet50
  import gluoncv
  from gluoncv.data.market1501.data_read import ImageTxtDataset
  from gluoncv.data.market1501.label_read import LabelList
  from gluoncv.data.transforms.block import RandomCrop
label_desc: Use image node_id 3 for calling a global function with example usage: main(net, batch_size, epochs, opt, ctx) without return types