class_docstr: Creates a recurrent actor network.
docstr: Creates an instance of `ActorRnnNetwork`.
  
  Args:
    input_tensor_spec: A nest of `tensor_spec.TensorSpec` representing the
      input observations.
    output_tensor_spec: A nest of `tensor_spec.BoundedTensorSpec` representing
      the actions.
    conv_layer_params: Optional list of convolution layers parameters, where
      each item is a length-three tuple indicating (filters, kernel_size,
      stride).
    input_fc_layer_params: Optional list of fully_connected parameters, where
      each item is the number of units in the layer. This is applied before
      the LSTM cell.
    lstm_size: An iterable of ints specifying the LSTM cell sizes to use.
    output_fc_layer_params: Optional list of fully_connected parameters, where
      each item is the number of units in the layer. This is applied after the
      LSTM cell.
    activation_fn: Activation function, e.g. tf.nn.relu, slim.leaky_relu, ...
    name: A string representing name of the network.
  
  Returns:
    A nest of action tensors matching the action_spec.
  
  Raises:
    ValueError: If `input_tensor_spec` contains more than one observation.
docstr_tok: ["Creates","an","instance","of","`","ActorRnnNetwork","`",".","Args",":","input_tensor_spec",":","A","nest","of","`","tensor_spec.TensorSpec","`","representing","the","input","observations",".","output_tensor_spec",":","A","nest","of","`","tensor_spec.BoundedTensorSpec","`","representing","the","actions",".","conv_layer_params",":","Optional","list","of","convolution","layers","parameters",",","where","each","item","is","a","length-three","tuple","indicating","(","filters",",","kernel_size",",","stride",")",".","input_fc_layer_params",":","Optional","list","of","fully_connected","parameters",",","where","each","item","is","the","number","of","units","in","the","layer",".","This","is","applied","before","the","LSTM","cell",".","lstm_size",":","An","iterable","of","ints","specifying","the","LSTM","cell","sizes","to","use",".","output_fc_layer_params",":","Optional","list","of","fully_connected","parameters",",","where","each","item","is","the","number","of","units","in","the","layer",".","This","is","applied","after","the","LSTM","cell",".","activation_fn",":","Activation","function",",","e.g",".","tf.nn.relu",",","slim.leaky_relu",",","...","name",":","A","string","representing","name","of","the","network",".","Returns",":","A","nest","of","action","tensors","matching","the","action_spec",".","Raises",":","ValueError",":","If","`","input_tensor_spec","`","contains","more","than","one","observation","."]
code: def __init__(
      self,
      input_tensor_spec,
      output_tensor_spec,
      conv_layer_params=None,
      input_fc_layer_params=(200, 100),
      lstm_size=(40,),
      output_fc_layer_params=(200, 100),
      activation_fn=tf.keras.activations.relu,
      name="ActorRnnNetwork",
  ):
      """Creates an instance of `ActorRnnNetwork`.
  
      Args:
        input_tensor_spec: A nest of `tensor_spec.TensorSpec` representing the
          input observations.
        output_tensor_spec: A nest of `tensor_spec.BoundedTensorSpec` representing
          the actions.
        conv_layer_params: Optional list of convolution layers parameters, where
          each item is a length-three tuple indicating (filters, kernel_size,
          stride).
        input_fc_layer_params: Optional list of fully_connected parameters, where
          each item is the number of units in the layer. This is applied before
          the LSTM cell.
        lstm_size: An iterable of ints specifying the LSTM cell sizes to use.
        output_fc_layer_params: Optional list of fully_connected parameters, where
          each item is the number of units in the layer. This is applied after the
          LSTM cell.
        activation_fn: Activation function, e.g. tf.nn.relu, slim.leaky_relu, ...
        name: A string representing name of the network.
  
      Returns:
        A nest of action tensors matching the action_spec.
  
      Raises:
        ValueError: If `input_tensor_spec` contains more than one observation.
      """
      if len(tf.nest.flatten(input_tensor_spec)) > 1:
          raise ValueError(
              "Only a single observation is supported by this network"
          )
  
      input_layers = utils.mlp_layers(
          conv_layer_params,
          input_fc_layer_params,
          activation_fn=activation_fn,
          kernel_initializer=tf.compat.v1.keras.initializers.glorot_uniform(),
          name="input_mlp",
      )
  
      # Create RNN cell
      if len(lstm_size) == 1:
          cell = tf.keras.layers.LSTMCell(lstm_size[0])
      else:
          cell = tf.keras.layers.StackedRNNCells(
              [tf.keras.layers.LSTMCell(size) for size in lstm_size]
          )
  
      state_spec = tf.nest.map_structure(
          functools.partial(
              tensor_spec.TensorSpec,
              dtype=tf.float32,
              name="network_state_spec",
          ),
          list(cell.state_size),
      )
  
      output_layers = utils.mlp_layers(
          fc_layer_params=output_fc_layer_params, name="output"
      )
  
      flat_action_spec = tf.nest.flatten(output_tensor_spec)
      action_layers = [
          tf.keras.layers.Dense(
              single_action_spec.shape.num_elements(),
              activation=tf.keras.activations.tanh,
              kernel_initializer=tf.keras.initializers.RandomUniform(
                  minval=-0.003, maxval=0.003
              ),
              name="action",
          )
          for single_action_spec in flat_action_spec
      ]
  
      super(ActorRnnNetwork, self).__init__(
          input_tensor_spec=input_tensor_spec,
          state_spec=state_spec,
          name=name,
      )
  
      self._output_tensor_spec = output_tensor_spec
      self._flat_action_spec = flat_action_spec
      self._conv_layer_params = conv_layer_params
      self._input_layers = input_layers
      self._dynamic_unroll = dynamic_unroll_layer.DynamicUnroll(cell)
      self._output_layers = output_layers
      self._action_layers = action_layers
  
file_path: agents/tf_agents/agents/ddpg/actor_rnn_network.py
imports: import functools
  import gin
  import tensorflow
  from tf_agents.keras_layers import dynamic_unroll_layer
  from tf_agents.networks import network
  from tf_agents.networks import utils
  from tf_agents.specs import tensor_spec
  from tf_agents.trajectories import time_step
  from tf_agents.utils import common
  from tf_agents.utils import nest_utils
label_desc: Use image node_id 1 to create a new ActorRnnNetwork object from inherited base classes: network with example: obj = ActorRnnNetwork(input_tensor_spec, output_tensor_spec, conv_layer_params, input_fc_layer_params, lstm_size, output_fc_layer_params, activation_fn, name)