public class MultiLayerNetwork extends Object implements Serializable, Classifier, Layer, NeuralNetwork
ComputationGraph
which allows for an arbitrary directed acyclic graph connection structure between layers.
MultiLayerNetwork is trainable via backprop, with optional unsupervised layerwise training, depending on the type of layers it contains.Layer.TrainingMode, Layer.Type
Modifier and Type | Field and Description |
---|---|
protected boolean |
clearTbpttState |
protected NeuralNetConfiguration |
defaultConfiguration |
protected INDArray |
flattenedGradients |
protected INDArray |
flattenedParams |
protected Gradient |
gradient |
protected Map<String,org.bytedeco.javacpp.Pointer> |
helperWorkspaces |
protected boolean |
initCalled |
protected boolean |
initDone |
protected INDArray |
input |
protected INDArray |
labels |
protected ThreadLocal<Long> |
lastEtlTime |
protected int |
layerIndex |
protected LinkedHashMap<String,Layer> |
layerMap |
protected Layer[] |
layers |
protected MultiLayerConfiguration |
layerWiseConfigurations |
protected INDArray |
mask |
protected double |
score |
protected Solver |
solver |
protected Collection<TrainingListener> |
trainingListeners |
protected static String |
WS_ALL_LAYERS_ACT
Workspace for storing all layers' activations - used only to store activations (layer inputs) as part of backprop
Not used for inference
|
protected static org.nd4j.linalg.api.memory.conf.WorkspaceConfiguration |
WS_ALL_LAYERS_ACT_CONFIG |
protected static String |
WS_LAYER_ACT_1
Next 2 workspaces: used for:
(a) Inference: holds activations for one layer only
(b) Backprop: holds activation gradients for one layer only
In both cases, they are opened and closed on every second layer
|
protected static String |
WS_LAYER_ACT_2 |
protected org.nd4j.linalg.api.memory.conf.WorkspaceConfiguration |
WS_LAYER_ACT_X_CONFIG |
protected static String |
WS_LAYER_WORKING_MEM
Workspace for working memory for a single layer: forward pass and backward pass
Note that this is opened/closed once per op (activate/backpropGradient call)
|
protected org.nd4j.linalg.api.memory.conf.WorkspaceConfiguration |
WS_LAYER_WORKING_MEM_CONFIG |
protected static String |
WS_OUTPUT_MEM
Workspace for output methods that use OutputAdapter
|
protected static String |
WS_RNN_LOOP_WORKING_MEM
Workspace for working memory in RNNs - opened and closed once per RNN time step
|
protected static org.nd4j.linalg.api.memory.conf.WorkspaceConfiguration |
WS_RNN_LOOP_WORKING_MEM_CONFIG |
Constructor and Description |
---|
MultiLayerNetwork(MultiLayerConfiguration conf) |
MultiLayerNetwork(MultiLayerConfiguration conf,
INDArray params)
Initialize the network based on the configuration and parameters array
|
MultiLayerNetwork(String conf,
INDArray params)
Initialize the network based on the configuration (a MultiLayerConfiguration in JSON format) and parameters array
|
Modifier and Type | Method and Description |
---|---|
INDArray |
activate(boolean training,
LayerWorkspaceMgr mgr)
Perform forward pass and return the activations array with the last set input
|
INDArray |
activate(INDArray input,
boolean training,
LayerWorkspaceMgr mgr)
Perform forward pass and return the activations array with the specified input
|
INDArray |
activate(INDArray input,
Layer.TrainingMode training)
Equivalent to
#output(INDArray, TrainingMode) |
INDArray |
activate(Layer.TrainingMode training)
Equivalent to
output(INDArray) using the input set via setInput(INDArray) |
INDArray |
activateSelectedLayers(int from,
int to,
INDArray input)
Calculate activation for few layers at once.
|
protected INDArray |
activationFromPrevLayer(int curr,
INDArray input,
boolean training,
LayerWorkspaceMgr mgr) |
void |
addListeners(TrainingListener... listeners)
This method ADDS additional TrainingListener to existing listeners
|
void |
allowInputModification(boolean allow)
A performance optimization: mark whether the layer is allowed to modify its input array in-place.
|
void |
applyConstraints(int iteration,
int epoch)
Apply any constraints to the model
|
Pair<Gradient,INDArray> |
backpropGradient(INDArray epsilon,
LayerWorkspaceMgr workspaceMgr)
Calculate the gradient relative to the error in the next layer
|
int |
batchSize()
The current inputs batch size
|
protected Pair<Gradient,INDArray> |
calcBackpropGradients(INDArray epsilon,
boolean withOutputLayer,
boolean tbptt,
boolean returnInputActGrad)
Calculate gradients and errors.
|
double |
calcRegularizationScore(boolean backpropParamsOnly)
Calculate the regularization component of the score, for the parameters in this layer
For example, the L1, L2 and/or weight decay components of the loss function |
Pair<Gradient,INDArray> |
calculateGradients(INDArray features,
INDArray label,
INDArray fMask,
INDArray labelMask)
Calculate parameter gradients and input activation gradients given the input and labels, and optionally mask arrays
|
void |
clear()
Clear the inputs.
|
void |
clearLayerMaskArrays()
Remove the mask arrays from all layers.
See setLayerMaskArrays(INDArray, INDArray) for details on mask arrays. |
void |
clearLayersStates()
This method just makes sure there's no state preserved within layers
|
void |
clearNoiseWeightParams() |
MultiLayerNetwork |
clone()
Clone the MultiLayerNetwork
|
void |
computeGradientAndScore() |
void |
computeGradientAndScore(LayerWorkspaceMgr layerWorkspaceMgr)
Update the score
|
NeuralNetConfiguration |
conf()
The configuration for the neural network
|
MultiLayerNetwork |
convertDataType(org.nd4j.linalg.api.buffer.DataType dataType)
Return a copy of the network with the parameters and activations set to use the specified (floating point) data type.
|
<T extends IEvaluation> |
doEvaluation(DataSetIterator iterator,
T... evaluations)
Perform evaluation using an arbitrary IEvaluation instance.
|
<T extends IEvaluation> |
doEvaluation(MultiDataSetIterator iterator,
T[] evaluations)
This method executes evaluation of the model against given iterator and evaluation implementations
|
<T extends IEvaluation> |
doEvaluationHelper(DataSetIterator iterator,
T... evaluations) |
protected void |
doTruncatedBPTT(INDArray input,
INDArray labels,
INDArray featuresMaskArray,
INDArray labelsMaskArray,
LayerWorkspaceMgr workspaceMgr) |
boolean |
equals(Object obj)
Indicates whether some other object is "equal to" this one.
|
<T extends Evaluation> |
evaluate(DataSetIterator iterator)
Evaluate the network (classification performance)
|
Evaluation |
evaluate(DataSetIterator iterator,
List<String> labelsList)
Evaluate the network on the provided data set.
|
Evaluation |
evaluate(DataSetIterator iterator,
List<String> labelsList,
int topN)
Evaluate the network (for classification) on the provided data set, with top N accuracy in addition to standard accuracy.
|
<T extends RegressionEvaluation> |
evaluateRegression(DataSetIterator iterator)
Evaluate the network for regression performance
|
<T extends ROC> |
evaluateROC(DataSetIterator iterator)
Deprecated.
To be removed - use
evaluateROC(DataSetIterator, int) to enforce selection of appropriate ROC/threshold configuration |
<T extends ROC> |
evaluateROC(DataSetIterator iterator,
int rocThresholdSteps)
Evaluate the network (must be a binary classifier) on the specified data, using the
ROC class |
<T extends ROCMultiClass> |
evaluateROCMultiClass(DataSetIterator iterator)
Deprecated.
To be removed - use
evaluateROCMultiClass(DataSetIterator, int) to enforce selection of appropriate ROC/threshold configuration |
<T extends ROCMultiClass> |
evaluateROCMultiClass(DataSetIterator iterator,
int rocThresholdSteps)
Evaluate the network on the specified data, using the
ROCMultiClass class |
double |
f1Score(DataSet data)
Sets the input and labels and returns the F1 score for the prediction with respect to the true labels
|
double |
f1Score(INDArray input,
INDArray labels)
Perform inference and then calculate the F1 score of the output(input) vs.
|
List<INDArray> |
feedForward()
Compute activations of all layers from input (inclusive) to output of the final/output layer.
|
List<INDArray> |
feedForward(boolean train)
Compute activations from input to output of the output layer.
|
List<INDArray> |
feedForward(boolean train,
boolean clearInputs)
Perform feed-forward, optionally (not) clearing the layer input arrays.
Note: when using clearInputs=false, there can be some performance and memory overhead: this is because the arrays are defined outside of workspaces (which are enabled by default) - otherwise, old/invalidated arrays could still be accessed after calling this method. |
List<INDArray> |
feedForward(INDArray input)
Compute activations of all layers from input (inclusive) to output of the final/output layer.
|
List<INDArray> |
feedForward(INDArray input,
boolean train)
Compute all layer activations, from input to output of the output layer.
|
List<INDArray> |
feedForward(INDArray input,
INDArray featuresMask,
INDArray labelsMask)
Compute the activations from the input to the output layer, given mask arrays (that may be null)
The masking arrays are used in situations such an one-to-many and many-to-one rucerrent neural network (RNN)
designs, as well as for supporting time series of varying lengths within the same minibatch for RNNs.
|
Pair<INDArray,MaskState> |
feedForwardMaskArray(INDArray maskArray,
MaskState currentMaskState,
int minibatchSize)
Feed forward the input mask array, setting in the layer as appropriate.
|
List<INDArray> |
feedForwardToLayer(int layerNum,
boolean train)
Compute the activations from the input to the specified layer, using the currently set input for the network.
To compute activations for all layers, use feedForward(...) methods Note: output list includes the original input. |
List<INDArray> |
feedForwardToLayer(int layerNum,
INDArray input)
Compute the activations from the input to the specified layer.
To compute activations for all layers, use feedForward(...) methods Note: output list includes the original input. |
List<INDArray> |
feedForwardToLayer(int layerNum,
INDArray input,
boolean train)
Compute the activations from the input to the specified layer.
To compute activations for all layers, use feedForward(...) methods Note: output list includes the original input. |
protected List<INDArray> |
ffToLayerActivationsDetached(boolean train,
FwdPassType fwdPassType,
boolean storeLastForTBPTT,
int layerIndex,
INDArray input,
INDArray fMask,
INDArray lMask,
boolean clearInputs)
Feed-forward through the network - returning all array activations in a list, detached from any workspace.
|
protected List<INDArray> |
ffToLayerActivationsInWs(int layerIndex,
FwdPassType fwdPassType,
boolean storeLastForTBPTT,
INDArray input,
INDArray fMask,
INDArray lMask)
Feed-forward through the network at training time - returning a list of all activations in a workspace (WS_ALL_LAYERS_ACT)
if workspaces are enabled for training; or detached if no workspaces are used.
Note: if using workspaces for training, this method requires that WS_ALL_LAYERS_ACT is open externally. If using NO workspaces, requires that no external workspace is open Note that this method does NOT clear the inputs to each layer - instead, they are in the WS_ALL_LAYERS_ACT workspace for use in later backprop. |
void |
fit()
All models have a fit method
|
void |
fit(DataSet data)
Fit the model for one iteration on the provided data
|
void |
fit(DataSetIterator iterator)
Perform minibatch training on all minibatches in the DataSetIterator for 1 epoch.
Note that this method does not do layerwise pretraining. For pretraining use method pretrain.. |
void |
fit(DataSetIterator iterator,
int numEpochs)
Perform minibatch training on all minibatches in the DataSetIterator, for the specified number of epochs.
|
void |
fit(INDArray data,
INDArray labels)
Fit the model for one iteration on the provided data
|
void |
fit(INDArray features,
INDArray labels,
INDArray featuresMask,
INDArray labelsMask)
Fit the model for one iteration on the provided data
|
void |
fit(INDArray examples,
int[] labels)
Fit the model for one iteration on the provided data
|
void |
fit(INDArray data,
LayerWorkspaceMgr workspaceMgr)
Fit the model to the given data
|
void |
fit(MultiDataSet dataSet)
This method fits model with a given MultiDataSet
|
void |
fit(MultiDataSetIterator iterator)
Perform minibatch training on all minibatches in the MultiDataSetIterator.
Note: The MultiDataSets in the MultiDataSetIterator must have exactly 1 input and output array (as MultiLayerNetwork only supports 1 input and 1 output) |
void |
fit(MultiDataSetIterator iterator,
int numEpochs)
Perform minibatch training on all minibatches in the MultiDataSetIterator, for the specified number of epochs.
|
TrainingConfig |
getConfig() |
NeuralNetConfiguration |
getDefaultConfiguration()
Intended for internal/developer use
|
int |
getEpochCount() |
INDArray |
getGradientsViewArray() |
LayerHelper |
getHelper() |
int |
getIndex()
Get the layer index.
|
INDArray |
getInput() |
int |
getInputMiniBatchSize()
Get current/last input mini-batch size, as set by setInputMiniBatchSize(int)
|
int |
getIterationCount() |
INDArray |
getLabels() |
long |
getLastEtlTime()
Get the last ETL time.
|
Layer |
getLayer(int i) |
Layer |
getLayer(String name) |
protected static org.nd4j.linalg.api.memory.conf.WorkspaceConfiguration |
getLayerActivationWSConfig(int numLayers) |
List<String> |
getLayerNames() |
Layer[] |
getLayers() |
MultiLayerConfiguration |
getLayerWiseConfigurations()
Get the configuration for the network
|
protected static org.nd4j.linalg.api.memory.conf.WorkspaceConfiguration |
getLayerWorkingMemWSConfig(int numWorkingMemCycles) |
Double |
getLearningRate(int layerNumber)
Get the current learning rate, for the specified layer, from the network.
|
Collection<TrainingListener> |
getListeners()
Get the
TrainingListener s set for this network, if any |
INDArray |
getMask() |
INDArray |
getMaskArray() |
int |
getnLayers()
Get the number of layers in the network
|
ConvexOptimizer |
getOptimizer()
Returns this models optimizer
|
Layer |
getOutputLayer()
Get the output layer - i.e., the last layer in the netwok
|
INDArray |
getParam(String param)
Get one parameter array for the network.
In MultiLayerNetwork, parameters are keyed like "0_W" and "0_b" to mean "weights of layer index 0" and "biases of layer index 0" respectively. |
Collection<TrainingListener> |
getTrainingListeners()
Deprecated.
Use
getListeners() |
Updater |
getUpdater()
Get the updater for this MultiLayerNetwork
|
Updater |
getUpdater(boolean initializeIfReq) |
Gradient |
gradient()
Get the gradient.
|
Pair<Gradient,Double> |
gradientAndScore()
Get the gradient and score
|
protected boolean |
hasAFrozenLayer() |
void |
incrementEpochCount()
Increment the epoch count (in the underlying
MultiLayerConfiguration by 1). |
void |
init()
Initialize the MultiLayerNetwork.
|
void |
init(INDArray parameters,
boolean cloneParametersArray)
Initialize the MultiLayerNetwork, optionally with an existing parameters array.
|
void |
initGradientsView()
This method: initializes the flattened gradients array (used in backprop) and sets the appropriate subset in all layers.
|
INDArray |
input()
The input/feature matrix for the model
|
protected void |
intializeConfigurations() |
boolean |
isInitCalled() |
boolean |
isPretrainLayer()
Returns true if the layer can be trained in an unsupervised/pretrain manner (AE, VAE, etc)
|
int |
layerInputSize(int layer)
Return the input size (number of inputs) for the specified layer.
Note that the meaning of the "input size" can depend on the type of layer. |
int |
layerSize(int layer)
Return the layer size (number of units) for the specified layer.
Note that the meaning of the "layer size" can depend on the type of layer. |
static MultiLayerNetwork |
load(File f,
boolean loadUpdater)
Restore a MultiLayerNetwork to a file, saved using
save(File) or ModelSerializer |
String |
memoryInfo(int minibatch,
InputType inputType)
Generate information regarding memory use for the network, for the given input type and minibatch size.
|
int |
numLabels()
Deprecated.
Will be removed in a future release
|
long |
numParams()
Returns the number of parameters in the network
|
long |
numParams(boolean backwards)
Returns the number of parameters in the network
|
INDArray |
output(DataSetIterator iterator)
Equivalent to
output(DataSetIterator, boolean) with train=false |
INDArray |
output(DataSetIterator iterator,
boolean train)
Generate the output for all examples/batches in the input iterator, and concatenate them into a single array.
|
INDArray |
output(INDArray input)
Perform inference on the provided input/features - i.e., perform forward pass using the provided input/features
and return the output of the final layer.
|
INDArray |
output(INDArray input,
boolean train)
Perform inference on the provided input/features - i.e., perform forward pass using the provided input/features
and return the output of the final layer.
|
INDArray |
output(INDArray input,
boolean train,
INDArray featuresMask,
INDArray labelsMask)
Calculate the output of the network, with masking arrays.
|
INDArray |
output(INDArray input,
boolean train,
INDArray featuresMask,
INDArray labelsMask,
org.nd4j.linalg.api.memory.MemoryWorkspace outputWorkspace)
Get the network output, which is optionally placed in the specified memory workspace.
If no memory workspace is provided, the output will be detached (not in any workspace). If a memory workspace is provided, the output activation array (i.e., the INDArray returned by this method) will be placed in the specified workspace. |
INDArray |
output(INDArray input,
boolean train,
org.nd4j.linalg.api.memory.MemoryWorkspace outputWorkspace)
Get the network output, which is optionally placed in the specified memory workspace.
If no memory workspace is provided, the output will be detached (not in any workspace). If a memory workspace is provided, the output activation array (i.e., the INDArray returned by this method) will be placed in the specified workspace. |
<T> T |
output(INDArray inputs,
INDArray inputMasks,
INDArray labelMasks,
OutputAdapter<T> outputAdapter)
This method uses provided OutputAdapter to return custom object built from INDArray
PLEASE NOTE: This method uses dedicated Workspace for output generation to avoid redundant allocations
|
INDArray |
output(INDArray input,
Layer.TrainingMode train)
Perform inference on the provided input/features - i.e., perform forward pass using the provided input/features
and return the output of the final layer.
|
protected INDArray |
outputOfLayerDetached(boolean train,
FwdPassType fwdPassType,
int layerIndex,
INDArray input,
INDArray featureMask,
INDArray labelsMask,
org.nd4j.linalg.api.memory.MemoryWorkspace outputWorkspace)
Provide the output of the specified layer, detached from any workspace.
|
INDArray |
params()
Returns a 1 x m vector where the vector is composed of a flattened vector of all of the parameters in the network.
See getParam(String) and paramTable() for a more useful/interpretable representation of the parameters.Note that the parameter vector is not a copy, and changes to the returned INDArray will impact the network parameters. |
INDArray |
params(boolean backwardOnly)
Returns a 1 x m vector where the vector is composed of a flattened vector of all of the parameters (weights and
biases etc) for all parameters in the network.
|
Map<String,INDArray> |
paramTable()
Return a map of all parameters in the network.
|
Map<String,INDArray> |
paramTable(boolean backpropParamsOnly)
Returns a map of all parameters in the network as per
paramTable() .Optionally (with backpropParamsOnly=true) only the 'backprop' parameters are returned - that is, any parameters involved only in unsupervised layerwise pretraining not standard inference/backprop are excluded from the returned list. |
List<String> |
predict(DataSet dataSet)
As per
predict(INDArray) but the returned values are looked up from the list of label names
in the provided DataSet |
int[] |
predict(INDArray d)
Usable only for classification networks in conjunction with OutputLayer.
|
void |
pretrain(DataSetIterator iter)
Perform layerwise pretraining for one epoch - see
pretrain(DataSetIterator, int) |
void |
pretrain(DataSetIterator iter,
int numEpochs)
Perform layerwise unsupervised training on all pre-trainable layers in the network (VAEs, Autoencoders, etc), for the specified
number of epochs each.
|
void |
pretrainLayer(int layerIdx,
DataSetIterator iter)
Fit for one epoch - see
pretrainLayer(int, DataSetIterator, int) |
void |
pretrainLayer(int layerIdx,
DataSetIterator iter,
int numEpochs)
Perform layerwise unsupervised training on a single pre-trainable layer in the network (VAEs, Autoencoders, etc)
for the specified number of epochs
If the specified layer index (0 to numLayers - 1) is not a pretrainable layer, this is a no-op. |
void |
pretrainLayer(int layerIdx,
INDArray features)
Perform layerwise unsupervised training on a single pre-trainable layer in the network (VAEs, Autoencoders, etc)
If the specified layer index (0 to numLayers - 1) is not a pretrainable layer, this is a no-op. |
List<INDArray> |
rnnActivateUsingStoredState(INDArray input,
boolean training,
boolean storeLastForTBPTT)
Similar to rnnTimeStep and feedForward() methods.
|
void |
rnnClearPreviousState()
Clear the previous state of the RNN layers (if any).
|
Map<String,INDArray> |
rnnGetPreviousState(int layer)
Get the state of the RNN layer, as used in rnnTimeStep().
|
void |
rnnSetPreviousState(int layer,
Map<String,INDArray> state)
Set the state of the RNN layer.
|
INDArray |
rnnTimeStep(INDArray input)
If this MultiLayerNetwork contains one or more RNN layers: conduct forward pass (prediction)
but using previous stored state for any RNN layers.
|
INDArray |
rnnTimeStep(INDArray input,
org.nd4j.linalg.api.memory.MemoryWorkspace outputWorkspace)
See
rnnTimeStep(INDArray) for detailsIf no memory workspace is provided, the output will be detached (not in any workspace). If a memory workspace is provided, the output activation array (i.e., the INDArray returned by this method) will be placed in the specified workspace. |
void |
save(File f)
Save the MultiLayerNetwork to a file.
|
void |
save(File f,
boolean saveUpdater)
Save the MultiLayerNetwork to a file.
|
double |
score()
Score of the model (relative to the objective function) - previously calculated on the last minibatch
|
double |
score(DataSet data)
Sets the input and labels and calculates the score (value of the output layer loss function plus l1/l2 if applicable)
for the prediction with respect to the true labels
This is equivalent to score(DataSet, boolean) with training==false. |
double |
score(DataSet data,
boolean training)
Sets the input and labels and calculates the score (value of the output layer loss function plus l1/l2 if applicable)
for the prediction with respect to the true labels
|
INDArray |
scoreExamples(DataSet data,
boolean addRegularizationTerms)
Calculate the score for each example in a DataSet individually.
|
INDArray |
scoreExamples(DataSetIterator iter,
boolean addRegularizationTerms)
As per
scoreExamples(DataSet, boolean) - the outputs (example scores) for all DataSets in the iterator are concatenated |
void |
setBackpropGradientsViewArray(INDArray gradients)
Set the gradients array as a view of the full (backprop) network parameters
NOTE: this is intended to be used internally in MultiLayerNetwork and ComputationGraph, not by users.
|
void |
setCacheMode(CacheMode mode)
This method sets specified CacheMode for all layers within network
|
void |
setConf(NeuralNetConfiguration conf)
Setter for the configuration
|
void |
setEpochCount(int epochCount)
Set the current epoch count (number of epochs passed ) for the layer/network
|
void |
setGradientsAccumulator(GradientsAccumulator accumulator)
This method allows you to specificy GradientsAccumulator instance to be used with this model
PLEASE NOTE: Do not use this method unless you understand how to use GradientsAccumulator & updates sharing. PLEASE NOTE: Do not use this method on standalone model |
void |
setIndex(int index)
Set the layer index.
|
void |
setInput(INDArray input)
Set the input array for the network
|
void |
setInput(INDArray input,
LayerWorkspaceMgr mgr)
Set the layer input.
|
void |
setInputMiniBatchSize(int size)
Set current/last input mini-batch size.
Used for score and gradient calculations. |
void |
setIterationCount(int iterationCount)
Set the current iteration count (number of parameter updates) for the layer/network
|
void |
setLabels(INDArray labels) |
void |
setLastEtlTime(long time)
Set the last ETL time in milliseconds, for informational/reporting purposes.
|
void |
setLayerMaskArrays(INDArray featuresMaskArray,
INDArray labelsMaskArray)
Set the mask arrays for features and labels.
|
void |
setLayers(Layer[] layers) |
void |
setLayerWiseConfigurations(MultiLayerConfiguration layerWiseConfigurations)
This method is intended for internal/developer use only.
|
void |
setLearningRate(double newLr)
Set the learning rate for all layers in the network to the specified value.
|
void |
setLearningRate(int layerNumber,
double newLr)
Set the learning rate for a single layer in the network to the specified value.
|
void |
setLearningRate(int layerNumber,
ISchedule newLr)
Set the learning rate schedule for a single layer in the network to the specified value.
Note also that setLearningRate(ISchedule) should also be used in preference, when all layers need
to be set to a new LR schedule.This schedule will replace any/all existing schedules, and also any fixed learning rate values. Note also that the iteration/epoch counts will not be reset. |
void |
setLearningRate(ISchedule newLr)
Set the learning rate schedule for all layers in the network to the specified schedule.
|
void |
setListeners(Collection<TrainingListener> listeners)
Set the trainingListeners for the ComputationGraph (and all layers in the network)
|
void |
setListeners(TrainingListener... listeners)
Set the trainingListeners for the ComputationGraph (and all layers in the network)
|
void |
setMask(INDArray mask) |
void |
setMaskArray(INDArray maskArray)
Set the mask array.
|
void |
setParam(String key,
INDArray val)
Set the values of a single parameter.
|
void |
setParameters(INDArray params)
|
void |
setParams(INDArray params)
Set the parameters for this model.
|
void |
setParamsViewArray(INDArray params)
Set the initial parameters array as a view of the full (backprop) network parameters
NOTE: this is intended to be used internally in MultiLayerNetwork and ComputationGraph, not by users.
|
void |
setParamTable(Map<String,INDArray> paramTable)
Set the parameters of the netowrk.
|
void |
setScore(double score)
Intended for developer/internal use
|
void |
setUpdater(Updater updater)
Set the updater for the MultiLayerNetwork
|
String |
summary()
String detailing the architecture of the multilayernetwork.
|
String |
summary(InputType inputType)
String detailing the architecture of the multilayernetwork.
|
protected void |
synchronizeIterEpochCounts() |
ComputationGraph |
toComputationGraph()
Convert this MultiLayerNetwork to a ComputationGraph
|
Layer.Type |
type()
Returns the layer type
|
void |
update(Gradient gradient)
Update layer weights and biases with gradient change
|
void |
update(INDArray gradient,
String paramType)
Perform one update applying the gradient
|
protected void |
update(Task task) |
boolean |
updaterDivideByMinibatch(String paramName)
Intended for internal use
|
void |
updateRnnStateWithTBPTTState()
Intended for internal/developer use
|
INDArray |
updaterState()
This method returns updater state (if applicable), null otherwise
|
protected void |
validateArrayWorkspaces(LayerWorkspaceMgr mgr,
INDArray array,
ArrayType arrayType,
int layerIdx,
boolean isPreprocessor,
String op) |
protected Layer[] layers
protected LinkedHashMap<String,Layer> layerMap
protected INDArray input
protected INDArray labels
protected boolean initCalled
protected Collection<TrainingListener> trainingListeners
protected NeuralNetConfiguration defaultConfiguration
protected MultiLayerConfiguration layerWiseConfigurations
protected Gradient gradient
protected double score
protected boolean initDone
protected INDArray flattenedParams
protected transient INDArray flattenedGradients
protected boolean clearTbpttState
protected transient ThreadLocal<Long> lastEtlTime
protected INDArray mask
protected int layerIndex
protected transient Solver solver
protected static final String WS_LAYER_WORKING_MEM
protected static final String WS_ALL_LAYERS_ACT
protected static final String WS_LAYER_ACT_1
protected static final String WS_LAYER_ACT_2
protected static final String WS_OUTPUT_MEM
protected static final String WS_RNN_LOOP_WORKING_MEM
protected org.nd4j.linalg.api.memory.conf.WorkspaceConfiguration WS_LAYER_WORKING_MEM_CONFIG
protected static final org.nd4j.linalg.api.memory.conf.WorkspaceConfiguration WS_ALL_LAYERS_ACT_CONFIG
protected org.nd4j.linalg.api.memory.conf.WorkspaceConfiguration WS_LAYER_ACT_X_CONFIG
protected static final org.nd4j.linalg.api.memory.conf.WorkspaceConfiguration WS_RNN_LOOP_WORKING_MEM_CONFIG
public MultiLayerNetwork(MultiLayerConfiguration conf)
public MultiLayerNetwork(String conf, INDArray params)
conf
- the configuration jsonparams
- the parameters for the networkpublic MultiLayerNetwork(MultiLayerConfiguration conf, INDArray params)
conf
- the configurationparams
- the parametersprotected static org.nd4j.linalg.api.memory.conf.WorkspaceConfiguration getLayerWorkingMemWSConfig(int numWorkingMemCycles)
protected static org.nd4j.linalg.api.memory.conf.WorkspaceConfiguration getLayerActivationWSConfig(int numLayers)
public void setCacheMode(CacheMode mode)
setCacheMode
in interface Layer
mode
- public void setLastEtlTime(long time)
time
- ETL timepublic long getLastEtlTime()
protected void intializeConfigurations()
public void pretrain(DataSetIterator iter)
pretrain(DataSetIterator, int)
public void pretrain(DataSetIterator iter, int numEpochs)
pretrainLayer(int, DataSetIterator)
iter
- Training datapublic void pretrainLayer(int layerIdx, DataSetIterator iter)
pretrainLayer(int, DataSetIterator, int)
public void pretrainLayer(int layerIdx, DataSetIterator iter, int numEpochs)
layerIdx
- Index of the layer to train (0 to numLayers-1)iter
- Training datanumEpochs
- Number of epochs to fit the specified layer forpublic void pretrainLayer(int layerIdx, INDArray features)
layerIdx
- Index of the layer to train (0 to numLayers-1)features
- Training data arraypublic int batchSize()
Model
public NeuralNetConfiguration conf()
Model
public void setConf(NeuralNetConfiguration conf)
Model
public INDArray input()
Model
public ConvexOptimizer getOptimizer()
Model
getOptimizer
in interface Model
getOptimizer
in interface NeuralNetwork
public INDArray getParam(String param)
getParam
in interface Model
param
- the key of the parameterparamTable() method, for a map of all parameters
public Map<String,INDArray> paramTable()
getParam(String)
.
As per getParam(String)
the returned arrays are views - modifications to these will impact
the underlying network parametersparamTable
in interface Model
public Map<String,INDArray> paramTable(boolean backpropParamsOnly)
paramTable()
.paramTable
in interface Model
paramTable
in interface Trainable
backpropParamsOnly
- If true, return backprop params only. If false: return all paramspublic boolean updaterDivideByMinibatch(String paramName)
updaterDivideByMinibatch
in interface Trainable
paramName
- Name of the parameterpublic void setParamTable(Map<String,INDArray> paramTable)
getParam(String)
and paramTable()
. Note that the values of the parameters used as an argument to this method are copied -
i.e., it is safe to later modify/reuse the values in the provided paramTable without this impacting the network.setParamTable
in interface Model
paramTable
- Parameters to setpublic void setParam(String key, INDArray val)
setParamTable(Map)
and getParam(String)
for more
details.public MultiLayerConfiguration getLayerWiseConfigurations()
public void setLayerWiseConfigurations(MultiLayerConfiguration layerWiseConfigurations)
public void init()
init(null, false)
.init
in interface Model
init
in interface NeuralNetwork
init(INDArray, boolean)
public void init(INDArray parameters, boolean cloneParametersArray)
parameters
- Network parameter. May be null. If null: randomly initialize.cloneParametersArray
- Whether the parameter array (if any) should be cloned, or used directlypublic void setGradientsAccumulator(GradientsAccumulator accumulator)
accumulator
- Gradient accumulator to use for the networkpublic boolean isInitCalled()
public void initGradientsView()
protected INDArray activationFromPrevLayer(int curr, INDArray input, boolean training, LayerWorkspaceMgr mgr)
public INDArray activateSelectedLayers(int from, int to, INDArray input)
from
- first layer to be activated, inclusiveto
- last layer to be activated, inclusivepublic List<INDArray> feedForward(INDArray input, boolean train)
train
- Training: if true, perform forward pass/inference at training time. Usually, inference is performed
with train = false. This impacts whether dropout etc is applied or not.public List<INDArray> feedForward(boolean train)
feedForward(INDArray, boolean)
but using the inputs that have previously been set using setInput(INDArray)
public List<INDArray> feedForward(boolean train, boolean clearInputs)
train
- training mode (true) or test mode (false)clearInputs
- If false: don't clear the layer inputspublic List<INDArray> feedForwardToLayer(int layerNum, INDArray input)
layerNum
- Index of the last layer to calculate activations for. Layers are zero-indexed.
feedForwardToLayer(i,input) will return the activations for layers 0..i (inclusive)input
- Input to the networkpublic List<INDArray> feedForwardToLayer(int layerNum, INDArray input, boolean train)
layerNum
- Index of the last layer to calculate activations for. Layers are zero-indexed.
feedForwardToLayer(i,input) will return the activations for layers 0..i (inclusive)input
- Input to the networktrain
- true for training, false for test (i.e., false if using network after training)public List<INDArray> feedForwardToLayer(int layerNum, boolean train)
layerNum
- Index of the last layer to calculate activations for. Layers are zero-indexed.
feedForwardToLayer(i,input) will return the activations for layers 0..i (inclusive)train
- true for training, false for test (i.e., false if using network after training)protected void validateArrayWorkspaces(LayerWorkspaceMgr mgr, INDArray array, ArrayType arrayType, int layerIdx, boolean isPreprocessor, String op)
protected List<INDArray> ffToLayerActivationsDetached(boolean train, @NonNull FwdPassType fwdPassType, boolean storeLastForTBPTT, int layerIndex, @NonNull INDArray input, INDArray fMask, INDArray lMask, boolean clearInputs)
train
- Training mode (true) or test/inference mode (false)fwdPassType
- Type of forward pass to perform (STANDARD or RNN_ACTIVATE_WITH_STORED_STATE only)storeLastForTBPTT
- ONLY used if fwdPassType == FwdPassType.RNN_ACTIVATE_WITH_STORED_STATElayerIndex
- Index (inclusive) to stop forward pass at. For all layers, use numLayers-1input
- Input to the networkfMask
- Feature mask array. May be null.lMask
- Label mask array. May be null.clearInputs
- Whether the layer inputs should be clearedprotected List<INDArray> ffToLayerActivationsInWs(int layerIndex, @NonNull FwdPassType fwdPassType, boolean storeLastForTBPTT, @NonNull INDArray input, INDArray fMask, INDArray lMask)
layerIndex
- Index (inclusive) to stop forward pass at. For all layers, use numLayers-1fwdPassType
- Type of forward pass to perform (STANDARD or RNN_ACTIVATE_WITH_STORED_STATE only)storeLastForTBPTT
- ONLY used if fwdPassType == FwdPassType.RNN_ACTIVATE_WITH_STORED_STATEinput
- Input to networkfMask
- Feature mask array. May be nulllMask
- Label mask aray. May be null.protected INDArray outputOfLayerDetached(boolean train, @NonNull FwdPassType fwdPassType, int layerIndex, @NonNull INDArray input, INDArray featureMask, INDArray labelsMask, org.nd4j.linalg.api.memory.MemoryWorkspace outputWorkspace)
ffToLayerActivationsDetached(boolean, FwdPassType, boolean, int, INDArray, INDArray, INDArray, boolean)
and ffToLayerActivationsInWs(int, FwdPassType, boolean, INDArray, INDArray, INDArray)
.train
- Training mode (true) or test/inference mode (false)fwdPassType
- Type of forward pass to perform (STANDARD, RNN_TIMESTEP or RNN_ACTIVATE_WITH_STORED_STATE)layerIndex
- Index (inclusive) to stop forward pass at. For all layers, use numLayers-1input
- Input to the networkfeatureMask
- Input/feature mask array. May be null.labelsMask
- Labels mask array. May be nulloutputWorkspace
- Optional - if provided, outputs should be placed in this workspace. NOTE: this workspace
must be openpublic List<INDArray> feedForward()
feedForward(boolean)
with train=falsepublic List<INDArray> feedForward(INDArray input)
feedForward(INDArray, boolean)
with train = falsepublic List<INDArray> feedForward(INDArray input, INDArray featuresMask, INDArray labelsMask)
feedForward(INDArray, boolean)
with train = falsepublic Gradient gradient()
Model
Model.computeGradientAndScore(LayerWorkspaceMgr)
} .public Pair<Gradient,Double> gradientAndScore()
Model
gradientAndScore
in interface Model
public MultiLayerNetwork clone()
protected boolean hasAFrozenLayer()
public INDArray params(boolean backwardOnly)
getParam(String)
and paramTable()
for a more useful/interpretable
representation of the parameters.backwardOnly
- Return a copy of the parameters excluding any parameters used only for unsupervised layers'
unsupervised training (such as decoder parameters in an autoencoder layerpublic INDArray params()
getParam(String)
and paramTable()
for a more useful/interpretable representation of the parameters.public void setParams(INDArray params)
setParamTable(Map)
and setParam(String, INDArray)
public void setParamsViewArray(INDArray params)
Model
setParamsViewArray
in interface Model
params
- a 1 x nParams row vector that is a view of the larger (MLN/CG) parameters arraypublic INDArray getGradientsViewArray()
getGradientsViewArray
in interface Model
getGradientsViewArray
in interface Trainable
public void setBackpropGradientsViewArray(INDArray gradients)
Model
setBackpropGradientsViewArray
in interface Model
gradients
- a 1 x nParams row vector that is a view of the larger (MLN/CG) gradients arraypublic TrainingConfig getConfig()
public long numParams()
public long numParams(boolean backwards)
public double f1Score(DataSet data)
f1Score
in interface Classifier
data
- the data to scorepublic void fit(@NonNull DataSetIterator iterator, int numEpochs)
fit(DataSetIterator)
numEpochs times in a loopiterator
- Training data (DataSetIterator). Iterator must support resettingnumEpochs
- Number of training epochs, >= 1public void fit(DataSetIterator iterator)
pretrain(DataSetIterator)
fit
in interface Classifier
fit
in interface NeuralNetwork
iterator
- Training data (DataSetIterator)public Pair<Gradient,INDArray> calculateGradients(@NonNull INDArray features, @NonNull INDArray label, INDArray fMask, INDArray labelMask)
features
- Features for gradient calculationlabel
- Labels for gradientfMask
- Features mask array (may be null)labelMask
- Label mask array (may be null)protected Pair<Gradient,INDArray> calcBackpropGradients(INDArray epsilon, boolean withOutputLayer, boolean tbptt, boolean returnInputActGrad)
epsilon
- Errors (technically errors .* activations). Not used if withOutputLayer = truewithOutputLayer
- if true: assume last layer is output layer, and calculate errors based on labels. In this
case, the epsilon input is not used (may/should be null).
If false: calculate backprop gradientsreturnInputActGrad
- If true: terun the input activation gradients (detached). False: don't returnprotected void doTruncatedBPTT(INDArray input, INDArray labels, INDArray featuresMaskArray, INDArray labelsMaskArray, LayerWorkspaceMgr workspaceMgr)
public void updateRnnStateWithTBPTTState()
public Collection<TrainingListener> getListeners()
TrainingListener
s set for this network, if anygetListeners
in interface Layer
@Deprecated public Collection<TrainingListener> getTrainingListeners()
getListeners()
public void setListeners(Collection<TrainingListener> listeners)
Model
setListeners
in interface Layer
setListeners
in interface Model
public void addListeners(TrainingListener... listeners)
addListeners
in interface Model
listeners
- public void setListeners(TrainingListener... listeners)
Model
setListeners
in interface Layer
setListeners
in interface Model
public int[] predict(INDArray d)
output(INDArray)
or similar.predict
in interface Classifier
d
- The input features to perform inference onpublic List<String> predict(DataSet dataSet)
predict(INDArray)
but the returned values are looked up from the list of label names
in the provided DataSetpredict
in interface Classifier
dataSet
- the examples to classifypublic void fit(INDArray data, INDArray labels)
fit
in interface Classifier
data
- the examples to classify (one example in each row)labels
- the example labels(a binary outcome matrix)public void fit(INDArray features, INDArray labels, INDArray featuresMask, INDArray labelsMask)
features
- the examples to classify (one example in each row)labels
- the example labels(a binary outcome matrix)featuresMask
- The mask array for the features (used for variable length time series, etc). May be null.labelsMask
- The mask array for the labels (used for variable length time series, etc). May be null.public void fit(INDArray data, LayerWorkspaceMgr workspaceMgr)
Model
public void fit(DataSet data)
fit
in interface Classifier
fit
in interface NeuralNetwork
data
- the data to train onpublic void fit(INDArray examples, int[] labels)
fit
in interface Classifier
examples
- the examples to classify (one example in each row)labels
- the labels for each example (the number of labels must matchpublic INDArray output(INDArray input, Layer.TrainingMode train)
input
- Input to the networktrain
- whether the output is test or train. This mainly affect hyper parameters such as dropout and
batch normalization, which have different behaviour for test vs. trainpublic INDArray output(INDArray input, boolean train)
input
- Input to the networktrain
- whether the output is test or train. This mainly affect hyper parameters such as dropout and
batch normalization, which have different behaviour for test vs. trainpublic INDArray output(INDArray input, boolean train, INDArray featuresMask, INDArray labelsMask)
public INDArray output(INDArray input, boolean train, org.nd4j.linalg.api.memory.MemoryWorkspace outputWorkspace)
input
- Input to the networktrain
- True for train, false otherwiseoutputWorkspace
- May be null. If not null: the workspace MUST be opened before calling this method.public INDArray output(INDArray input, boolean train, INDArray featuresMask, INDArray labelsMask, org.nd4j.linalg.api.memory.MemoryWorkspace outputWorkspace)
input
- Input to the networktrain
- True for train, false otherwiseoutputWorkspace
- May be null. If not null: the workspace MUST be opened before calling this method.public <T> T output(@NonNull INDArray inputs, INDArray inputMasks, INDArray labelMasks, @NonNull OutputAdapter<T> outputAdapter)
T
- T extends Objectinputs
- Input arrays to the netwonkinputMasks
- Optional input mask arrays (may be null)labelMasks
- Optional label mask arrays (may be nulloutputAdapter
- OutputAdapterpublic INDArray output(INDArray input)
output(INDArray, boolean)
with train=false - i.e.,
this method is used for inference.input
- Input to the networkpublic INDArray output(DataSetIterator iterator, boolean train)
output(INDArray)
iterator
- Data to pass through the networkpublic INDArray output(DataSetIterator iterator)
output(DataSetIterator, boolean)
with train=falsepublic double f1Score(INDArray input, INDArray labels)
f1Score
in interface Classifier
input
- the input to perform inference withlabels
- the true labels@Deprecated public int numLabels()
Classifier
numLabels
in interface Classifier
public double score(DataSet data)
score(DataSet, boolean)
with training==false.data
- the data to scorescore(DataSet, boolean)
public double score(DataSet data, boolean training)
data
- data to calculate score fortraining
- If true: score during training. If false: score at test time. This can affect the application of
certain features, such as dropout and dropconnect (which are applied at training time only)public INDArray scoreExamples(DataSetIterator iter, boolean addRegularizationTerms)
scoreExamples(DataSet, boolean)
- the outputs (example scores) for all DataSets in the iterator are concatenatedpublic INDArray scoreExamples(DataSet data, boolean addRegularizationTerms)
score(DataSet)
and score(DataSet, boolean)
this method does not average/sum over examples. This method allows for examples to be scored individually (at test time only), which
may be useful for example for autoencoder architectures and the like.data
- The data to scoreaddRegularizationTerms
- If true: add l1/l2 regularization terms (if any) to the score. If false: don't add regularization termspublic void fit()
Model
public void update(INDArray gradient, String paramType)
Model
public double score()
public void setScore(double score)
public void computeGradientAndScore(LayerWorkspaceMgr layerWorkspaceMgr)
Model
computeGradientAndScore
in interface Model
public void computeGradientAndScore()
public void clear()
public void applyConstraints(int iteration, int epoch)
Model
applyConstraints
in interface Model
public void setInput(INDArray input)
input
- Input array to setpublic void setInput(INDArray input, LayerWorkspaceMgr mgr)
Layer
public Layer getOutputLayer()
public void setParameters(INDArray params)
public NeuralNetConfiguration getDefaultConfiguration()
public INDArray getLabels()
public INDArray getInput()
public void setLabels(INDArray labels)
labels
- Labels to setpublic int getnLayers()
public Layer[] getLayers()
public Layer getLayer(int i)
public void setLayers(Layer[] layers)
public INDArray getMask()
public void setMask(INDArray mask)
public INDArray getMaskArray()
getMaskArray
in interface Layer
public boolean isPretrainLayer()
Layer
isPretrainLayer
in interface Layer
public void clearNoiseWeightParams()
clearNoiseWeightParams
in interface Layer
public void allowInputModification(boolean allow)
Layer
allowInputModification
in interface Layer
allow
- If true: the input array is safe to modify. If false: the input array should be copied before it
is modified (i.e., in-place modifications are un-safe)public Pair<INDArray,MaskState> feedForwardMaskArray(INDArray maskArray, MaskState currentMaskState, int minibatchSize)
Layer
feedForwardMaskArray
in interface Layer
maskArray
- Mask array to setcurrentMaskState
- Current state of the mask - see MaskState
minibatchSize
- Current minibatch size. Needs to be known as it cannot always be inferred from the activations
array due to reshaping (such as a DenseLayer within a recurrent neural network)public LayerHelper getHelper()
public Layer.Type type()
Layer
public INDArray activate(Layer.TrainingMode training)
output(INDArray)
using the input set via setInput(INDArray)
public INDArray activate(INDArray input, Layer.TrainingMode training)
#output(INDArray, TrainingMode)
public Pair<Gradient,INDArray> backpropGradient(INDArray epsilon, LayerWorkspaceMgr workspaceMgr)
Layer
backpropGradient
in interface Layer
epsilon
- w^(L+1)*delta^(L+1). Or, equiv: dC/da, i.e., (dC/dz)*(dz/da) = dC/da, where C
is cost function a=sigma(z) is activation.workspaceMgr
- Workspace managerArrayType.ACTIVATION_GRAD
workspace via the workspace managerpublic void setIndex(int index)
Layer
public int getIndex()
Layer
public int getIterationCount()
getIterationCount
in interface Layer
public int getEpochCount()
getEpochCount
in interface Layer
public void setIterationCount(int iterationCount)
Layer
setIterationCount
in interface Layer
public void setEpochCount(int epochCount)
Layer
setEpochCount
in interface Layer
public double calcRegularizationScore(boolean backpropParamsOnly)
Layer
calcRegularizationScore
in interface Layer
backpropParamsOnly
- If true: calculate regularization score based on backprop params only. If false: calculate
based on all params (including pretrain params, if any)public void update(Gradient gradient)
Model
public INDArray activate(boolean training, LayerWorkspaceMgr mgr)
Layer
activate
in interface Layer
training
- training or test modemgr
- Workspace managerArrayType.ACTIVATIONS
workspace via the workspace managerpublic INDArray activate(INDArray input, boolean training, LayerWorkspaceMgr mgr)
Layer
activate
in interface Layer
input
- the input to usetraining
- train or test modemgr
- Workspace manager.ArrayType.ACTIVATIONS
workspace via the workspace managerpublic void setInputMiniBatchSize(int size)
Layer
setInputMiniBatchSize
in interface Layer
public int getInputMiniBatchSize()
Layer
getInputMiniBatchSize
in interface Layer
Layer.setInputMiniBatchSize(int)
public void setMaskArray(INDArray maskArray)
Layer
Layer.feedForwardMaskArray(INDArray, MaskState, int)
should be used in
preference to this.setMaskArray
in interface Layer
maskArray
- Mask array to setpublic INDArray rnnTimeStep(INDArray input)
input
- Input to network. May be for one or multiple time steps. For single time step:
input has shape [miniBatchSize,inputSize] or [miniBatchSize,inputSize,1]. miniBatchSize=1 for single example.For outputting the activations in the specified workspace
public INDArray rnnTimeStep(INDArray input, org.nd4j.linalg.api.memory.MemoryWorkspace outputWorkspace)
rnnTimeStep(INDArray)
for detailsinput
- Input activationsoutputWorkspace
- Output workspace. May be nullpublic Map<String,INDArray> rnnGetPreviousState(int layer)
layer
- Number/index of the layer.public void rnnSetPreviousState(int layer, Map<String,INDArray> state)
layer
- The number/index of the layer.state
- The state to set the specified layer topublic void rnnClearPreviousState()
public List<INDArray> rnnActivateUsingStoredState(INDArray input, boolean training, boolean storeLastForTBPTT)
input
- Input to networktraining
- Whether training or notstoreLastForTBPTT
- set to true if used as part of truncated BPTT trainingpublic Updater getUpdater()
public Updater getUpdater(boolean initializeIfReq)
public void setUpdater(Updater updater)
public void setLayerMaskArrays(INDArray featuresMaskArray, INDArray labelsMaskArray)
feedForward(INDArray, INDArray, INDArray)
and output(INDArray, boolean, INDArray, INDArray)
handle setting of masking internally.featuresMaskArray
- Mask array for features (input)labelsMaskArray
- Mask array for labels (output)clearLayerMaskArrays()
public void clearLayerMaskArrays()
setLayerMaskArrays(INDArray, INDArray)
for details on mask arrays.public <T extends Evaluation> T evaluate(DataSetIterator iterator)
iterator
- Iterator to evaluate onpublic <T extends RegressionEvaluation> T evaluateRegression(DataSetIterator iterator)
iterator
- Data to evaluate on@Deprecated public <T extends ROC> T evaluateROC(DataSetIterator iterator)
evaluateROC(DataSetIterator, int)
to enforce selection of appropriate ROC/threshold configurationpublic <T extends ROC> T evaluateROC(DataSetIterator iterator, int rocThresholdSteps)
ROC
classiterator
- Data to evaluate onrocThresholdSteps
- Number of threshold steps to use with ROC
- see that class for details.@Deprecated public <T extends ROCMultiClass> T evaluateROCMultiClass(DataSetIterator iterator)
evaluateROCMultiClass(DataSetIterator, int)
to enforce selection of appropriate ROC/threshold configurationpublic <T extends ROCMultiClass> T evaluateROCMultiClass(DataSetIterator iterator, int rocThresholdSteps)
ROCMultiClass
classiterator
- Data to evaluate onrocThresholdSteps
- Number of threshold steps to use with ROCMultiClass
public <T extends IEvaluation> T[] doEvaluation(DataSetIterator iterator, T... evaluations)
doEvaluation
in interface NeuralNetwork
iterator
- data to evaluate onpublic <T extends IEvaluation> T[] doEvaluationHelper(DataSetIterator iterator, T... evaluations)
public Evaluation evaluate(DataSetIterator iterator, List<String> labelsList)
iterator
- Data to undertake evaluation onpublic INDArray updaterState()
NeuralNetwork
updaterState
in interface NeuralNetwork
public void fit(MultiDataSet dataSet)
NeuralNetwork
fit
in interface NeuralNetwork
public void fit(@NonNull MultiDataSetIterator iterator, int numEpochs)
fit(MultiDataSetIterator)
numEpochs times in a loopiterator
- Training data (DataSetIterator). Iterator must support resettingnumEpochs
- Number of training epochs, >= 1public void fit(MultiDataSetIterator iterator)
fit
in interface NeuralNetwork
iterator
- Training data (DataSetIterator). Iterator must support resettingpublic <T extends IEvaluation> T[] doEvaluation(MultiDataSetIterator iterator, T[] evaluations)
NeuralNetwork
doEvaluation
in interface NeuralNetwork
public Evaluation evaluate(DataSetIterator iterator, List<String> labelsList, int topN)
iterator
- Iterator (data) to evaluate onlabelsList
- List of labels. May be null.topN
- N value for top N accuracy evaluationprotected void update(Task task)
public String summary()
memoryInfo(int, InputType)
public String summary(InputType inputType)
memoryInfo(int, InputType)
public String memoryInfo(int minibatch, InputType inputType)
minibatch
- Minibatch size to estimate memory forinputType
- Input type to the networkpublic void clearLayersStates()
public void incrementEpochCount()
MultiLayerConfiguration
by 1).
Note that this is done automatically when using iterator-based fitting methods, such as
fit(DataSetIterator)
. However, when using non-iterator fit methods (DataSet, INDArray/INDArray etc),
the network has no way to know when one epoch ends and another starts. In such situations, this method
can be used to increment the epoch counter.MultiLayerConfiguration.getLayerwiseConfiguration().getEpochCount()
protected void synchronizeIterEpochCounts()
public void save(File f) throws IOException
load(File, boolean)
.
Note that this saves the updater (i.e., the state array for momentum/Adam/rmsprop etc), which is desirable
if further training will be undertaken.f
- File to save the network toIOException
ModelSerializer for more details (and saving/loading via streams)
,
save(File, boolean)
public void save(File f, boolean saveUpdater) throws IOException
load(File, boolean)
.f
- File to save the network tosaveUpdater
- If true: save the updater (i.e., the state array for momentum/Adam/rmsprop etc), which should
usually be saved if further training is requiredIOException
ModelSerializer for more details (and saving/loading via streams)
,
save(File, boolean)
public static MultiLayerNetwork load(File f, boolean loadUpdater) throws IOException
save(File)
or ModelSerializer
f
- File to load the network fromloadUpdater
- If true: load the updater if it is available (i.e., the state array for momentum/Adam/rmsprop
etc) - use false if no further training is required, or true if further training
will be undertakenIOException
ModelSerializer for more details (and saving/loading via streams)
public ComputationGraph toComputationGraph()
public MultiLayerNetwork convertDataType(@NonNull org.nd4j.linalg.api.buffer.DataType dataType)
dataType
- Datatype to convert the network topublic void setLearningRate(double newLr)
newLr
- New learning rate for all layerssetLearningRate(ISchedule)
,
setLearningRate(int, double)
public void setLearningRate(ISchedule newLr)
MultiLayerConfiguration#setIterationCount(int)
and MultiLayerConfiguration.setEpochCount(int)
if this is requirednewLr
- New learning rate schedule for all layerssetLearningRate(ISchedule)
,
setLearningRate(int, double)
public void setLearningRate(int layerNumber, double newLr)
setLearningRate(double)
should also be used in preference, when all layers need to be set to a new LRlayerNumber
- Number of the layer to set the LR fornewLr
- New learning rate for a single layersetLearningRate(ISchedule)
,
setLearningRate(int, double)
public void setLearningRate(int layerNumber, ISchedule newLr)
setLearningRate(ISchedule)
should also be used in preference, when all layers need
to be set to a new LR schedule.MultiLayerConfiguration#setIterationCount(int)
and MultiLayerConfiguration.setEpochCount(int)
if this is requiredlayerNumber
- Number of the layer to set the LR schedule fornewLr
- New learning rate for a single layersetLearningRate(ISchedule)
,
setLearningRate(int, double)
public Double getLearningRate(int layerNumber)
layerNumber
- Layer number to get the learning rate forpublic int layerSize(int layer)
layer
- Index of the layer to get the size of. Must be in range 0 to nLayers-1 inclusivepublic int layerInputSize(int layer)
layer
- Index of the layer to get the size of. Must be in range 0 to nLayers-1 inclusivepublic boolean equals(Object obj)
The equals
method implements an equivalence relation
on non-null object references:
x
, x.equals(x)
should return
true
.
x
and y
, x.equals(y)
should return true
if and only if
y.equals(x)
returns true
.
x
, y
, and z
, if
x.equals(y)
returns true
and
y.equals(z)
returns true
, then
x.equals(z)
should return true
.
x
and y
, multiple invocations of
x.equals(y)
consistently return true
or consistently return false
, provided no
information used in equals
comparisons on the
objects is modified.
x
,
x.equals(null)
should return false
.
The equals
method for class Object
implements
the most discriminating possible equivalence relation on objects;
that is, for any non-null reference values x
and
y
, this method returns true
if and only
if x
and y
refer to the same object
(x == y
has the value true
).
Note that it is generally necessary to override the hashCode
method whenever this method is overridden, so as to maintain the
general contract for the hashCode
method, which states
that equal objects must have equal hash codes.
equals
in class Object
obj
- the reference object with which to compare.true
if this object is the same as the obj
argument; false
otherwise.Object.hashCode()
,
HashMap
Copyright © 2019. All rights reserved.