code: def __init__(self, options, logger):
      # configuration setting
      self.opt = options
      self.logger = logger
      self.log_path = os.path.join(self.opt.log_dir, self.opt.model_zoo)
  
      # checking height and width are multiples of 32
      assert (
          self.opt.height % 32 == 0
      ), "'height' must be a multiple of 32"
      assert (
          self.opt.width % 32 == 0
      ), "'width' must be a multiple of 32"
  
      self.num_scales = len(self.opt.scales)
      self.num_input_frames = len(self.opt.frame_ids)
  
      assert self.opt.frame_ids[0] == 0, "frame_ids must start with 0"
  
      self.use_pose_net = not (
          self.opt.use_stereo and self.opt.frame_ids == [0]
      )
  
      if self.opt.use_stereo:
          self.opt.frame_ids.append("s")
  
      ######################### dataloader #########################
      datasets_dict = {
          "kitti": KITTIRAWDataset,
          "kitti_odom": KITTIOdomDataset,
      }
      self.dataset = datasets_dict[self.opt.dataset]
  
      fpath = os.path.join(
          os.path.expanduser("~"),
          ".mxnet/datasets/kitti",
          "splits",
          self.opt.split,
          "{}_files.txt",
      )
      train_filenames = readlines(fpath.format("train"))
      val_filenames = readlines(fpath.format("val"))
      img_ext = ".png" if self.opt.png else ".jpg"
  
      train_dataset = self.dataset(
          self.opt.data_path,
          train_filenames,
          self.opt.height,
          self.opt.width,
          self.opt.frame_ids,
          num_scales=4,
          is_train=True,
          img_ext=img_ext,
      )
      self.train_loader = gluon.data.DataLoader(
          train_dataset,
          batch_size=self.opt.batch_size,
          shuffle=True,
          batchify_fn=dict_batchify_fn,
          num_workers=self.opt.num_workers,
          pin_memory=True,
          last_batch="discard",
      )
  
      val_dataset = self.dataset(
          self.opt.data_path,
          val_filenames,
          self.opt.height,
          self.opt.width,
          self.opt.frame_ids,
          num_scales=4,
          is_train=False,
          img_ext=img_ext,
      )
      self.val_loader = gluon.data.DataLoader(
          val_dataset,
          batch_size=self.opt.batch_size,
          shuffle=False,
          batchify_fn=dict_batchify_fn,
          num_workers=self.opt.num_workers,
          pin_memory=True,
          last_batch="discard",
      )
  
      ################### model initialization ###################
      # create depth network
      if self.opt.model_zoo is not None:
          self.model = get_model(
              self.opt.model_zoo,
              pretrained_base=self.opt.pretrained_base,
              scales=self.opt.scales,
              ctx=self.opt.ctx,
          )
      else:
          assert (
              "Must choose a model from model_zoo, "
              "please provide depth the model_zoo using --model_zoo"
          )
      self.logger.info(self.model)
  
      # resume checkpoint if needed
      if self.opt.resume_depth is not None:
          if os.path.isfile(self.opt.resume_depth):
              logger.info(
                  "Resume depth model: %s" % self.opt.resume_depth
              )
              self.model.load_parameters(
                  self.opt.resume_depth, ctx=self.opt.ctx
              )
          else:
              raise RuntimeError(
                  "=> no checkpoint found at '{}'".format(
                      self.opt.resume_depth
                  )
              )
  
      if self.use_pose_net:
          # create pose network
          if self.opt.model_zoo_pose is not None:
              self.posenet = get_model(
                  self.opt.model_zoo_pose,
                  pretrained_base=self.opt.pretrained_base,
                  num_input_images=2,
                  num_input_features=1,
                  num_frames_to_predict_for=2,
                  ctx=self.opt.ctx,
              )
          else:
              assert (
                  "Must choose a model from model_zoo, "
                  "please provide the pose model_zoo_pose using --model_zoo_pose"
              )
          self.logger.info(self.posenet)
  
          # resume checkpoint if needed
          if self.opt.resume_pose is not None:
              if os.path.isfile(self.opt.resume_pose):
                  logger.info(
                      "Resume pose model: %s" % self.opt.resume_pose
                  )
                  self.model.load_parameters(
                      self.opt.resume_pose, ctx=self.opt.ctx
                  )
              else:
                  raise RuntimeError(
                      "=> no checkpoint found at '{}'".format(
                          self.opt.resume_pose
                      )
                  )
  
      if self.opt.hybridize:
          self.model.hybridize()
          self.posenet.hybridize()
  
      ################### optimization setting ###################
      self.lr_scheduler_depth = LRSequential(
          [
              LRScheduler(
                  "step",
                  base_lr=self.opt.learning_rate,
                  nepochs=self.opt.num_epochs - self.opt.warmup_epochs,
                  iters_per_epoch=len(self.train_loader),
                  step_epoch=[
                      self.opt.scheduler_step_size
                      - self.opt.warmup_epochs
                  ],
              )
          ]
      )
      optimizer_params_depth = {
          "lr_scheduler": self.lr_scheduler_depth,
          "learning_rate": self.opt.learning_rate,
      }
  
      self.depth_optimizer = gluon.Trainer(
          self.model.collect_params(), "adam", optimizer_params_depth
      )
  
      if self.use_pose_net:
          self.lr_scheduler_pose = LRSequential(
              [
                  LRScheduler(
                      "step",
                      base_lr=self.opt.learning_rate,
                      nepochs=self.opt.num_epochs
                      - self.opt.warmup_epochs,
                      iters_per_epoch=len(self.train_loader),
                      step_epoch=[
                          self.opt.scheduler_step_size
                          - self.opt.warmup_epochs
                      ],
                  )
              ]
          )
          optimizer_params_pose = {
              "lr_scheduler": self.lr_scheduler_pose,
              "learning_rate": self.opt.learning_rate,
          }
          self.pose_optimizer = gluon.Trainer(
              self.posenet.collect_params(),
              "adam",
              optimizer_params_pose,
          )
  
      print("Training model named:\n  ", self.opt.model_zoo)
      print("Models are saved to:\n  ", self.opt.log_dir)
      print(
          "Training is using:\n  ",
          "CPU" if self.opt.ctx[0] is mx.cpu() else "GPU",
      )
  
      ################### loss function ###################
      if not self.opt.no_ssim:
          self.ssim = SSIM()
  
      self.backproject_depth = {}
      self.project_3d = {}
      for scale in self.opt.scales:
          h = self.opt.height // (2**scale)
          w = self.opt.width // (2**scale)
  
          self.backproject_depth[scale] = BackprojectDepth(
              self.opt.batch_size, h, w, ctx=self.opt.ctx[0]
          )
          self.project_3d[scale] = Project3D(self.opt.batch_size, h, w)
  
      ################### metrics ###################
      self.depth_metric_names = [
          "de/abs_rel",
          "de/sq_rel",
          "de/rms",
          "de/log_rms",
          "da/a1",
          "da/a2",
          "da/a3",
      ]
  
      print("Using split:\n  ", self.opt.split)
      print(
          "There are {:d} training items and {:d} validation items\n".format(
              len(train_dataset), len(val_dataset)
          )
      )
  
      self.save_opts()
  
      # for save best model
      self.best_delta1 = 0
      self.best_model = self.model
  
      if self.use_pose_net:
          self.best_posenet = self.posenet
  
imports: from __future__ import absolute_import, division, print_function
  import os
  import sys
  import shutil
  import copy
  from tqdm import tqdm
  import numpy
  import json
  import mxnet
  from mxnet import gluon, autograd
  from gluoncv.data import KITTIRAWDataset, KITTIOdomDataset
  from gluoncv.data.kitti.kitti_utils import dict_batchify_fn, readlines
  from gluoncv.model_zoo import get_model
  from gluoncv.model_zoo.monodepthv2.layers import *
  from gluoncv.model_zoo.monodepthv2 import MonoDepth2PoseNet
  from gluoncv.utils import LRScheduler, LRSequential
label_desc: Use image node_id 1 to create a new Trainer object  with example: obj = Trainer(options, logger)