class_docstr: Interface for tensorflow models.
docstr: In a case model has a linear activation in the last layer,
  and we want softmax, we have to rebuild the model and replace top with
  softmax activation.
  Cache the rebuilt model and reuse it during consecutive predict calls.
docstr_tok: ["In","a","case","model","has","a","linear","activation","in","the","last","layer",",","and","we","want","softmax",",","we","have","to","rebuild","the","model","and","replace","top","with","softmax","activation",".","Cache","the","rebuilt","model","and","reuse","it","during","consecutive","predict","calls","."]
code: def _get_model_with_softmax_top(self) -> Model:
      """
      In a case model has a linear activation in the last layer,
      and we want softmax, we have to rebuild the model and replace top with
      softmax activation.
      Cache the rebuilt model and reuse it during consecutive predict calls.
      """
  
      if self._last_layer_is_softmax:
          return self.model
  
      output_activation = self.model.layers[-1].activation
      if output_activation == activations.softmax:
          return self.model
  
      output_layer = tf.keras.layers.Softmax(axis=-1)(
          self.model.layers[-1].output
      )
      new_model = Model(
          inputs=[self.model.input], outputs=[output_layer]
      )
  
      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 5 for calling the TensorFlowModel obj's underlying member method code with example usage: obj._get_model_with_softmax_top() and returns: new_model, self, self