code: def train(
      self,
      total_iter,
      eval_iter,
      save_iter,
      train_sampler,
      start_iter=0,
      eval_samplers=[],
      evaluators=[],
  ):
      acc_loss = 0
      self._eval_manager = EvalManager(evaluators=evaluators)
  
      train_sampler.reset()
      for sampler in eval_samplers:
          sampler.reset()
  
      print(
          colored(
              "[Training starts, total_iter: %d, eval_iter: %d, save_iter: %d]"
              % (total_iter, eval_iter, save_iter),
              "blue",
          )
      )
  
      for _iter in range(total_iter):
          batch_data = train_sampler.next_batch()
          loss = self._train_iter_func(self._model, batch_data)
          acc_loss += loss
          self._trained_it += 1
          print("..Trained for %d iterations." % _iter, end="\r")
          if (_iter + 1) % save_iter == 0:
              self._model.save(global_step=self._trained_it)
              print(
                  " " * len("..Trained for %d iterations." % _iter),
                  end="\r",
              )
              print(
                  colored("[iter %d]" % self._trained_it, "red"),
                  "Model saved.",
              )
          if (_iter + 1) % eval_iter == 0:
              print(
                  " " * len("..Trained for %d iterations." % _iter),
                  end="\r",
              )
              print(
                  colored("[iter %d]" % self._trained_it, "red"),
                  "loss: %f" % (acc_loss / eval_iter),
              )
              for sampler in eval_samplers:
                  print(
                      colored(
                          "..(dataset: %s) evaluation" % sampler.name,
                          "green",
                      )
                  )
                  sys.stdout.flush()
                  eval_results = self._evaluate(sampler)
                  for key, result in eval_results.items():
                      average_result = np.mean(result, axis=0)
                      if type(average_result) is np.ndarray:
                          print(
                              colored(
                                  "..(dataset: %s)" % sampler.name,
                                  "green",
                              ),
                              key,
                              " ".join(
                                  [str(s) for s in average_result]
                              ),
                          )
                      else:
                          print(
                              colored(
                                  "..(dataset: %s)" % sampler.name,
                                  "green",
                              ),
                              key,
                              average_result,
                          )
              acc_loss = 0
  
file_path: openrec/openrec/tf1/model_trainer.py
imports: from __future__ import print_function
  from openrec.tf1.utils.evaluators import EvalManager
  from termcolor import colored
  import sys
  import numpy
label_desc: Use image node_id 5 for calling the ModelTrainer obj's underlying member method code with example usage: obj.train(total_iter, eval_iter, save_iter, train_sampler, start_iter, eval_samplers, evaluators) without return types