class_docstr: Solver for raw tensorflow model.
class_docstr_tok: ["Solver","for","raw","tensorflow","model","."]
docstr: Train the model.
docstr_tok: ["Train","the","model","."]
code: def train(self):  # pylint: disable=too-many-locals
      """Train the model."""
      mode = utils.TRAIN
      train_model = self.build(mode)
  
      # Supervisor
      with tf.name_scope("train"):
          global_step = tf.train.get_or_create_global_step()
          train_op = self.get_train_op(train_model.loss_op, global_step)
  
          checkpoint_dir = get_checkpoint_dir(self.config)
  
          # scaffold
          scaffold = self.get_scaffold(
              mode, global_step, train_model.iterator.initializer
          )
  
      with tf.train.MonitoredTrainingSession(
          checkpoint_dir=checkpoint_dir,
          scaffold=scaffold,
          save_checkpoint_steps=self.save_checkpoint_steps,
          config=self.session_conf,
      ) as sess:
          # Training loop. For each batch...
          data_size = self.config["data"]["train_data_size"]
          num_epochs = self.config["data"]["task"]["epochs"]
          num_batch = int(
              math.ceil(data_size * num_epochs / self.batch_size)
          )
          num_batch_per_epoch = int(data_size / self.batch_size)
          logging.info(
              "num_batch: {}, num_batch_per_epoch: {}, num_epochs: {}".format(
                  num_batch, num_batch_per_epoch, num_epochs
              )
          )
          for i in range(num_batch):
              _, _, out_loss = sess.run(
                  [train_op, global_step, train_model.loss_op]
              )
              if i % self.print_every == 0 or i == num_batch - 1:
                  logging.info(
                      "Training for epoch {}: [ {:.2%} ] loss is {:g}".format(
                          int(i / num_batch_per_epoch),
                          (i % num_batch_per_epoch)
                          / num_batch_per_epoch,
                          out_loss,
                      )
                  )
  
imports: import re
  import math
  import numpy
  import delta.compat
  from absl import logging
  from delta.utils.solver.base_solver import Solver
  from delta import utils
  from delta.utils.register import registers
  from delta.utils.solver.utils.solver_utils import get_checkpoint_dir
  from delta.utils.solver.utils.solver_utils import get_ckpt_state
  from delta.utils.solver.utils.solver_utils import get_session_conf
  from delta.utils.solver.utils.solver_utils import to_saved_model
  from delta.utils.solver.utils.solver_utils import run_metrics
label_desc: Use image node_id 19 for calling the RawSolver obj's underlying member method code with example usage: obj.train() without return types