/** * Add a {@link GraphVertex} to the network configuration. A GraphVertex defines forward and backward pass methods, * and can contain a {@link LayerVertex}, a {@link org.deeplearning4j.nn.conf.graph.ElementWiseVertex} to do element-wise * addition/subtraction, a {@link MergeVertex} to combine/concatenate the activations out of multiple layers or vertices, * a {@link org.deeplearning4j.nn.conf.graph.SubsetVertex} to select a subset of the activations out of another layer/GraphVertex.<br> * Custom GraphVertex objects (that extend the abstract {@link GraphVertex} class) may also be used. * * @param vertexName The name of the GraphVertex to add * @param vertex The GraphVertex to add * @param vertexInputs The inputs/activations to this GraphVertex */ public GraphBuilder addVertex(String vertexName, GraphVertex vertex, String... vertexInputs) { vertices.put(vertexName, vertex); //Automatically insert a MergeNode if this vertex can only take 1 input (layer vertices, etc) if (vertex.maxVertexInputs() == 1 && vertexInputs != null && vertexInputs.length > 1) { String mergeName = vertexName + "-merge"; addVertex(mergeName, new MergeVertex(), vertexInputs); this.vertexInputs.put(vertexName, Collections.singletonList(mergeName)); } else if (vertexInputs != null) { this.vertexInputs.put(vertexName, Arrays.asList(vertexInputs)); } return this; }