class_docstr: `Sequential` groups a linear stack of layers into a `tf.keras.Model`.
  
  `Sequential` provides training and inference features on this model.
  
  Examples:
  
  >>> # Optionally, the first layer can receive an `input_shape` argument:
  >>> model = tf.keras.Sequential()
  >>> model.add(tf.keras.layers.Dense(8, input_shape=(16,)))
  >>> # Afterwards, we do automatic shape inference:
  >>> model.add(tf.keras.layers.Dense(4))
  
  >>> # This is identical to the following:
  >>> model = tf.keras.Sequential()
  >>> model.add(tf.keras.Input(shape=(16,)))
  >>> model.add(tf.keras.layers.Dense(8))
  
  >>> # Note that you can also omit the `input_shape` argument.
  >>> # In that case the model doesn't have any weights until the first call
  >>> # to a training/evaluation method (since it isn't yet built):
  >>> model = tf.keras.Sequential()
  >>> model.add(tf.keras.layers.Dense(8))
  >>> model.add(tf.keras.layers.Dense(4))
  >>> # model.weights not created yet
  
  >>> # Whereas if you specify the input shape, the model gets built
  >>> # continuously as you are adding layers:
  >>> model = tf.keras.Sequential()
  >>> model.add(tf.keras.layers.Dense(8, input_shape=(16,)))
  >>> model.add(tf.keras.layers.Dense(4))
  >>> len(model.weights)
  4
  
  >>> # When using the delayed-build pattern (no input shape specified), you can
  >>> # choose to manually build your model by calling
  >>> # `build(batch_input_shape)`:
  >>> model = tf.keras.Sequential()
  >>> model.add(tf.keras.layers.Dense(8))
  >>> model.add(tf.keras.layers.Dense(4))
  >>> model.build((None, 16))
  >>> len(model.weights)
  4
  
  ```python
  # Note that when using the delayed-build pattern (no input shape specified),
  # the model gets built the first time you call `fit`, `eval`, or `predict`,
  # or the first time you call the model on some input data.
  model = tf.keras.Sequential()
  model.add(tf.keras.layers.Dense(8))
  model.add(tf.keras.layers.Dense(1))
  model.compile(optimizer='sgd', loss='mse')
  # This builds the model for the first time:
  model.fit(x, y, batch_size=32, epochs=10)
  ```
class_docstr_tok: ["`","Sequential","`","groups","a","linear","stack","of","layers","into","a","`","tf.keras.Model","`",".","`","Sequential","`","provides","training","and","inference","features","on","this","model",".","Examples",":",">",">",">","#","Optionally",",","the","first","layer","can","receive","an","`","input_shape","`","argument",":",">",">",">","model","=","tf.keras.Sequential","(",")",">",">",">","model.add","(","tf.keras.layers.Dense","(","8",",","input_shape=","(","16",",",")",")",")",">",">",">","#","Afterwards",",","we","do","automatic","shape","inference",":",">",">",">","model.add","(","tf.keras.layers.Dense","(","4",")",")",">",">",">","#","This","is","identical","to","the","following",":",">",">",">","model","=","tf.keras.Sequential","(",")",">",">",">","model.add","(","tf.keras.Input","(","shape=","(","16",",",")",")",")",">",">",">","model.add","(","tf.keras.layers.Dense","(","8",")",")",">",">",">","#","Note","that","you","can","also","omit","the","`","input_shape","`","argument",".",">",">",">","#","In","that","case","the","model","does","n't","have","any","weights","until","the","first","call",">",">",">","#","to","a","training\/evaluation","method","(","since","it","is","n't","yet","built",")",":",">",">",">","model","=","tf.keras.Sequential","(",")",">",">",">","model.add","(","tf.keras.layers.Dense","(","8",")",")",">",">",">","model.add","(","tf.keras.layers.Dense","(","4",")",")",">",">",">","#","model.weights","not","created","yet",">",">",">","#","Whereas","if","you","specify","the","input","shape",",","the","model","gets","built",">",">",">","#","continuously","as","you","are","adding","layers",":",">",">",">","model","=","tf.keras.Sequential","(",")",">",">",">","model.add","(","tf.keras.layers.Dense","(","8",",","input_shape=","(","16",",",")",")",")",">",">",">","model.add","(","tf.keras.layers.Dense","(","4",")",")",">",">",">","len","(","model.weights",")","4",">",">",">","#","When","using","the","delayed-build","pattern","(","no","input","shape","specified",")",",","you","can",">",">",">","#","choose","to","manually","build","your","model","by","calling",">",">",">","#","`","build","(","batch_input_shape",")","`",":",">",">",">","model","=","tf.keras.Sequential","(",")",">",">",">","model.add","(","tf.keras.layers.Dense","(","8",")",")",">",">",">","model.add","(","tf.keras.layers.Dense","(","4",")",")",">",">",">","model.build","(","(","None",",","16",")",")",">",">",">","len","(","model.weights",")","4","``","`","python","#","Note","that","when","using","the","delayed-build","pattern","(","no","input","shape","specified",")",",","#","the","model","gets","built","the","first","time","you","call","`","fit","`",",","`","eval","`",",","or","`","predict","`",",","#","or","the","first","time","you","call","the","model","on","some","input","data",".","model","=","tf.keras.Sequential","(",")","model.add","(","tf.keras.layers.Dense","(","8",")",")","model.add","(","tf.keras.layers.Dense","(","1",")",")","model.compile","(","optimizer='sgd","'",",","loss='mse","'",")","#","This","builds","the","model","for","the","first","time",":","model.fit","(","x",",","y",",","batch_size=32",",","epochs=10",")","``","`"]
code: def _build_graph_network_for_inferred_shape(
      self, input_shape, input_dtype=None
  ):
      if input_shape is None or not self.layers:
          return
      if (
          not tf2.enabled()
          or not ops.executing_eagerly_outside_functions()
      ):
          # This behavior is disabled in V1 or when eager execution is disabled.
          return
      if (
          not self._has_explicit_input_shape
          and not self._use_legacy_deferred_behavior
      ):
          # Determine whether the input shape is novel, i.e. whether the model
          # should be rebuilt.
          input_shape = tuple(input_shape)
          if self._inferred_input_shape is None:
              new_shape = input_shape
          else:
              new_shape = relax_input_shape(
                  self._inferred_input_shape, input_shape
              )
          if (
              new_shape is not None
              and new_shape != self._inferred_input_shape
          ):
              # A novel shape has been received: we need to rebuild the model.
              # In case we are inside a graph function, we step out of it.
              with ops.init_scope():
                  inputs = input_layer.Input(
                      batch_shape=new_shape,
                      dtype=input_dtype,
                      name=self.layers[0].name + "_input",
                  )
                  layer_input = inputs
                  created_nodes = set()
                  for layer in self.layers:
                      # Clear nodes previously created via this method. This prevents
                      # node accumulation and ensures that e.g. `layer.output` is
                      # always connected to `model.inputs`
                      # (this is important e.g. for the feature extraction use case).
                      # We don't just do `layer._inbound_nodes = []` in order
                      # not to break shared layers added to Sequential models (which is
                      # technically illegal as per the `add()` docstring,
                      # but wasn't previously disabled).
                      clear_previously_created_nodes(
                          layer, self._created_nodes
                      )
                      try:
                          # Create Functional API connection by calling the current layer
                          layer_output = layer(layer_input)
                      except:  # pylint:disable=bare-except
                          # Functional API calls may fail for a number of reasons:
                          # 1) The layer may be buggy. In this case it will be easier for
                          # the user to debug if we fail on the first call on concrete data,
                          # instead of our own call on a symbolic input.
                          # 2) The layer is dynamic (graph-incompatible) and hasn't
                          # overridden `compute_output_shape`. In this case, it is
                          # impossible to build a graph network.
                          # 3) The layer is otherwise incompatible with the Functional API
                          # (e.g. this is the case for some probabilistic layers that rely
                          # on hacks and that do not return tensors).
                          # In all these cases, we should avoid creating a graph network
                          # (or we simply can't).
                          self._use_legacy_deferred_behavior = True
                          return
                      if len(nest.flatten(layer_output)) != 1:
                          raise ValueError(
                              SINGLE_LAYER_OUTPUT_ERROR_MSG
                          )
                      # Keep track of nodes just created above
                      track_nodes_created_by_last_call(
                          layer, created_nodes
                      )
                      layer_input = layer_output
                      outputs = layer_output
                  self._created_nodes = created_nodes
                  try:
                      # Initialize a graph Network. This call will never fail for
                      # a stack of valid Keras layers.
                      # However some users have layers that are fundamentally incompatible
                      # with the Functional API, which do not return tensors. In this
                      # case, we fall back to the legacy deferred behavior.
                      # TODO(fchollet): consider raising here, as we should not be
                      # supporting such layers.
                      self._init_graph_network(inputs, outputs)
                      self._graph_initialized = True
                  except:  # pylint:disable=bare-except
                      self._use_legacy_deferred_behavior = True
              self._inferred_input_shape = new_shape
  
imports: import copy
  import warnings
  from tensorflow.python import tf2
  from tensorflow.python.framework import ops
  from tensorflow.python.framework import tensor_util
  from tensorflow.python.keras import layers
  from tensorflow.python.keras.engine import base_layer
  from tensorflow.python.keras.engine import functional
  from tensorflow.python.keras.engine import input_layer
  from tensorflow.python.keras.engine import training_utils
  from tensorflow.python.keras.saving.saved_model import model_serialization
  from tensorflow.python.keras.utils import generic_utils
  from tensorflow.python.keras.utils import layer_utils
  from tensorflow.python.keras.utils import tf_inspect
  from tensorflow.python.keras.utils import tf_utils
  from tensorflow.python.module import module
  from tensorflow.python.ops.numpy_ops import np_arrays
  from tensorflow.python.platform import tf_logging
  from tensorflow.python.trackable import base
  from tensorflow.python.util import nest
label_desc: Use image node_id 5 for calling the Sequential obj's underlying member method code with example usage: obj._build_graph_network_for_inferred_shape(input_shape, input_dtype) without return types