class_docstr: Interface for tensorflow models.
docstr: In a case model has a softmax on top, and we want linear,
  we have to rebuild the model and replace top with linear activation.
  Softmax can either be a separate last layer, or activation of the
  last layer.
  Cache the rebuilt model and reuse it during consecutive predict calls.
docstr_tok: ["In","a","case","model","has","a","softmax","on","top",",","and","we","want","linear",",","we","have","to","rebuild","the","model","and","replace","top","with","linear","activation",".","Softmax","can","either","be","a","separate","last","layer",",","or","activation","of","the","last","layer",".","Cache","the","rebuilt","model","and","reuse","it","during","consecutive","predict","calls","."]
code: def _get_model_with_linear_top(self) -> Model:
      """
      In a case model has a softmax on top, and we want linear,
      we have to rebuild the model and replace top with linear activation.
      Softmax can either be a separate last layer, or activation of the
      last layer.
      Cache the rebuilt model and reuse it during consecutive predict calls.
      """
  
      if self._last_layer_is_softmax:
          output_layer = self.model.layers[-2].output
          new_model = Model(
              inputs=[self.model.input], outputs=[output_layer]
          )
          return new_model
  
      output_activation = self.model.layers[-1].activation
      if output_activation == activations.linear:
          return self.model
  
      config = self.model.layers[-1].get_config()
      config["activation"] = activations.linear
      weights = self.model.layers[-1].get_weights()
  
      output_layer = Dense(**config)(self.model.layers[-2].output)
      new_model = Model(
          inputs=[self.model.input], outputs=[output_layer]
      )
      new_model.layers[-1].set_weights(weights)
      return new_model
  
imports: from __future__ import annotations
  from typing import Dict, Optional, Tuple, List, Union, Generator
  from keras.layers import Dense
  from keras import activations
  from keras import Model
  from keras.models import clone_model
  import numpy
  import tensorflow
  from warnings import warn
  from cachetools import cachedmethod, LRUCache
  import operator
  from quantus.helpers.model.model_interface import ModelInterface
  from quantus.helpers import utils
label_desc: Use image node_id 4 for calling the TensorFlowModel obj's underlying member method code with example usage: obj._get_model_with_linear_top() and returns: new_model, new_model, self