class_docstr: TF version of ModelV2, which should contain a tf keras Model.
  
  Note that this class by itself is not a valid model unless you
  implement forward() in a subclass.
class_docstr_tok: ["TF","version","of","ModelV2",",","which","should","contain","a","tf","keras","Model",".","Note","that","this","class","by","itself","is","not","a","valid","model","unless","you","implement","forward","(",")","in","a","subclass","."]
docstr: Initializes a TFModelV2 instance.
  
  Here is an example implementation for a subclass
  ``MyModelClass(TFModelV2)``::
  
      def __init__(self, *args, **kwargs):
          super(MyModelClass, self).__init__(*args, **kwargs)
          input_layer = tf.keras.layers.Input(...)
          hidden_layer = tf.keras.layers.Dense(...)(input_layer)
          output_layer = tf.keras.layers.Dense(...)(hidden_layer)
          value_layer = tf.keras.layers.Dense(...)(hidden_layer)
          self.base_model = tf.keras.Model(
              input_layer, [output_layer, value_layer])
docstr_tok: ["Initializes","a","TFModelV2","instance",".","Here","is","an","example","implementation","for","a","subclass","``","MyModelClass","(","TFModelV2",")","``",":",":","def","__init__","(","self",",","*","args",",","*","*","kwargs",")",":","super","(","MyModelClass",",","self",")",".__init__","(","*","args",",","*","*","kwargs",")","input_layer","=","tf.keras.layers.Input","(","...",")","hidden_layer","=","tf.keras.layers.Dense","(","...",")","(","input_layer",")","output_layer","=","tf.keras.layers.Dense","(","...",")","(","hidden_layer",")","value_layer","=","tf.keras.layers.Dense","(","...",")","(","hidden_layer",")","self.base_model","=","tf.keras.Model","(","input_layer",",","[","output_layer",",","value_layer","]",")"]
code: def __init__(
      self,
      obs_space: gym.spaces.Space,
      action_space: gym.spaces.Space,
      num_outputs: int,
      model_config: ModelConfigDict,
      name: str,
  ):
      """Initializes a TFModelV2 instance.
  
      Here is an example implementation for a subclass
      ``MyModelClass(TFModelV2)``::
  
          def __init__(self, *args, **kwargs):
              super(MyModelClass, self).__init__(*args, **kwargs)
              input_layer = tf.keras.layers.Input(...)
              hidden_layer = tf.keras.layers.Dense(...)(input_layer)
              output_layer = tf.keras.layers.Dense(...)(hidden_layer)
              value_layer = tf.keras.layers.Dense(...)(hidden_layer)
              self.base_model = tf.keras.Model(
                  input_layer, [output_layer, value_layer])
      """
      super().__init__(
          obs_space,
          action_space,
          num_outputs,
          model_config,
          name,
          framework="tf",
      )
  
      # Deprecated: TFModelV2 now automatically track their variables.
      self.var_list = []
  
      if tf1.executing_eagerly():
          self.graph = None
      else:
          self.graph = tf1.get_default_graph()
  
file_path: ray/rllib/models/tf/tf_modelv2.py
imports: import contextlib
  import gymnasium
  import re
  from typing import Dict, List, Union
  from ray.util import log_once
  from ray.rllib.models.modelv2 import ModelV2
  from ray.rllib.utils.annotations import override, PublicAPI
  from ray.rllib.utils.deprecation import deprecation_warning
  from ray.rllib.utils.framework import try_import_tf
  from ray.rllib.utils.typing import ModelConfigDict, TensorType
label_desc: Use image node_id 1 to create a new TFModelV2 object from inherited base classes: ModelV2 with example: obj = TFModelV2(obs_space, action_space, num_outputs, model_config, name)