'Builds the graph from the Caffe layer definitions.'

def build(self):

    layers = (self.params.layers or self.params.layer)
    layers = self.filter_layers(layers)
    nodes = self.make_input_nodes()
    nodes += [self.make_node(layer) for layer in layers]
    graph = Graph(nodes=nodes, name=self.params.name)
    node_outputs = {}
    for layer in layers:
        node = graph.get_node(layer.name)
        for input_name in layer.bottom:
            assert (input_name != layer.name)
            parent_node = node_outputs.get(input_name)
            if ((parent_node is None) or (parent_node == node)):
                parent_node = graph.get_node(input_name)
            node.add_parent(parent_node)
        if (len(layer.top) > 1):
            raise KaffeError('Multiple    top    nodes    are    not    supported.')
        for output_name in layer.top:
            if (output_name == layer.name):
                continue
            node_outputs[output_name] = node
    graph.compute_output_shapes()
    return graph
