class_docstr: Implementation of a Basic Iterative Pruner.
  Any iterative pruning technique can be extended from this by implementing the `prune_model` method.
  
  :param model: Model that needs to be pruned
  :type model: torch.nn.Module
  :param train_loader: Dataloader for training
  :type train_loader: torch.utils.data.DataLoader
  :param test_loader: Dataloader for validation/testing
  :type test_loader: torch.utils.data.DataLoader
  :param loss_fn: Loss function to be used for training
  :type loss_fn: torch.nn.Module
  :param device: Device used for implementation ("cpu" by default)
  :type device: torch.device
class_docstr_tok: ["Implementation","of","a","Basic","Iterative","Pruner",".","Any","iterative","pruning","technique","can","be","extended","from","this","by","implementing","the","`","prune_model","`","method",".",":","param","model",":","Model","that","needs","to","be","pruned",":","type","model",":","torch.nn.Module",":","param","train_loader",":","Dataloader","for","training",":","type","train_loader",":","torch.utils.data.DataLoader",":","param","test_loader",":","Dataloader","for","validation\/testing",":","type","test_loader",":","torch.utils.data.DataLoader",":","param","loss_fn",":","Loss","function","to","be","used","for","training",":","type","loss_fn",":","torch.nn.Module",":","param","device",":","Device","used","for","implementation","(","``","cpu","''","by","default",")",":","type","device",":","torch.device"]
docstr: Function used for evaluating a model
  
  :param model_path: Path to a PyTorch model that needs to be evaluated. If None, current final model is used.
  :type model_path: str
docstr_tok: ["Function","used","for","evaluating","a","model",":","param","model_path",":","Path","to","a","PyTorch","model","that","needs","to","be","evaluated",".","If","None",",","current","final","model","is","used",".",":","type","model_path",":","str"]
code: def evaluate_model(self, model_path=None):
      """
      Function used for evaluating a model
  
      :param model_path: Path to a PyTorch model that needs to be evaluated. If None, current final model is used.
      :type model_path: str
      """
  
      model = copy.deepcopy(self.model)
      if model_path:
          model.load_state_dict(torch.load(model_path))
  
      model.eval()
      test_loss = 0
      correct = 0
  
      with torch.no_grad():
          for data, targets in self.test_loader:
              data, targets = data.to(self.device), targets.to(
                  self.device
              )
              outputs = model(data)
  
              if isinstance(outputs, tuple):
                  outputs = outputs[0]
  
              test_loss += self.loss_fn(outputs, targets).item()
              pred = outputs.argmax(dim=1, keepdim=True)
              correct += (
                  pred.eq(targets.data.view_as(pred)).sum().item()
              )
  
          test_loss /= len(self.test_loader.dataset)
          test_acc = 100.0 * correct / len(self.test_loader.dataset)
  
      return test_loss, test_acc
  
file_path: KD_Lib/KD_Lib/Pruning/common/iterative_base_class.py
imports: import copy
  import numpy
  import torch
  import torch.nn
label_desc: Use image node_id 5 for calling the BaseIterativePruner obj's underlying member method code with example usage: obj.evaluate_model(model_path) and returns: test_loss,  test_acc