class_docstr: Interface for torch models.
class_docstr_tok: ["Interface","for","torch","models","."]
docstr: In a case model has a softmax module, the last torch.nn.Softmax module in the self.model.modules() list is
  replaced with torch.nn.Identity().
  Iterates through named modules in reverse order (from the last to the first), for the first module of
  torch.nn.Softmax type, the module's name is then used to replace the module with torch.nn.Identity() in
  the original model's copy using setattr.
docstr_tok: ["In","a","case","model","has","a","softmax","module",",","the","last","torch.nn.Softmax","module","in","the","self.model.modules","(",")","list","is","replaced","with","torch.nn.Identity","(",")",".","Iterates","through","named","modules","in","reverse","order","(","from","the","last","to","the","first",")",",","for","the","first","module","of","torch.nn.Softmax","type",",","the","module","'s","name","is","then","used","to","replace","the","module","with","torch.nn.Identity","(",")","in","the","original","model","'s","copy","using","setattr","."]
code: def _get_model_with_linear_top(self) -> torch.nn:
      """
      In a case model has a softmax module, the last torch.nn.Softmax module in the self.model.modules() list is
      replaced with torch.nn.Identity().
      Iterates through named modules in reverse order (from the last to the first), for the first module of
      torch.nn.Softmax type, the module's name is then used to replace the module with torch.nn.Identity() in
      the original model's copy using setattr.
      """
      linear_model = copy.deepcopy(self.model)
  
      for named_module in list(linear_model.named_modules())[::-1]:
          if isinstance(named_module[1], torch.nn.Softmax):
              setattr(
                  linear_model, named_module[0], torch.nn.Identity()
              )
  
              logging.info(
                  "Argument softmax=False passed, but the passed model contains a module of type "
                  "torch.nn.Softmax. Module {} has been replaced with torch.nn.Identity().",
                  named_module[0],
              )
              break
  
      return linear_model
  
imports: import copy
  from contextlib import suppress
  from copy import deepcopy
  from typing import Any, Dict, Optional, Tuple, List, Union, Generator
  import warnings
  import logging
  import numpy
  import torch
  from torch import nn
  from functools import lru_cache
  from quantus.helpers import utils
  from quantus.helpers.model.model_interface import ModelInterface
label_desc: Use image node_id 3 for calling the PyTorchModel obj's underlying member method code with example usage: obj._get_model_with_linear_top() and returns: linear_model