# in autokeras/graph.py def_build_network(self): self._node_to_id = {} # Recursively find all the interested nodes. for input_node in self.inputs: self._search_network(input_node, self.outputs, set(), set()) self._nodes = sorted( list(self._node_to_id.keys()), key=lambda x: self._node_to_id[x] )
for node in self.inputs + self.outputs: if node notin self._node_to_id: raise ValueError("Inputs and outputs not connected.")
# Find the blocks. blocks = [] for input_node in self._nodes: for block in input_node.out_blocks: if ( any( [ output_node in self._node_to_id for output_node in block.outputs ] ) and block notin blocks ): blocks.append(block)
# Check if all the inputs of the blocks are set as inputs. for block in blocks: for input_node in block.inputs: if input_node notin self._node_to_id: raise ValueError( "A required input is missing for HyperModel " "{name}.".format(name=block.name) )
# Calculate the in degree of all the nodes in_degree = [0] * len(self._nodes) for node_id, node inenumerate(self._nodes): in_degree[node_id] = len( [block for block in node.in_blocks if block in blocks] )
# Add the blocks in topological order. self.blocks = [] self._block_to_id = {} whilelen(blocks) != 0: new_added = []
# Collect blocks with in degree 0. for block in blocks: ifany([in_degree[self._node_to_id[node]] for node in block.inputs]): continue new_added.append(block)
# Remove the collected blocks from blocks. for block in new_added: blocks.remove(block)
for block in new_added: # Add the collected blocks to the Graph. self._add_block(block)
# Decrease the in degree of the output nodes. for output_node in block.outputs: output_node_id = self._node_to_id[output_node] in_degree[output_node_id] -= 1`