Package org.deeplearning4j.nn.conf
Class ComputationGraphConfiguration.GraphBuilder
- java.lang.Object
-
- org.deeplearning4j.nn.conf.ComputationGraphConfiguration.GraphBuilder
-
- Enclosing class:
- ComputationGraphConfiguration
public static class ComputationGraphConfiguration.GraphBuilder extends Object
-
-
Field Summary
Fields Modifier and Type Field Description protected boolean
allowDisconnected
protected boolean
allowNoOutput
protected BackpropType
backpropType
protected NeuralNetConfiguration.Builder
globalConfiguration
protected Map<String,InputPreProcessor>
inputPreProcessors
protected String
lastAdded
protected List<String>
networkInputs
protected List<InputType>
networkInputTypes
protected List<String>
networkOutputs
protected int
tbpttBackLength
protected int
tbpttFwdLength
protected boolean
validateOutputConfig
protected boolean
validateTbpttConfig
protected Map<String,List<String>>
vertexInputs
Key: graph node.protected Map<String,GraphVertex>
vertices
-
Constructor Summary
Constructors Constructor Description GraphBuilder(ComputationGraphConfiguration newConf, NeuralNetConfiguration.Builder globalConfiguration)
GraphBuilder(NeuralNetConfiguration.Builder globalConfiguration)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description ComputationGraphConfiguration.GraphBuilder
addInputs(String... inputNames)
Specify the inputs to the network, and their associated labels.ComputationGraphConfiguration.GraphBuilder
addInputs(Collection<String> inputNames)
Specify the inputs to the network, and their associated labels.ComputationGraphConfiguration.GraphBuilder
addLayer(String layerName, Layer layer, String... layerInputs)
Add a layer, with noInputPreProcessor
, with the specified name and specified inputs.ComputationGraphConfiguration.GraphBuilder
addLayer(String layerName, Layer layer, InputPreProcessor preProcessor, String... layerInputs)
Add a layer and anInputPreProcessor
, with the specified name and specified inputs.ComputationGraphConfiguration.GraphBuilder
addVertex(String vertexName, GraphVertex vertex, String... vertexInputs)
Add aGraphVertex
to the network configuration.ComputationGraphConfiguration.GraphBuilder
allowDisconnected(boolean allowDisconnected)
Used only during validation after building.
If true: don't throw an exception on configurations containing vertices that are 'disconnected'.ComputationGraphConfiguration.GraphBuilder
allowNoOutput(boolean allowNoOutput)
Used only during validation after building.
If true: don't throw an exception on configurations without any outputs.ComputationGraphConfiguration.GraphBuilder
appendLayer(String layerName, Layer layer)
Add a layer, with noInputPreProcessor
, with the specified name and input from the last added layer/vertex.ComputationGraphConfiguration.GraphBuilder
appendLayer(String layerName, Layer layer, InputPreProcessor preProcessor)
Add a layer and anInputPreProcessor
, with the specified name and input from the last added layer/vertex.ComputationGraphConfiguration.GraphBuilder
appendVertex(String vertexName, GraphVertex vertex)
Add aGraphVertex
to the network configuration, with input from the last added vertex/layer.ComputationGraphConfiguration.GraphBuilder
backpropType(BackpropType type)
The type of backprop.ComputationGraphConfiguration
build()
Create the ComputationGraphConfiguration from the Builder patternMap<String,InputType>
getLayerActivationTypes()
For the (perhaps partially constructed) network configuration, return a map of activation sizes for each layer and vertex in the graph.
Note 1: The network configuration may be incomplete, but the inputs have been added to the layer already.
Note 2: To use this method, the network input types must have been set usingsetInputTypes(InputType...)
firstComputationGraphConfiguration.GraphBuilder
inputPreProcessor(String layer, InputPreProcessor processor)
Specify the processors for a given layer These are used at each layer for doing things like normalization and shaping of input.
Note: preprocessors can also be defined using theaddLayer(String, Layer, InputPreProcessor, String...)
method.ComputationGraphConfiguration.GraphBuilder
layer(int layerName, Layer layer, String... layerInputs)
Add a layer, with noInputPreProcessor
, with the specified name and specified inputs.ComputationGraphConfiguration.GraphBuilder
layer(String layerName, Layer layer, String... layerInputs)
Add a layer, with noInputPreProcessor
, with the specified name and specified inputs.ComputationGraphConfiguration.GraphBuilder
layer(String layerName, Layer layer, InputPreProcessor preProcessor, String... layerInputs)
Add a layer and anInputPreProcessor
, with the specified name and specified inputs.ComputationGraphConfiguration.GraphBuilder
removeVertex(String vertexName)
Intended for use with the transfer learning API.ComputationGraphConfiguration.GraphBuilder
removeVertex(String vertexName, boolean removeConnections)
Intended for use with the transfer learning API.ComputationGraphConfiguration.GraphBuilder
setInputTypes(InputType... inputTypes)
Specify the types of inputs to the network, so that:
(a) preprocessors can be automatically added, and
(b) the nIns (input size) for each layer can be automatically calculated and set
The order here is the same order as .addInputs().ComputationGraphConfiguration.GraphBuilder
setOutputs(String... outputNames)
Set the network output labels.ComputationGraphConfiguration.GraphBuilder
tBPTTBackwardLength(int backwardLength)
When doing truncated BPTT: how many steps of backward should we do?
Only applicable when doing backpropType(BackpropType.TruncatedBPTT)
This is the k2 parameter on pg23 of http://www.cs.utoronto.ca/~ilya/pubs/ilya_sutskever_phd_thesis.pdfComputationGraphConfiguration.GraphBuilder
tBPTTForwardLength(int forwardLength)
When doing truncated BPTT: how many steps of forward pass should we do before doing (truncated) backprop?
Only applicable when doing backpropType(BackpropType.TruncatedBPTT)
Typically tBPTTForwardLength parameter is same as the tBPTTBackwardLength parameter, but may be larger than it in some circumstances (but never smaller)
Ideally your training data time series length should be divisible by this This is the k1 parameter on pg23 of http://www.cs.utoronto.ca/~ilya/pubs/ilya_sutskever_phd_thesis.pdfComputationGraphConfiguration.GraphBuilder
tBPTTLength(int tbpttLength)
When doing truncated backpropagation through time (tBPTT): how many steps should we do?
Only applicable when doing backpropType(BackpropType.TruncatedBPTT)
See: http://www.cs.utoronto.ca/~ilya/pubs/ilya_sutskever_phd_thesis.pdfComputationGraphConfiguration.GraphBuilder
validateOutputLayerConfig(boolean validate)
Enabled by default.ComputationGraphConfiguration.GraphBuilder
validateTbpttConfig(boolean validate)
Enabled by default.
-
-
-
Field Detail
-
vertices
protected Map<String,GraphVertex> vertices
-
vertexInputs
protected Map<String,List<String>> vertexInputs
Key: graph node. Values: input to that node
-
backpropType
protected BackpropType backpropType
-
tbpttFwdLength
protected int tbpttFwdLength
-
tbpttBackLength
protected int tbpttBackLength
-
inputPreProcessors
protected Map<String,InputPreProcessor> inputPreProcessors
-
globalConfiguration
protected NeuralNetConfiguration.Builder globalConfiguration
-
allowDisconnected
protected boolean allowDisconnected
-
allowNoOutput
protected boolean allowNoOutput
-
validateOutputConfig
protected boolean validateOutputConfig
-
validateTbpttConfig
protected boolean validateTbpttConfig
-
lastAdded
protected String lastAdded
-
-
Constructor Detail
-
GraphBuilder
public GraphBuilder(NeuralNetConfiguration.Builder globalConfiguration)
-
GraphBuilder
public GraphBuilder(ComputationGraphConfiguration newConf, NeuralNetConfiguration.Builder globalConfiguration)
-
-
Method Detail
-
inputPreProcessor
public ComputationGraphConfiguration.GraphBuilder inputPreProcessor(String layer, InputPreProcessor processor)
Specify the processors for a given layer These are used at each layer for doing things like normalization and shaping of input.
Note: preprocessors can also be defined using theaddLayer(String, Layer, InputPreProcessor, String...)
method.- Parameters:
layer
- the name of the layer that this preprocessor will be used withprocessor
- the preprocessor to use for the specified layer
-
backpropType
public ComputationGraphConfiguration.GraphBuilder backpropType(BackpropType type)
The type of backprop. Default setting is used for most networks (MLP, CNN etc), but optionally truncated BPTT can be used for training recurrent neural networks. If using TruncatedBPTT make sure you set both tBPTTForwardLength() and tBPTTBackwardLength()- Parameters:
type
- Type of backprop. Default: BackpropType.Standard
-
tBPTTForwardLength
public ComputationGraphConfiguration.GraphBuilder tBPTTForwardLength(int forwardLength)
When doing truncated BPTT: how many steps of forward pass should we do before doing (truncated) backprop?
Only applicable when doing backpropType(BackpropType.TruncatedBPTT)
Typically tBPTTForwardLength parameter is same as the tBPTTBackwardLength parameter, but may be larger than it in some circumstances (but never smaller)
Ideally your training data time series length should be divisible by this This is the k1 parameter on pg23 of http://www.cs.utoronto.ca/~ilya/pubs/ilya_sutskever_phd_thesis.pdf- Parameters:
forwardLength
- Forward length > 0, >= backwardLength
-
tBPTTBackwardLength
public ComputationGraphConfiguration.GraphBuilder tBPTTBackwardLength(int backwardLength)
When doing truncated BPTT: how many steps of backward should we do?
Only applicable when doing backpropType(BackpropType.TruncatedBPTT)
This is the k2 parameter on pg23 of http://www.cs.utoronto.ca/~ilya/pubs/ilya_sutskever_phd_thesis.pdf- Parameters:
backwardLength
- <= forwardLength
-
tBPTTLength
public ComputationGraphConfiguration.GraphBuilder tBPTTLength(int tbpttLength)
When doing truncated backpropagation through time (tBPTT): how many steps should we do?
Only applicable when doing backpropType(BackpropType.TruncatedBPTT)
See: http://www.cs.utoronto.ca/~ilya/pubs/ilya_sutskever_phd_thesis.pdf- Parameters:
tbpttLength
- length > 0
-
addLayer
public ComputationGraphConfiguration.GraphBuilder addLayer(String layerName, Layer layer, String... layerInputs)
Add a layer, with noInputPreProcessor
, with the specified name and specified inputs.- Parameters:
layerName
- Name/label of the layer to addlayer
- The layer configurationlayerInputs
- Inputs to this layer. Inputs may be other layers, GraphVertex objects, on a combination of the two.- See Also:
addLayer(String, Layer, InputPreProcessor, String...)
-
appendLayer
public ComputationGraphConfiguration.GraphBuilder appendLayer(String layerName, Layer layer)
Add a layer, with noInputPreProcessor
, with the specified name and input from the last added layer/vertex.- Parameters:
layerName
- Name/label of the layer to addlayer
- The layer configuration- See Also:
addLayer(String, Layer, InputPreProcessor, String...)
-
layer
public ComputationGraphConfiguration.GraphBuilder layer(int layerName, Layer layer, String... layerInputs)
Add a layer, with noInputPreProcessor
, with the specified name and specified inputs.- Parameters:
layerName
- Name/label of the layer to addlayer
- The layer configurationlayerInputs
- Inputs to this layer. Inputs may be other layers, GraphVertex objects, on a combination of the two.- See Also:
addLayer(String, Layer, InputPreProcessor, String...)
-
layer
public ComputationGraphConfiguration.GraphBuilder layer(String layerName, Layer layer, String... layerInputs)
Add a layer, with noInputPreProcessor
, with the specified name and specified inputs.- Parameters:
layerName
- Name/label of the layer to addlayer
- The layer configurationlayerInputs
- Inputs to this layer. Inputs may be other layers, GraphVertex objects, on a combination of the two.- See Also:
addLayer(String, Layer, InputPreProcessor, String...)
-
addLayer
public ComputationGraphConfiguration.GraphBuilder addLayer(String layerName, Layer layer, InputPreProcessor preProcessor, String... layerInputs)
Add a layer and anInputPreProcessor
, with the specified name and specified inputs.- Parameters:
layerName
- Name/label of the layer to addlayer
- The layer configurationpreProcessor
- The InputPreProcessor to use with this layer.layerInputs
- Inputs to this layer. Inputs may be other layers, GraphVertex objects, on a combination of the two.
-
appendLayer
public ComputationGraphConfiguration.GraphBuilder appendLayer(String layerName, Layer layer, InputPreProcessor preProcessor)
Add a layer and anInputPreProcessor
, with the specified name and input from the last added layer/vertex.- Parameters:
layerName
- Name/label of the layer to addlayer
- The layer configurationpreProcessor
- The InputPreProcessor to use with this layer.
-
layer
public ComputationGraphConfiguration.GraphBuilder layer(String layerName, Layer layer, InputPreProcessor preProcessor, String... layerInputs)
Add a layer and anInputPreProcessor
, with the specified name and specified inputs.- Parameters:
layerName
- Name/label of the layer to addlayer
- The layer configurationpreProcessor
- The InputPreProcessor to use with this layer.layerInputs
- Inputs to this layer. Inputs may be other layers, GraphVertex objects, on a combination of the two.
-
removeVertex
public ComputationGraphConfiguration.GraphBuilder removeVertex(String vertexName)
Intended for use with the transfer learning API. Users discouraged from employing it directly. Removes the specified vertex from the vertices list, it's connections and associated preprocessor If the vertex removed is an output vertex it will also be removed from the list of outputs- Parameters:
vertexName
- Name of the vertex to remove
-
removeVertex
public ComputationGraphConfiguration.GraphBuilder removeVertex(String vertexName, boolean removeConnections)
Intended for use with the transfer learning API. Users discouraged from employing it directly. Removes the specified vertex from the vertices list, Removes it's connections (associated preprocessor and if an output also removes it from list of outputs) if "removeConnections" is specified as true Specifying as false can leave the graph in an invalid state with references to vertices that donot exist unless a new vertex is added back in with the same name- Parameters:
removeConnections
- Specify true to remove connectionsvertexName
- Name of the vertex to remove
-
addInputs
public ComputationGraphConfiguration.GraphBuilder addInputs(String... inputNames)
Specify the inputs to the network, and their associated labels.- Parameters:
inputNames
- The names of the inputs. This also defines their order
-
addInputs
public ComputationGraphConfiguration.GraphBuilder addInputs(Collection<String> inputNames)
Specify the inputs to the network, and their associated labels.- Parameters:
inputNames
- The names of the inputs. This also defines their order
-
setInputTypes
public ComputationGraphConfiguration.GraphBuilder setInputTypes(InputType... inputTypes)
Specify the types of inputs to the network, so that:
(a) preprocessors can be automatically added, and
(b) the nIns (input size) for each layer can be automatically calculated and set
The order here is the same order as .addInputs(). Thus, if you do .addInputs("a","b") and .setInputTypes(InputType.feedForward(), InputType.convolutional(28,28,1)) then the input labelled "a" is a feed forward input, whereas the input labelled "b" in a CNN input, with 28x28x1 images as input.
Note: Using setInputTypes is not always necessary, but can be especially helpful for example with CNNs such that the calculations on input/output sizes (width, height, channels, etc) don't need to be done manually.
Note 2: If a preprocessor is manually added for a given layer, it will not be overridden by the automatic addition of preprocessors. Note 3: If a layer has an nIn set manually, this will not be overridden
-
setOutputs
public ComputationGraphConfiguration.GraphBuilder setOutputs(String... outputNames)
Set the network output labels. These should be the names of the OutputLayer instances in the network- Parameters:
outputNames
- The names of the output layers. This also defines their order.
-
addVertex
public ComputationGraphConfiguration.GraphBuilder addVertex(String vertexName, GraphVertex vertex, String... vertexInputs)
Add aGraphVertex
to the network configuration. A GraphVertex defines forward and backward pass methods, and can contain aLayerVertex
, aElementWiseVertex
to do element-wise addition/subtraction, aMergeVertex
to combine/concatenate the activations out of multiple layers or vertices, aSubsetVertex
to select a subset of the activations out of another layer/GraphVertex.
Custom GraphVertex objects (that extend the abstractGraphVertex
class) may also be used.- Parameters:
vertexName
- The name of the GraphVertex to addvertex
- The GraphVertex to addvertexInputs
- The inputs/activations to this GraphVertex.
-
appendVertex
public ComputationGraphConfiguration.GraphBuilder appendVertex(String vertexName, GraphVertex vertex)
Add aGraphVertex
to the network configuration, with input from the last added vertex/layer. A GraphVertex defines forward and backward pass methods, and can contain aLayerVertex
, aElementWiseVertex
to do element-wise addition/subtraction, aMergeVertex
to combine/concatenate the activations out of multiple layers or vertices, aSubsetVertex
to select a subset of the activations out of another layer/GraphVertex.
Custom GraphVertex objects (that extend the abstractGraphVertex
class) may also be used.- Parameters:
vertexName
- The name of the GraphVertex to addvertex
- The GraphVertex to add
-
allowDisconnected
public ComputationGraphConfiguration.GraphBuilder allowDisconnected(boolean allowDisconnected)
Used only during validation after building.
If true: don't throw an exception on configurations containing vertices that are 'disconnected'. A disconnected vertex is one that is not an output, and doesn't connect to any other vertices. i.e., it's output activations don't go anywhere. Most users can (and should) leave this as the default value of false.- Parameters:
allowDisconnected
- Whether to allow disconnected vertices, during validation
-
allowNoOutput
public ComputationGraphConfiguration.GraphBuilder allowNoOutput(boolean allowNoOutput)
Used only during validation after building.
If true: don't throw an exception on configurations without any outputs. This is enabled by default to avoid creating invalid graphs, but can be disabled if required.
Most users can (and should) leave this as the default value of false.- Parameters:
allowNoOutput
- Whether to allow no outputs, during validation
-
validateOutputLayerConfig
public ComputationGraphConfiguration.GraphBuilder validateOutputLayerConfig(boolean validate)
Enabled by default. If enabled, the output layer configuration will be validated, to throw an exception on likely invalid outputs - such as softmax + nOut=1, or LossMCXENT + Tanh.
If disabled (false) no output layer validation will be performed.
Disabling this validation is not recommended, as the configurations that fail validation usually will not be able to learn correctly. However, the option to disable this validation is provided for advanced users when creating non-standard architectures.- Parameters:
validate
- If true: validate output layer configuration. False: don't validate
-
validateTbpttConfig
public ComputationGraphConfiguration.GraphBuilder validateTbpttConfig(boolean validate)
Enabled by default. If enabled, an exception will be throw when using the (invalid) combination of truncated backpropagation through time (TBPTT) with either a GlobalPoolingLayer or LastTimeStepLayer.
It is possible to disable this validation to allow what is almost certainly an invalid configuration to be used, however this is not recommended.- Parameters:
validate
- Whether TBPTT validation should be performed
-
getLayerActivationTypes
public Map<String,InputType> getLayerActivationTypes()
For the (perhaps partially constructed) network configuration, return a map of activation sizes for each layer and vertex in the graph.
Note 1: The network configuration may be incomplete, but the inputs have been added to the layer already.
Note 2: To use this method, the network input types must have been set usingsetInputTypes(InputType...)
first- Returns:
- A map of activation types for the graph (key: vertex name. value: type of activations out of that vertex)
-
build
public ComputationGraphConfiguration build()
Create the ComputationGraphConfiguration from the Builder pattern
-
-