org.deeplearning4j.nn.graph.vertex.impl.InputVertex Maven / Gradle / Ivy
/*
* ******************************************************************************
* *
* *
* * This program and the accompanying materials are made available under the
* * terms of the Apache License, Version 2.0 which is available at
* * https://www.apache.org/licenses/LICENSE-2.0.
* *
* * See the NOTICE file distributed with this work for additional
* * information regarding copyright ownership.
* * Unless required by applicable law or agreed to in writing, software
* * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* * License for the specific language governing permissions and limitations
* * under the License.
* *
* * SPDX-License-Identifier: Apache-2.0
* *****************************************************************************
*/
package org.deeplearning4j.nn.graph.vertex.impl;
import org.deeplearning4j.nn.api.Layer;
import org.deeplearning4j.nn.api.MaskState;
import org.deeplearning4j.nn.gradient.Gradient;
import org.deeplearning4j.nn.graph.ComputationGraph;
import org.deeplearning4j.nn.graph.vertex.BaseGraphVertex;
import org.deeplearning4j.nn.graph.vertex.VertexIndices;
import org.nd4j.linalg.api.buffer.DataType;
import org.nd4j.linalg.api.ndarray.INDArray;
import org.nd4j.common.primitives.Pair;
import org.deeplearning4j.nn.workspace.LayerWorkspaceMgr;
public class InputVertex extends BaseGraphVertex {
public InputVertex(ComputationGraph graph, String name, int vertexIndex, VertexIndices[] outputVertices, DataType dataType) {
super(graph, name, vertexIndex, null, outputVertices, dataType);
}
@Override
public boolean hasLayer() {
return false;
}
@Override
public boolean isOutputVertex() {
return false;
}
@Override
public boolean isInputVertex() {
return true;
}
@Override
public Layer getLayer() {
return null;
}
@Override
public INDArray doForward(boolean training, LayerWorkspaceMgr workspaceMgr) {
throw new UnsupportedOperationException("Cannot do forward pass for InputVertex");
}
@Override
public Pair doBackward(boolean tbptt, LayerWorkspaceMgr workspaceMgr) {
throw new UnsupportedOperationException("Cannot do backward pass for InputVertex");
}
@Override
public void setBackpropGradientsViewArray(INDArray backpropGradientsViewArray) {
if (backpropGradientsViewArray != null)
throw new RuntimeException("Vertex does not have gradients; gradients view array cannot be set here");
}
@Override
public Pair feedForwardMaskArrays(INDArray[] maskArrays, MaskState currentMaskState,
int minibatchSize) {
//No op
if (maskArrays == null || maskArrays.length == 0) {
return null;
}
return new Pair<>(maskArrays[0], currentMaskState);
}
@Override
public String toString() {
return "InputVertex(id=" + vertexIndex + ",name=\"" + vertexName + "\")";
}
}