code: def _rnn_template(
      incoming,
      cell,
      dropout=None,
      return_seq=False,
      return_state=False,
      initial_state=None,
      dynamic=False,
      scope=None,
      reuse=False,
      name="LSTM",
  ):
      """RNN Layer Template."""
      sequence_length = None
      if dynamic:
          sequence_length = retrieve_seq_length_op(
              incoming
              if isinstance(incoming, tf.Tensor)
              else tf.stack(incoming)
          )
  
      input_shape = utils.get_incoming_shape(incoming)
  
      with tf.variable_scope(
          scope, default_name=name, values=[incoming], reuse=reuse
      ) as scope:
          name = scope.name
  
          _cell = cell
          # Apply dropout
          if dropout:
              if type(dropout) in [tuple, list]:
                  in_keep_prob = dropout[0]
                  out_keep_prob = dropout[1]
              elif isinstance(dropout, float):
                  in_keep_prob, out_keep_prob = dropout, dropout
              else:
                  raise Exception(
                      "Invalid dropout type (must be a 2-D tuple of "
                      "float)"
                  )
              cell = DropoutWrapper(cell, in_keep_prob, out_keep_prob)
  
          inference = incoming
          # If a tensor given, convert it to a per timestep list
          if type(inference) not in [list, np.array]:
              ndim = len(input_shape)
              assert ndim >= 3, "Input dim should be at least 3."
              axes = [1, 0] + list(range(2, ndim))
              inference = tf.transpose(inference, (axes))
              inference = tf.unstack(inference)
  
          outputs, state = _rnn(
              cell,
              inference,
              dtype=tf.float32,
              initial_state=initial_state,
              scope=name,
              sequence_length=sequence_length,
          )
  
          # Retrieve RNN Variables
          c = tf.GraphKeys.LAYER_VARIABLES + "/" + scope.name
          for v in [_cell.W, _cell.b]:
              if hasattr(v, "__len__"):
                  for var in v:
                      tf.add_to_collection(c, var)
              else:
                  tf.add_to_collection(c, v)
          # Track activations.
          tf.add_to_collection(tf.GraphKeys.ACTIVATIONS, outputs[-1])
  
      if dynamic:
          if return_seq:
              o = tf.stack(outputs, 1)
          else:
              outputs = tf.transpose(tf.stack(outputs), [1, 0, 2])
              o = advanced_indexing_op(outputs, sequence_length)
      else:
          o = tf.stack(outputs, 1) if return_seq else outputs[-1]
  
      # Track output tensor.
      tf.add_to_collection(tf.GraphKeys.LAYER_TENSOR + "/" + name, o)
  
      return (o, state) if return_state else o
  
imports: from __future__ import division, print_function, absolute_import
  import logging
  import numpy
  import tensorflow.compat.v1
  from tensorflow.python.ops import array_ops
  from tensorflow.python.util.nest import is_sequence
  from ..None import config
  from ..None import utils
  from ..None import activations
  from ..None import initializations
  from ..None import variables
  from .normalization import batch_normalization
label_desc: Use image node_id 1 for calling a global function with example usage: _rnn_template(incoming, cell, dropout, return_seq, return_state, initial_state, dynamic, scope, reuse, name) and returns: unknown