parameters: (self, outputs=None)
docstring: Prune graph to keep only required outputs. It removes unnecessary inputs and nodes.
          Nodes are not linked (directly or indirectly) to any required output will be removed.
  
          Args:
              outputs (list): a list of graph outputs to retain. If it is None, all graph outputs will be kept.
docstring_summary: Prune graph to keep only required outputs. It removes unnecessary inputs and nodes.
          Nodes are not linked (directly or indirectly) to any required output will be removed.
docstring_tokens: Prune graph to keep only required outputs . It removes unnecessary inputs and nodes . Nodes are not linked ( directly or indirectly ) to any required output will be removed .
function: def prune_graph(self, outputs=None):
          """
          Prune graph to keep only required outputs. It removes unnecessary inputs and nodes.
          Nodes are not linked (directly or indirectly) to any required output will be removed.
  
          Args:
              outputs (list): a list of graph outputs to retain. If it is None, all graph outputs will be kept.
          """
          if len(self.graphs()) > 1:
              logger.debug(f"Skip prune_graph since graph has subgraph")
              return
  
          if outputs is None:
              outputs = [output.name for output in self.model.graph.output]
  
          output_name_to_node = self.output_name_to_node()
          all_nodes = []
          for output in outputs:
              if output in output_name_to_node:
                  last_node = output_name_to_node[output]
                  if last_node in all_nodes:
                      continue
                  nodes = self.get_parent_subgraph_nodes(last_node, [])
                  all_nodes.append(last_node)
                  all_nodes.extend(nodes)
  
          nodes_to_remove = []
          for node in self.model.graph.node:
              if node not in all_nodes:
                  nodes_to_remove.append(node)
  
          self.remove_nodes(nodes_to_remove)
  
          # remove outputs not in list
          output_to_remove = []
          for output in self.model.graph.output:
              if output.name not in outputs:
                  output_to_remove.append(output)
          for output in output_to_remove:
              self.model.graph.output.remove(output)
  
          # remove inputs not used by any node.
          input_name_to_nodes = self.input_name_to_nodes()
          input_to_remove = []
          for input in self.model.graph.input:
              if input.name not in input_name_to_nodes:
                  input_to_remove.append(input)
          for input in input_to_remove:
              self.model.graph.input.remove(input)
  
          if input_to_remove or output_to_remove or nodes_to_remove:
              logger.info("Graph pruned: {} inputs, {} outputs and {} nodes are removed".format(
                  len(input_to_remove), len(output_to_remove), len(nodes_to_remove)))
  
          self.update_graph()
function_tokens: def prune_graph ( self , outputs = None ) : if len ( self . graphs ( ) ) > 1 : logger . debug ( f"Skip prune_graph since graph has subgraph" ) return if outputs is None : outputs = [ output . name for output in self . model . graph . output ] output_name_to_node = self . output_name_to_node ( ) all_nodes = [ ] for output in outputs : if output in output_name_to_node : last_node = output_name_to_node [ output ] if last_node in all_nodes : continue nodes = self . get_parent_subgraph_nodes ( last_node , [ ] ) all_nodes . append ( last_node ) all_nodes . extend ( nodes ) nodes_to_remove = [ ] for node in self . model . graph . node : if node not in all_nodes : nodes_to_remove . append ( node ) self . remove_nodes ( nodes_to_remove ) # remove outputs not in list output_to_remove = [ ] for output in self . model . graph . output : if output . name not in outputs : output_to_remove . append ( output ) for output in output_to_remove : self . model . graph . output . remove ( output ) # remove inputs not used by any node. input_name_to_nodes = self . input_name_to_nodes ( ) input_to_remove = [ ] for input in self . model . graph . input : if input . name not in input_name_to_nodes : input_to_remove . append ( input ) for input in input_to_remove : self . model . graph . input . remove ( input ) if input_to_remove or output_to_remove or nodes_to_remove : logger . info ( "Graph pruned: {} inputs, {} outputs and {} nodes are removed" . format ( len ( input_to_remove ) , len ( output_to_remove ) , len ( nodes_to_remove ) ) ) self . update_graph ( )