class_docstr: Interface for torch models.
class_docstr_tok: ["Interface","for","torch","models","."]
docstr: Returns model with last layer adjusted accordingly to softmax argument.
  If the original model has softmax activation as the last layer and softmax=false,
  the layer is removed.
      +----------------------------------------------+----------------+-------------------+
      |                                              | softmax = true |  softmax = false  |
      +----------------------------------------------+----------------+-------------------+
      | torch.nn.Softmax LAST in model.modules()     | Do softmax  (1)| Remove softmax (4)|
      +----------------------------------------------+----------------+-------------------+
      | torch.nn.Softmax NOT LAST in model.modules() | Add softmax (2)| Do nothing     (5)|
      +----------------------------------------------+----------------+-------------------+
      | torch.nn.Softmax NOT in model.modules()      | Add softmax (3)| Do nothing     (6)|
      +----------------------------------------------+----------------+-------------------+
  
  (cells numbers according to Case N comments in the method)
docstr_tok: ["Returns","model","with","last","layer","adjusted","accordingly","to","softmax","argument",".","If","the","original","model","has","softmax","activation","as","the","last","layer","and","softmax=false",",","the","layer","is","removed",".","+","--","--","--","--","--","--","--","--","--","--","--","--","--","--","--","--","--","--","--","--","--","--","--","+","--","--","--","--","--","--","--","--","+","--","--","--","--","--","--","--","--","--","-+","|","|","softmax","=","true","|","softmax","=","false","|","+","--","--","--","--","--","--","--","--","--","--","--","--","--","--","--","--","--","--","--","--","--","--","--","+","--","--","--","--","--","--","--","--","+","--","--","--","--","--","--","--","--","--","-+","|","torch.nn.Softmax","LAST","in","model.modules","(",")","|","Do","softmax","(","1",")","|","Remove","softmax","(","4",")","|","+","--","--","--","--","--","--","--","--","--","--","--","--","--","--","--","--","--","--","--","--","--","--","--","+","--","--","--","--","--","--","--","--","+","--","--","--","--","--","--","--","--","--","-+","|","torch.nn.Softmax","NOT","LAST","in","model.modules","(",")","|","Add","softmax","(","2",")","|","Do","nothing","(","5",")","|","+","--","--","--","--","--","--","--","--","--","--","--","--","--","--","--","--","--","--","--","--","--","--","--","+","--","--","--","--","--","--","--","--","+","--","--","--","--","--","--","--","--","--","-+","|","torch.nn.Softmax","NOT","in","model.modules","(",")","|","Add","softmax","(","3",")","|","Do","nothing","(","6",")","|","+","--","--","--","--","--","--","--","--","--","--","--","--","--","--","--","--","--","--","--","--","--","--","--","+","--","--","--","--","--","--","--","--","+","--","--","--","--","--","--","--","--","--","-+","(","cells","numbers","according","to","Case","N","comments","in","the","method",")"]
code: def get_softmax_arg_model(self) -> torch.nn:
      """
      Returns model with last layer adjusted accordingly to softmax argument.
      If the original model has softmax activation as the last layer and softmax=false,
      the layer is removed.
          +----------------------------------------------+----------------+-------------------+
          |                                              | softmax = true |  softmax = false  |
          +----------------------------------------------+----------------+-------------------+
          | torch.nn.Softmax LAST in model.modules()     | Do softmax  (1)| Remove softmax (4)|
          +----------------------------------------------+----------------+-------------------+
          | torch.nn.Softmax NOT LAST in model.modules() | Add softmax (2)| Do nothing     (5)|
          +----------------------------------------------+----------------+-------------------+
          | torch.nn.Softmax NOT in model.modules()      | Add softmax (3)| Do nothing     (6)|
          +----------------------------------------------+----------------+-------------------+
  
      (cells numbers according to Case N comments in the method)
      """
  
      # last_softmax is the index of the last module which is of softmax type in the list of model children
      # or None if no softmax layer is found
      last_softmax = self._get_last_softmax_layer_index()
  
      if self.softmax and last_softmax == -1:
          return self.model  # Case 1
  
      if self.softmax and not last_softmax:
          logging.info(
              "Argument softmax=True passed, but the passed model contains no module of type "
              "torch.nn.Softmax. torch.nn.Softmax module is added as the output layer."
          )
          return torch.nn.Sequential(
              self.model, torch.nn.Softmax(dim=-1)
          )  # Case 3
  
      if not self.softmax and not last_softmax:
          return self.model  # Case 6
  
      warnings.warn(
          "The combination of the value of the passed softmax argument and the passed model potentially requires "
          "adjusting the model's modules. Make sure that the torch.nn.Softmax layer is the last module in the list "
          "of model's children (self.model.modules()) if and only if it is the actual last module applied before"
          "output."
      )  # Warning for cases 2, 4, 5
  
      if self.softmax and last_softmax != -1:
          logging.info(
              "Argument softmax=True passed. The passed model contains a module of type "
              "torch.nn.Softmax, but it is not the last in the list of model's children ("
              "self.model.modules()). torch.nn.Softmax module is added as the output layer."
              "Make sure that the torch.nn.Softmax layer is the last module in the list "
              "of model's children (self.model.modules()) if and only if it is the actual last module "
              "applied before output."
          )
  
          return torch.nn.Sequential(
              self.model, torch.nn.Softmax(dim=-1)
          )  # Case 2
  
      if not self.softmax and last_softmax == -1:
          return self._get_model_with_linear_top()  # Case 4
  
      return self.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 4 for calling the PyTorchModel obj's underlying member method code with example usage: obj.get_softmax_arg_model() and returns: self, self, torch, self, torch, self