Class TransferLearning.GraphBuilder
- java.lang.Object
-
- org.deeplearning4j.nn.transferlearning.TransferLearning.GraphBuilder
-
- Enclosing class:
- TransferLearning
public static class TransferLearning.GraphBuilder extends Object
-
-
Constructor Summary
Constructors Constructor Description GraphBuilder(ComputationGraph origGraph)Computation Graph to tweak for transfer learning
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description TransferLearning.GraphBuilderaddInputs(String... inputNames)TransferLearning.GraphBuilderaddLayer(String layerName, Layer layer, String... layerInputs)Add a layer of the specified configuration to the computation graphTransferLearning.GraphBuilderaddLayer(String layerName, Layer layer, InputPreProcessor preProcessor, String... layerInputs)Add a layer with a specified preprocessorTransferLearning.GraphBuilderaddVertex(String vertexName, GraphVertex vertex, String... vertexInputs)Add a vertex of the given configuration to the computation graphComputationGraphbuild()Returns a computation graph build to specifications.TransferLearning.GraphBuilderfineTuneConfiguration(FineTuneConfiguration fineTuneConfiguration)Set parameters to selectively override existing learning parameters Usage eg.TransferLearning.GraphBuildernInReplace(String layerName, int nIn, IWeightInit scheme)Modify the architecture of a vertex layer by changing nIn of the specified layer.
Note that only the specified layer will be modified - all other layers will not be changed by this call.TransferLearning.GraphBuildernInReplace(String layerName, int nIn, WeightInit scheme)Modify the architecture of a vertex layer by changing nIn of the specified layer.
Note that only the specified layer will be modified - all other layers will not be changed by this call.TransferLearning.GraphBuildernInReplace(String layerName, int nIn, WeightInit scheme, Distribution dist)Modify the architecture of a vertex layer by changing nIn of the specified layer.
Note that only the specified layer will be modified - all other layers will not be changed by this call.TransferLearning.GraphBuildernOutReplace(String layerName, int nOut, Distribution dist)Modify the architecture of a vertex layer by changing nOut Note this will also affect the vertex layer that follows the layer specified, unless it is the output layer Currently does not support modifying nOut of layers that feed into non-layer vertices like merge, subset etc To modify nOut for such vertices use remove vertex, followed by add vertex Can specify different weight init schemes for the specified layer and the layer that follows it.TransferLearning.GraphBuildernOutReplace(String layerName, int nOut, Distribution dist, Distribution distNext)Modified nOut of specified layer.TransferLearning.GraphBuildernOutReplace(String layerName, int nOut, Distribution dist, WeightInit scheme)TransferLearning.GraphBuildernOutReplace(String layerName, int nOut, WeightInit scheme)Modify the architecture of a vertex layer by changing nOut Note this will also affect the vertex layer that follows the layer specified, unless it is the output layer Currently does not support modifying nOut of layers that feed into non-layer vertices like merge, subset etc To modify nOut for such vertices use remove vertex, followed by add vertex Can specify different weight init schemes for the specified layer and the layer that follows it.TransferLearning.GraphBuildernOutReplace(String layerName, int nOut, WeightInit scheme, Distribution dist)TransferLearning.GraphBuildernOutReplace(String layerName, int nOut, WeightInit scheme, WeightInit schemeNext)TransferLearning.GraphBuilderremoveVertexAndConnections(String vertexName)Remove specified vertex and it's connections from the computation graphTransferLearning.GraphBuilderremoveVertexKeepConnections(String outputName)Remove the specified vertex from the computation graph but keep it's connections.TransferLearning.GraphBuildersetFeatureExtractor(String... layerName)Specify a layer vertex to set as a "feature extractor" The specified layer vertex and the layers on the path from an input vertex to it will be "frozen" with parameters staying constantTransferLearning.GraphBuildersetInputs(String... inputs)Sets new inputs for the computation graph.TransferLearning.GraphBuildersetInputTypes(InputType... inputTypes)Sets the input type of corresponding inputs.TransferLearning.GraphBuildersetOutputs(String... outputNames)Set outputs to the computation graph, will add to ones that are existing Also determines the order, like in ComputationGraphConfigurationTransferLearning.GraphBuildersetWorkspaceMode(WorkspaceMode workspaceMode)TransferLearning.GraphBuildervalidateOutputLayerConfig(boolean validateOutputLayerConfig)
-
-
-
Constructor Detail
-
GraphBuilder
public GraphBuilder(ComputationGraph origGraph)
Computation Graph to tweak for transfer learning- Parameters:
origGraph-
-
-
Method Detail
-
fineTuneConfiguration
public TransferLearning.GraphBuilder fineTuneConfiguration(FineTuneConfiguration fineTuneConfiguration)
Set parameters to selectively override existing learning parameters Usage eg. specify a lower learning rate. This will get applied to all layers- Parameters:
fineTuneConfiguration-- Returns:
- GraphBuilder
-
setFeatureExtractor
public TransferLearning.GraphBuilder setFeatureExtractor(String... layerName)
Specify a layer vertex to set as a "feature extractor" The specified layer vertex and the layers on the path from an input vertex to it will be "frozen" with parameters staying constant- Parameters:
layerName-- Returns:
- Builder
-
nOutReplace
public TransferLearning.GraphBuilder nOutReplace(String layerName, int nOut, WeightInit scheme)
Modify the architecture of a vertex layer by changing nOut Note this will also affect the vertex layer that follows the layer specified, unless it is the output layer Currently does not support modifying nOut of layers that feed into non-layer vertices like merge, subset etc To modify nOut for such vertices use remove vertex, followed by add vertex Can specify different weight init schemes for the specified layer and the layer that follows it.- Parameters:
layerName- The name of the layer to change nOut ofnOut- Value of nOut to change toscheme- Weight init scheme to use for params in layerName and the layers following it- Returns:
- GraphBuilder
- See Also:
DISTRIBUTION
-
nOutReplace
public TransferLearning.GraphBuilder nOutReplace(String layerName, int nOut, Distribution dist)
Modify the architecture of a vertex layer by changing nOut Note this will also affect the vertex layer that follows the layer specified, unless it is the output layer Currently does not support modifying nOut of layers that feed into non-layer vertices like merge, subset etc To modify nOut for such vertices use remove vertex, followed by add vertex Can specify different weight init schemes for the specified layer and the layer that follows it.- Parameters:
layerName- The name of the layer to change nOut ofnOut- Value of nOut to change todist- Weight distribution scheme to use- Returns:
- GraphBuilder
- See Also:
DISTRIBUTION
-
nOutReplace
public TransferLearning.GraphBuilder nOutReplace(String layerName, int nOut, Distribution dist, Distribution distNext)
Modified nOut of specified layer. Also affects layers following layerName unless they are output layers- Parameters:
layerName- The name of the layer to change nOut ofnOut- Value of nOut to change todist- Weight distribution scheme to use for layerNamedistNext- Weight distribution scheme for layers following layerName- Returns:
- GraphBuilder
- See Also:
DISTRIBUTION
-
nOutReplace
public TransferLearning.GraphBuilder nOutReplace(String layerName, int nOut, WeightInit scheme, Distribution dist)
-
nOutReplace
public TransferLearning.GraphBuilder nOutReplace(String layerName, int nOut, Distribution dist, WeightInit scheme)
-
nOutReplace
public TransferLearning.GraphBuilder nOutReplace(String layerName, int nOut, WeightInit scheme, WeightInit schemeNext)
-
nInReplace
public TransferLearning.GraphBuilder nInReplace(String layerName, int nIn, WeightInit scheme)
Modify the architecture of a vertex layer by changing nIn of the specified layer.
Note that only the specified layer will be modified - all other layers will not be changed by this call.- Parameters:
layerName- The name of the layer to change nIn ofnIn- Value of nIn to change toscheme- Weight init scheme to use for params in layerName- Returns:
- GraphBuilder
-
validateOutputLayerConfig
public TransferLearning.GraphBuilder validateOutputLayerConfig(boolean validateOutputLayerConfig)
-
nInReplace
public TransferLearning.GraphBuilder nInReplace(String layerName, int nIn, WeightInit scheme, Distribution dist)
Modify the architecture of a vertex layer by changing nIn of the specified layer.
Note that only the specified layer will be modified - all other layers will not be changed by this call.- Parameters:
layerName- The name of the layer to change nIn ofnIn- Value of nIn to change toscheme- Weight init scheme to use for params in layerName and the layers following it- Returns:
- GraphBuilder
-
nInReplace
public TransferLearning.GraphBuilder nInReplace(String layerName, int nIn, IWeightInit scheme)
Modify the architecture of a vertex layer by changing nIn of the specified layer.
Note that only the specified layer will be modified - all other layers will not be changed by this call.- Parameters:
layerName- The name of the layer to change nIn ofnIn- Value of nIn to change toscheme- Weight init scheme to use for params in layerName and the layers following it- Returns:
- GraphBuilder
-
removeVertexKeepConnections
public TransferLearning.GraphBuilder removeVertexKeepConnections(String outputName)
Remove the specified vertex from the computation graph but keep it's connections. Note the expectation here is to then add back another vertex with the same name or else the graph will be left in an invalid state Possibly with references to vertices that no longer exist- Parameters:
outputName-- Returns:
-
removeVertexAndConnections
public TransferLearning.GraphBuilder removeVertexAndConnections(String vertexName)
Remove specified vertex and it's connections from the computation graph- Parameters:
vertexName-- Returns:
-
addLayer
public TransferLearning.GraphBuilder addLayer(String layerName, Layer layer, String... layerInputs)
Add a layer of the specified configuration to the computation graph- Parameters:
layerName-layer-layerInputs-- Returns:
-
addLayer
public TransferLearning.GraphBuilder addLayer(String layerName, Layer layer, InputPreProcessor preProcessor, String... layerInputs)
Add a layer with a specified preprocessor- Parameters:
layerName-layer-preProcessor-layerInputs-- Returns:
-
addVertex
public TransferLearning.GraphBuilder addVertex(String vertexName, GraphVertex vertex, String... vertexInputs)
Add a vertex of the given configuration to the computation graph- Parameters:
vertexName-vertex-vertexInputs-- Returns:
-
setOutputs
public TransferLearning.GraphBuilder setOutputs(String... outputNames)
Set outputs to the computation graph, will add to ones that are existing Also determines the order, like in ComputationGraphConfiguration- Parameters:
outputNames-- Returns:
-
setInputs
public TransferLearning.GraphBuilder setInputs(String... inputs)
Sets new inputs for the computation graph. This method will remove any pre-existing inputs.- Parameters:
inputs- String names of each graph input.- Returns:
GraphBuilderinstance.
-
setInputTypes
public TransferLearning.GraphBuilder setInputTypes(InputType... inputTypes)
Sets the input type of corresponding inputs.- Parameters:
inputTypes- The type of input (such as convolutional).- Returns:
GraphBuilderinstance.
-
addInputs
public TransferLearning.GraphBuilder addInputs(String... inputNames)
-
setWorkspaceMode
public TransferLearning.GraphBuilder setWorkspaceMode(WorkspaceMode workspaceMode)
-
build
public ComputationGraph build()
Returns a computation graph build to specifications. Init has been internally called. Can be fit directly.- Returns:
- Computation graph
-
-