class_docstr: Sets up a standard trainer
  
  Args:
      device: gpu or cpu
      train_loader: the training data loader
      valid_loader: the validation data loader
      model: the (network) model
      optim: the optimizer
      logger:: the logger to log info
      output_dir: the path to save info
      cfg: a YACS config object.
class_docstr_tok: ["Sets","up","a","standard","trainer","Args",":","device",":","gpu","or","cpu","train_loader",":","the","training","data","loader","valid_loader",":","the","validation","data","loader","model",":","the","(","network",")","model","optim",":","the","optimizer","logger",":",":","the","logger","to","log","info","output_dir",":","the","path","to","save","info","cfg",":","a","YACS","config","object","."]
docstr: One training epoch
docstr_tok: ["One","training","epoch"]
code: def train_epoch(self):
      """One training epoch"""
      self.model.train()
      self.ce_loss = 0
      self.ortho_loss = 0
      self.ave_time = 0
      correct = 0
      total = 0
      epoch_t = time.time()
      for batch_idx, (inputs, targets) in enumerate(self.train_loader):
          iter_t = time.time()
          inputs, targets = inputs.to(self.device), targets.to(
              self.device
          )
          self.optim.zero_grad()
          batch_size = inputs.shape[0]
  
          outputs = self.model(inputs)
          loss = self.loss(outputs, targets)
          loss.backward()
          self.optim.step()
  
          _, predicted = outputs.max(1)
          total += batch_size
  
          correct += predicted.eq(targets).sum().item()
  
          self.ave_time += time.time() - iter_t
          tprint(
              f"train Epoch: {self.epochs} | {batch_idx + 1} / {len(self.train_loader)} | "
              f"Acc: {100. * correct / total:.3f} | CE: {self.ce_loss / (batch_idx + 1):.3f} | "
              f"O: {self.ortho_loss / (batch_idx + 1):.3f} | time: {self.ave_time / (batch_idx + 1):.3f}s"
          )
  
      info_str = (
          f"train Epoch: {self.epochs} | Acc: {100. * correct / total:.3f} | "
          f"CE: {self.ce_loss / (batch_idx + 1):.3f} | "
          f"time: {time.time() - epoch_t:.2f}s |"
      )
      self.logger.info(info_str)
      pprint_without_newline(info_str)
      self.train_acc.append(100.0 * correct / total)
  
file_path: pykale/examples/cifar_isonet/trainer.py
imports: import time
  import torch
  import torch.nn
  from kale.utils.print import pprint_without_newline, tprint
label_desc: Use image node_id 3 for calling the Trainer obj's underlying member method code with example usage: obj.train_epoch() without return types