class_docstr: Matches patterns to apply transforms in a tf.keras model graph.
docstr: Sequential model: replace the chain of match_layer_node with replacement_layer_node.
code: def _replace_sequential(
      self, match_layer_node, replacement_layer_node
  ):
      """Sequential model: replace the chain of match_layer_node with replacement_layer_node."""
      # 1. Remove the original matched layers.
      layers_to_remove_names = self._get_layer_names(match_layer_node)
      layers_to_remove = self._get_layers(layers_to_remove_names)
  
      # These variables are needed when adding the new layers
      # and must be set before _remove_layers removes them.
      first_layer_removed = layers_to_remove[0]
      first_layer_removed_index = self._config["layers"].index(
          first_layer_removed
      )
  
      self._remove_layers(layers_to_remove, layers_to_remove_names)
  
      # 2. Add in the new layers.
      def _get_replacement_nodes(replacement_node):
          """Get list of replacement nodes in Sequential order."""
          replacement_nodes = []
  
          for input_layer in replacement_node.input_layers:
              replacement_nodes.extend(
                  _get_replacement_nodes(input_layer)
              )
  
          replacement_nodes.append(replacement_node)
  
          return replacement_nodes
  
      def _add_replacement_nodes(
          first_layer_removed_index, replacement_nodes
      ):
          """Add replacement nodes to Sequential model."""
  
          # Potentially insert nodes into middle of model.
          i = first_layer_removed_index
          for replacement_node in replacement_nodes:
              self._config["layers"].insert(i, replacement_node.layer)
              layer_name = replacement_node.layer["config"]["name"]
              if replacement_node.weights:
                  self._layer_weights_map[
                      layer_name
                  ] = replacement_node.weights
              if replacement_node.names_and_weights:
                  self._layer_names_and_weights_map[
                      layer_name
                  ] = replacement_node.names_and_weights
              if replacement_node.metadata:
                  self._layer_metadata_map[
                      layer_name
                  ] = replacement_node.metadata
              if self.candidate_layers:
                  self.candidate_layers.add(layer_name)
              i += 1
  
      replacement_nodes = _get_replacement_nodes(replacement_layer_node)
      _add_replacement_nodes(
          first_layer_removed_index, replacement_nodes
      )
  
imports: import collections
  import copy
  import re
  import tensorflow
  from tensorflow_model_optimization.python.core.quantization.keras.graph_transformations import transforms
label_desc: Use image node_id 23 for calling the ModelTransformer obj's underlying member method code with example usage: obj._replace_sequential(match_layer_node, replacement_layer_node) and returns: replacement_nodes