code: def __init__(self, args, logger):
      self.args = args
      self.logger = logger
  
      # image transform
      input_transform = transforms.Compose(
          [
              transforms.ToTensor(),
              transforms.Normalize(
                  [0.485, 0.456, 0.406], [0.229, 0.224, 0.225]
              ),
          ]
      )
  
      # dataset and dataloader
      data_kwargs = {
          "transform": input_transform,
          "base_size": args.base_size,
          "crop_size": args.crop_size,
      }
      trainset = get_segmentation_dataset(
          args.dataset,
          split=args.train_split,
          mode="train",
          **data_kwargs,
      )
      valset = get_segmentation_dataset(
          args.dataset, split="val", mode="val", **data_kwargs
      )
      self.train_data = gluon.data.DataLoader(
          trainset,
          args.batch_size,
          shuffle=True,
          last_batch="rollover",
          num_workers=args.workers,
      )
      self.eval_data = gluon.data.DataLoader(
          valset,
          args.test_batch_size,
          last_batch="rollover",
          num_workers=args.workers,
      )
  
      # create network
      if args.model_zoo is not None:
          model = get_model(
              args.model_zoo,
              norm_layer=args.norm_layer,
              norm_kwargs=args.norm_kwargs,
              aux=args.aux,
              base_size=args.base_size,
              crop_size=args.crop_size,
              pretrained=args.pretrained,
          )
      else:
          model = get_segmentation_model(
              model=args.model,
              dataset=args.dataset,
              backbone=args.backbone,
              norm_layer=args.norm_layer,
              norm_kwargs=args.norm_kwargs,
              aux=args.aux,
              base_size=args.base_size,
              crop_size=args.crop_size,
          )
      # for resnest use only
      from gluoncv.nn.dropblock import set_drop_prob
      from functools import partial
  
      apply_drop_prob = partial(set_drop_prob, 0.0)
      model.apply(apply_drop_prob)
  
      model.cast(args.dtype)
      logger.info(model)
  
      self.net = DataParallelModel(model, args.ctx, args.syncbn)
      self.evaluator = DataParallelModel(SegEvalModel(model), args.ctx)
      # resume checkpoint if needed
      if args.resume is not None:
          if os.path.isfile(args.resume):
              model.load_parameters(args.resume, ctx=args.ctx)
          else:
              raise RuntimeError(
                  "=> no checkpoint found at '{}'".format(args.resume)
              )
  
      # create criterion
      if "icnet" in args.model:
          criterion = ICNetLoss(crop_size=args.crop_size)
      elif "danet" in args.model or (
          args.model_zoo and "danet" in args.model_zoo
      ):
          criterion = SegmentationMultiLosses()
      else:
          criterion = MixSoftmaxCrossEntropyLoss(
              args.aux, aux_weight=args.aux_weight
          )
      self.criterion = DataParallelCriterion(
          criterion, args.ctx, args.syncbn
      )
  
      # optimizer and lr scheduling
      self.lr_scheduler = LRSequential(
          [
              LRScheduler(
                  "linear",
                  base_lr=0,
                  target_lr=args.lr,
                  nepochs=args.warmup_epochs,
                  iters_per_epoch=len(self.train_data),
              ),
              LRScheduler(
                  mode="poly",
                  base_lr=args.lr,
                  nepochs=args.epochs - args.warmup_epochs,
                  iters_per_epoch=len(self.train_data),
                  power=0.9,
              ),
          ]
      )
      kv = mx.kv.create(args.kvstore)
  
      if args.optimizer == "sgd":
          optimizer_params = {
              "lr_scheduler": self.lr_scheduler,
              "wd": args.weight_decay,
              "momentum": args.momentum,
              "learning_rate": args.lr,
          }
      elif args.optimizer == "adam":
          optimizer_params = {
              "lr_scheduler": self.lr_scheduler,
              "wd": args.weight_decay,
              "learning_rate": args.lr,
          }
      else:
          raise ValueError(
              "Unsupported optimizer {} used".format(args.optimizer)
          )
  
      if args.dtype == "float16":
          optimizer_params["multi_precision"] = True
  
      if args.no_wd:
          for k, v in self.net.module.collect_params(
              ".*beta|.*gamma|.*bias"
          ).items():
              v.wd_mult = 0.0
  
      self.optimizer = gluon.Trainer(
          self.net.module.collect_params(),
          args.optimizer,
          optimizer_params,
          kvstore=kv,
      )
      # evaluation metrics
      self.metric = gluoncv.utils.metrics.SegmentationMetric(
          trainset.num_class
      )
  
imports: import os
  import logging
  import shutil
  import argparse
  import numpy
  from tqdm import tqdm
  import mxnet
  from mxnet import gluon, autograd
  from mxnet.gluon.data.vision import transforms
  import gluoncv
  from gluoncv.loss import *
  from gluoncv.utils import makedirs, LRScheduler, LRSequential
  from gluoncv.model_zoo.segbase import *
  from gluoncv.model_zoo import get_model
  from gluoncv.utils.parallel import *
  from gluoncv.data import get_segmentation_dataset
label_desc: Use image node_id 1 to create a new Trainer object from inherited base classes: object with example: obj = Trainer(args, logger)