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: The validation step
docstr_tok: ["The","validation","step"]
code: def valid(self):
      """The validation step"""
      self.model.eval()
      self.ce_loss = 0
      self.ortho_loss = 0
      correct = 0
      total = 0
      with torch.no_grad():
          for batch_idx, (inputs, targets) in enumerate(
              self.valid_loader
          ):
              inputs, targets = inputs.to(self.device), targets.to(
                  self.device
              )
              outputs = self.model(inputs)
              # loss = self.loss(outputs, targets)
  
              _, predicted = outputs.max(1)
              total += targets.size(0)
              correct += predicted.eq(targets).sum().item()
  
      if 100.0 * correct / total > self.best_valid_acc:
          self.snapshot("best")
      self.snapshot("latest")
      self.best_valid_acc = max(
          self.best_valid_acc, 100.0 * correct / total
      )
      info_str = (
          f"valid | Acc: {100. * correct / total:.3f} | "
          f"CE: {self.ce_loss / len(self.valid_loader):.3f} | "
          f"O: {self.ortho_loss / len(self.valid_loader):.3f} | "
          f"best: {self.best_valid_acc:.3f} | "
      )
      print(info_str)
      self.logger.info(info_str)
      self.valid_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 4 for calling the Trainer obj's underlying member method code with example usage: obj.valid() without return types