Class BaseWrapperVertex
- java.lang.Object
-
- org.deeplearning4j.nn.graph.vertex.BaseWrapperVertex
-
- All Implemented Interfaces:
Serializable,Trainable,GraphVertex
- Direct Known Subclasses:
FrozenVertex
public abstract class BaseWrapperVertex extends Object implements GraphVertex
- See Also:
- Serialized Form
-
-
Field Summary
Fields Modifier and Type Field Description protected GraphVertexunderlying
-
Constructor Summary
Constructors Modifier Constructor Description protectedBaseWrapperVertex(GraphVertex underlying)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description booleancanDoBackward()Whether the GraphVertex can do backward pass.booleancanDoForward()Whether the GraphVertex can do forward pass.voidclear()Clear the internal state (if any) of the GraphVertex.voidclearVertex()This method clears inpjut for this vertexPair<Gradient,INDArray[]>doBackward(boolean tbptt, LayerWorkspaceMgr workspaceMgr)Do backward passINDArraydoForward(boolean training, LayerWorkspaceMgr workspaceMgr)Do forward pass using the stored inputsPair<INDArray,MaskState>feedForwardMaskArrays(INDArray[] maskArrays, MaskState currentMaskState, int minibatchSize)TrainingConfiggetConfig()INDArraygetEpsilon()Get the epsilon/error (i.e., dL/dOutput) array previously set for this GraphVertexINDArraygetGradientsViewArray()INDArray[]getInputs()Get the array of inputs previously set for this GraphVertexVertexIndices[]getInputVertices()A representation of the vertices that are inputs to this vertex (inputs duing forward pass)
Specifically, if inputVertices[X].getVertexIndex() = Y, and inputVertices[X].getVertexEdgeNumber() = Z then the Zth output connection (seeGraphVertex.getNumOutputConnections()of vertex Y is the Xth input to this vertexLayergetLayer()Get the Layer (if any).intgetNumInputArrays()Get the number of input arrays.intgetNumOutputConnections()Get the number of outgoing connections from this GraphVertex.VertexIndices[]getOutputVertices()A representation of the vertices that this vertex is connected to (outputs duing forward pass) Specifically, if outputVertices[X].getVertexIndex() = Y, and outputVertices[X].getVertexEdgeNumber() = Z then the Xth output of this vertex is connected to the Zth input of vertex YintgetVertexIndex()Get the index of the GraphVertexStringgetVertexName()Get the name/label of the GraphVertexbooleanhasLayer()Whether the GraphVertex contains aLayerobject or notbooleanisInputVertex()Whether the GraphVertex is an input vertexbooleanisOutputVertex()Whether the GraphVertex is an output vertexlongnumParams()INDArrayparams()Map<String,INDArray>paramTable(boolean backpropOnly)Get the parameter table for the vertexvoidsetBackpropGradientsViewArray(INDArray backpropGradientsViewArray)voidsetEpsilon(INDArray epsilon)Set the errors (epsilon - aka dL/dActivation) for this GraphVertexvoidsetInput(int inputNumber, INDArray input, LayerWorkspaceMgr workspaceMgr)Set the input activations.voidsetInputs(INDArray... inputs)Set all inputs for this GraphVertexvoidsetInputVertices(VertexIndices[] inputVertices)Sets the input vertices.voidsetLayerAsFrozen()Only applies to layer vertices.voidsetOutputVertex(boolean outputVertex)Set the GraphVertex to be an output vertexvoidsetOutputVertices(VertexIndices[] outputVertices)set the output vertices.booleanupdaterDivideByMinibatch(String paramName)DL4J layers typically produce the sum of the gradients during the backward pass for each layer, and if required (if minibatch=true) then divide by the minibatch size.
However, there are some exceptions, such as the batch norm mean/variance estimate parameters: these "gradients" are actually not gradients, but are updates to be applied directly to the parameter vector.
-
-
-
Field Detail
-
underlying
protected GraphVertex underlying
-
-
Constructor Detail
-
BaseWrapperVertex
protected BaseWrapperVertex(GraphVertex underlying)
-
-
Method Detail
-
getVertexName
public String getVertexName()
Description copied from interface:GraphVertexGet the name/label of the GraphVertex- Specified by:
getVertexNamein interfaceGraphVertex
-
getVertexIndex
public int getVertexIndex()
Description copied from interface:GraphVertexGet the index of the GraphVertex- Specified by:
getVertexIndexin interfaceGraphVertex
-
getNumInputArrays
public int getNumInputArrays()
Description copied from interface:GraphVertexGet the number of input arrays. For example, a Layer may have only one input array, but in general a GraphVertex may have an arbtrary (>=1) number of input arrays (for example, from multiple other layers)- Specified by:
getNumInputArraysin interfaceGraphVertex
-
getNumOutputConnections
public int getNumOutputConnections()
Description copied from interface:GraphVertexGet the number of outgoing connections from this GraphVertex. A GraphVertex may only have a single output (for example, the activations out of a layer), but this output may be used as the input to an arbitrary number of other GraphVertex instances. This method returns the number of GraphVertex instances the output of this GraphVertex is input for.- Specified by:
getNumOutputConnectionsin interfaceGraphVertex
-
getInputVertices
public VertexIndices[] getInputVertices()
Description copied from interface:GraphVertexA representation of the vertices that are inputs to this vertex (inputs duing forward pass)
Specifically, if inputVertices[X].getVertexIndex() = Y, and inputVertices[X].getVertexEdgeNumber() = Z then the Zth output connection (seeGraphVertex.getNumOutputConnections()of vertex Y is the Xth input to this vertex- Specified by:
getInputVerticesin interfaceGraphVertex
-
setInputVertices
public void setInputVertices(VertexIndices[] inputVertices)
Description copied from interface:GraphVertexSets the input vertices.- Specified by:
setInputVerticesin interfaceGraphVertex- See Also:
GraphVertex.getInputVertices()
-
getOutputVertices
public VertexIndices[] getOutputVertices()
Description copied from interface:GraphVertexA representation of the vertices that this vertex is connected to (outputs duing forward pass) Specifically, if outputVertices[X].getVertexIndex() = Y, and outputVertices[X].getVertexEdgeNumber() = Z then the Xth output of this vertex is connected to the Zth input of vertex Y- Specified by:
getOutputVerticesin interfaceGraphVertex
-
setOutputVertices
public void setOutputVertices(VertexIndices[] outputVertices)
Description copied from interface:GraphVertexset the output vertices.- Specified by:
setOutputVerticesin interfaceGraphVertex- See Also:
GraphVertex.getOutputVertices()
-
hasLayer
public boolean hasLayer()
Description copied from interface:GraphVertexWhether the GraphVertex contains aLayerobject or not- Specified by:
hasLayerin interfaceGraphVertex
-
isInputVertex
public boolean isInputVertex()
Description copied from interface:GraphVertexWhether the GraphVertex is an input vertex- Specified by:
isInputVertexin interfaceGraphVertex
-
isOutputVertex
public boolean isOutputVertex()
Description copied from interface:GraphVertexWhether the GraphVertex is an output vertex- Specified by:
isOutputVertexin interfaceGraphVertex
-
setOutputVertex
public void setOutputVertex(boolean outputVertex)
Description copied from interface:GraphVertexSet the GraphVertex to be an output vertex- Specified by:
setOutputVertexin interfaceGraphVertex
-
getLayer
public Layer getLayer()
Description copied from interface:GraphVertexGet the Layer (if any). Returns null ifGraphVertex.hasLayer()== false- Specified by:
getLayerin interfaceGraphVertex
-
setInput
public void setInput(int inputNumber, INDArray input, LayerWorkspaceMgr workspaceMgr)Description copied from interface:GraphVertexSet the input activations.- Specified by:
setInputin interfaceGraphVertex- Parameters:
inputNumber- Must be in range 0 toGraphVertex.getNumInputArrays()-1input- The input array
-
setEpsilon
public void setEpsilon(INDArray epsilon)
Description copied from interface:GraphVertexSet the errors (epsilon - aka dL/dActivation) for this GraphVertex- Specified by:
setEpsilonin interfaceGraphVertex
-
clear
public void clear()
Description copied from interface:GraphVertexClear the internal state (if any) of the GraphVertex. For example, any stored inputs/errors- Specified by:
clearin interfaceGraphVertex
-
canDoForward
public boolean canDoForward()
Description copied from interface:GraphVertexWhether the GraphVertex can do forward pass. Typically, this is just whether all inputs are set.- Specified by:
canDoForwardin interfaceGraphVertex
-
canDoBackward
public boolean canDoBackward()
Description copied from interface:GraphVertexWhether the GraphVertex can do backward pass. Typically, this is just whether all errors/epsilons are set- Specified by:
canDoBackwardin interfaceGraphVertex
-
doForward
public INDArray doForward(boolean training, LayerWorkspaceMgr workspaceMgr)
Description copied from interface:GraphVertexDo forward pass using the stored inputs- Specified by:
doForwardin interfaceGraphVertex- Parameters:
training- if true: forward pass at training time. If false: forward pass at test time- Returns:
- The output (for example, activations) of the GraphVertex
-
doBackward
public Pair<Gradient,INDArray[]> doBackward(boolean tbptt, LayerWorkspaceMgr workspaceMgr)
Description copied from interface:GraphVertexDo backward pass- Specified by:
doBackwardin interfaceGraphVertex- Parameters:
tbptt- If true: do backprop using truncated BPTT- Returns:
- The gradients (may be null), and the errors/epsilons for all inputs to this GraphVertex
-
getInputs
public INDArray[] getInputs()
Description copied from interface:GraphVertexGet the array of inputs previously set for this GraphVertex- Specified by:
getInputsin interfaceGraphVertex
-
getEpsilon
public INDArray getEpsilon()
Description copied from interface:GraphVertexGet the epsilon/error (i.e., dL/dOutput) array previously set for this GraphVertex- Specified by:
getEpsilonin interfaceGraphVertex
-
setInputs
public void setInputs(INDArray... inputs)
Description copied from interface:GraphVertexSet all inputs for this GraphVertex- Specified by:
setInputsin interfaceGraphVertex- See Also:
GraphVertex.setInput(int, INDArray, LayerWorkspaceMgr)
-
getGradientsViewArray
public INDArray getGradientsViewArray()
- Specified by:
getGradientsViewArrayin interfaceTrainable- Returns:
- 1D gradients view array
-
setBackpropGradientsViewArray
public void setBackpropGradientsViewArray(INDArray backpropGradientsViewArray)
Description copied from interface:GraphVertex- Specified by:
setBackpropGradientsViewArrayin interfaceGraphVertex
-
feedForwardMaskArrays
public Pair<INDArray,MaskState> feedForwardMaskArrays(INDArray[] maskArrays, MaskState currentMaskState, int minibatchSize)
- Specified by:
feedForwardMaskArraysin interfaceGraphVertex
-
setLayerAsFrozen
public void setLayerAsFrozen()
Description copied from interface:GraphVertexOnly applies to layer vertices. Will throw exceptions on others. If applied to a layer vertex it will treat the parameters of the layer within it as constant. Activations through these will be calculated as they would as test time regardless of training mode- Specified by:
setLayerAsFrozenin interfaceGraphVertex
-
clearVertex
public void clearVertex()
Description copied from interface:GraphVertexThis method clears inpjut for this vertex- Specified by:
clearVertexin interfaceGraphVertex
-
paramTable
public Map<String,INDArray> paramTable(boolean backpropOnly)
Description copied from interface:GraphVertexGet the parameter table for the vertex- Specified by:
paramTablein interfaceGraphVertex- Specified by:
paramTablein interfaceTrainable- Parameters:
backpropOnly- If true: exclude unsupervised training parameters- Returns:
- Parameter table
-
getConfig
public TrainingConfig getConfig()
-
params
public INDArray params()
-
numParams
public long numParams()
-
updaterDivideByMinibatch
public boolean updaterDivideByMinibatch(String paramName)
Description copied from interface:TrainableDL4J layers typically produce the sum of the gradients during the backward pass for each layer, and if required (if minibatch=true) then divide by the minibatch size.
However, there are some exceptions, such as the batch norm mean/variance estimate parameters: these "gradients" are actually not gradients, but are updates to be applied directly to the parameter vector. Put another way, most gradients should be divided by the minibatch to get the average; some "gradients" are actually final updates already, and should not be divided by the minibatch size.- Specified by:
updaterDivideByMinibatchin interfaceTrainable- Parameters:
paramName- Name of the parameter- Returns:
- True if gradients should be divided by minibatch (most params); false otherwise (edge cases like batch norm mean/variance estimates)
-
-