code: def run(self):
      print("training...")
  
      for epoch in range(self.start_epoch, self.nepochs + 1):
          if epoch in self.alpha_milestones:
              self.loss.alpha = self.loss.alpha * self.alpha_factor
  
          if epoch % 100 == 0 and epoch != 0:
              self.save_checkpoints(epoch)
  
          if epoch % self.plot_freq == 0 and epoch != 0:
              self.model.eval()
              if self.train_cameras:
                  self.pose_vecs.eval()
              self.train_dataset.change_sampling_idx(-1)
              indices, model_input, ground_truth = next(
                  iter(self.plot_dataloader)
              )
  
              model_input["intrinsics"] = model_input[
                  "intrinsics"
              ].cuda()
              model_input["uv"] = model_input["uv"].cuda()
              model_input["object_mask"] = model_input[
                  "object_mask"
              ].cuda()
              # model_input[""] = ground_truth["rgb"].cuda()
  
              if self.train_cameras:
                  pose_input = self.pose_vecs(indices.cuda())
                  model_input["pose"] = pose_input
              else:
                  model_input["pose"] = model_input["pose"].cuda()
  
              (
                  detail_3dmm,
                  detail_3dmm_subdivision_full,
              ) = plt.get_displacement_mesh(self.model)
              detail_3dmm.export(
                  "{0}/Detailed_3dmm_{1}.obj".format(
                      self.plots_dir, epoch
                  ),
                  "obj",
              )
              detail_3dmm_subdivision_full.export(
                  "{0}/Subdivide_full_{1}.obj".format(
                      self.plots_dir, epoch
                  ),
                  "obj",
              )
  
              self.model.train()
              if self.train_cameras:
                  self.pose_vecs.train()
  
          self.train_dataset.change_sampling_idx(self.num_pixels)
  
          if epoch > self.nepoch_freeze:
              print("Freeze Diffuse Part...")
              self.model.diffuse_network.eval()
              self.model.albedo_network.eval()
  
          for data_index, (
              indices,
              model_input,
              ground_truth,
          ) in enumerate(self.train_dataloader):
              model_input["intrinsics"] = model_input[
                  "intrinsics"
              ].cuda()
              model_input["uv"] = model_input["uv"].cuda()
              model_input["object_mask"] = model_input[
                  "object_mask"
              ].cuda()
  
              if self.train_cameras:
                  pose_input = self.pose_vecs(indices.cuda())
                  model_input["pose"] = pose_input
              else:
                  model_input["pose"] = model_input["pose"].cuda()
  
              model_outputs = self.model(model_input)
              loss_output = self.loss(model_outputs, ground_truth)
  
              loss = loss_output["loss"]
  
              self.optimizer.zero_grad()
              if self.train_cameras:
                  self.optimizer_cam.zero_grad()
  
              loss.backward()
  
              self.optimizer.step()
              if self.train_cameras:
                  self.optimizer_cam.step()
  
              print(
                  "{0} [{1}] ({2}/{3}): loss = {4}, rgb_loss = {5}, normal_loss = {6}, reg_loss = {7}, eikonal_loss = {8}, mask_loss = {9}, alpha = {10}, lr = {11}".format(
                      self.expname,
                      epoch,
                      data_index,
                      self.n_batches,
                      loss.item(),
                      loss_output["rgb_loss"].item(),
                      loss_output["normal_loss"].item(),
                      loss_output["reg_loss"].item(),
                      loss_output["eikonal_loss"].item(),
                      loss_output["mask_loss"].item(),
                      self.loss.alpha,
                      self.scheduler.get_lr()[0],
                  )
              )
  
          self.scheduler.step()
  
file_path: insightface/reconstruction/PBIDR/code/training/train.py
imports: import os
  from datetime import datetime
  from pyhocon import ConfigFactory
  import sys
  import torch
  import torch.nn
  import utils.general
  import utils.plots
label_desc: Use image node_id 3 for calling the IFTrainRunner obj's underlying member method code with example usage: obj.run() without return types