public abstract class AbstractLayer<LayerConfT extends Layer> extends Object implements Layer
Layer.TrainingMode, Layer.Type| Modifier and Type | Field and Description |
|---|---|
protected CacheMode |
cacheMode |
protected NeuralNetConfiguration |
conf |
protected boolean |
dropoutApplied |
protected org.nd4j.linalg.api.ndarray.INDArray |
dropoutMask |
protected int |
epochCount |
protected int |
index |
protected org.nd4j.linalg.api.ndarray.INDArray |
input |
protected int |
iterationCount |
protected org.nd4j.linalg.api.ndarray.INDArray |
maskArray |
protected MaskState |
maskState |
protected org.nd4j.linalg.api.ndarray.INDArray |
preOutput |
protected Collection<TrainingListener> |
trainingListeners |
| Constructor and Description |
|---|
AbstractLayer(NeuralNetConfiguration conf) |
AbstractLayer(NeuralNetConfiguration conf,
org.nd4j.linalg.api.ndarray.INDArray input) |
| Modifier and Type | Method and Description |
|---|---|
void |
accumulateScore(double accum)
Sets a rolling tally for the score.
|
org.nd4j.linalg.api.ndarray.INDArray |
activate(org.nd4j.linalg.api.ndarray.INDArray input,
boolean training,
LayerWorkspaceMgr workspaceMgr)
Perform forward pass and return the activations array with the specified input
|
void |
addListeners(TrainingListener... listeners)
This method ADDS additional TrainingListener to existing listeners
|
void |
applyConstraints(int iteration,
int epoch)
Apply any constraints to the model
|
protected void |
applyDropOutIfNecessary(boolean training,
LayerWorkspaceMgr workspaceMgr) |
protected void |
applyMask(org.nd4j.linalg.api.ndarray.INDArray to) |
void |
assertInputSet(boolean backprop) |
int |
batchSize()
The current inputs batch size
|
double |
calcL1(boolean backpropParamsOnly)
Calculate the l1 regularization term
0.0 if regularization is not used. |
double |
calcL2(boolean backpropParamsOnly)
Calculate the l2 regularization term
0.0 if regularization is not used. |
void |
clear()
Clear input
|
abstract Layer |
clone()
Clone the layer
|
void |
computeGradientAndScore(LayerWorkspaceMgr workspaceMgr)
Update the score
|
NeuralNetConfiguration |
conf()
The configuration for the neural network
|
org.nd4j.linalg.primitives.Pair<org.nd4j.linalg.api.ndarray.INDArray,MaskState> |
feedForwardMaskArray(org.nd4j.linalg.api.ndarray.INDArray maskArray,
MaskState currentMaskState,
int minibatchSize)
Feed forward the input mask array, setting in in the layer as appropriate.
|
void |
fit()
All models have a fit method
|
void |
fit(org.nd4j.linalg.api.ndarray.INDArray input,
LayerWorkspaceMgr workspaceMgr)
Fit the model to the given data
|
org.nd4j.linalg.api.ndarray.INDArray |
getGradientsViewArray() |
int |
getIndex()
Get the layer index.
|
org.nd4j.linalg.api.ndarray.INDArray |
getInput() |
int |
getInputMiniBatchSize()
Get current/last input mini-batch size, as set by setInputMiniBatchSize(int)
|
Collection<TrainingListener> |
getListeners()
Get the iteration listeners for this layer.
|
org.nd4j.linalg.api.ndarray.INDArray |
getMaskArray() |
ConvexOptimizer |
getOptimizer()
Returns this models optimizer
|
org.nd4j.linalg.api.ndarray.INDArray |
getParam(String param)
Get the parameter
|
Gradient |
gradient()
Get the gradient.
|
org.nd4j.linalg.primitives.Pair<Gradient,Double> |
gradientAndScore()
Get the gradient and score
|
void |
init()
Init the model
|
void |
initParams()
Initialize the parameters
|
org.nd4j.linalg.api.ndarray.INDArray |
input()
The input/feature matrix for the model
|
protected LayerConfT |
layerConf() |
protected String |
layerId() |
int |
numParams()
The number of parameters for the model
|
int |
numParams(boolean backwards)
the number of parameters for the model
|
org.nd4j.linalg.api.ndarray.INDArray |
params()
Returns the parameters of the neural network as a flattened row vector
|
Map<String,org.nd4j.linalg.api.ndarray.INDArray> |
paramTable()
The param table
|
Map<String,org.nd4j.linalg.api.ndarray.INDArray> |
paramTable(boolean backpropParamsOnly)
Table of parameters by key, for backprop
For many models (dense layers, etc) - all parameters are backprop parameters
|
double |
score()
The score for the model
|
void |
setBackpropGradientsViewArray(org.nd4j.linalg.api.ndarray.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 given CacheMode for current layer
|
void |
setConf(NeuralNetConfiguration conf)
Setter for the configuration
|
void |
setIndex(int index)
Set the layer index.
|
void |
setInput(org.nd4j.linalg.api.ndarray.INDArray input,
LayerWorkspaceMgr workspaceMgr)
Set the layer input.
|
void |
setInputMiniBatchSize(int size)
Set current/last input mini-batch size.
Used for score and gradient calculations. |
void |
setListeners(Collection<TrainingListener> listeners)
Set the iteration listeners for this layer.
|
void |
setListeners(TrainingListener... listeners)
Set the iteration listeners for this layer.
|
void |
setMaskArray(org.nd4j.linalg.api.ndarray.INDArray maskArray)
Set the mask array.
|
void |
setParam(String key,
org.nd4j.linalg.api.ndarray.INDArray val)
Set the parameter with a new ndarray
|
void |
setParams(org.nd4j.linalg.api.ndarray.INDArray params)
Set the parameters for this model.
|
protected void |
setParams(org.nd4j.linalg.api.ndarray.INDArray params,
char order) |
void |
setParamsViewArray(org.nd4j.linalg.api.ndarray.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,org.nd4j.linalg.api.ndarray.INDArray> paramTable)
Setter for the param table
|
Layer |
transpose()
Return a transposed copy of the weights/bias
(this means reverse the number of inputs and outputs on the weights)
|
Layer.Type |
type()
Returns the layer type
|
void |
update(Gradient gradient)
Update layer weights and biases with gradient change
|
void |
update(org.nd4j.linalg.api.ndarray.INDArray gradient,
String paramType)
Perform one update applying the gradient
|
void |
validateInput()
Validate the input
|
equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitactivate, backpropGradient, clearNoiseWeightParams, getEpochCount, getIterationCount, isPretrainLayer, setEpochCount, setIterationCountprotected org.nd4j.linalg.api.ndarray.INDArray input
protected org.nd4j.linalg.api.ndarray.INDArray preOutput
protected NeuralNetConfiguration conf
protected org.nd4j.linalg.api.ndarray.INDArray dropoutMask
protected boolean dropoutApplied
protected Collection<TrainingListener> trainingListeners
protected int index
protected org.nd4j.linalg.api.ndarray.INDArray maskArray
protected MaskState maskState
protected CacheMode cacheMode
protected int iterationCount
protected int epochCount
public AbstractLayer(NeuralNetConfiguration conf)
public AbstractLayer(NeuralNetConfiguration conf, org.nd4j.linalg.api.ndarray.INDArray input)
public void setCacheMode(CacheMode mode)
LayersetCacheMode in interface Layerprotected LayerConfT layerConf()
protected String layerId()
public org.nd4j.linalg.api.ndarray.INDArray getInput()
public void setInput(org.nd4j.linalg.api.ndarray.INDArray input,
LayerWorkspaceMgr workspaceMgr)
Layerpublic int getIndex()
Layerpublic void setIndex(int index)
Layerpublic Collection<TrainingListener> getListeners()
LayergetListeners in interface Layerpublic void setListeners(Collection<TrainingListener> listeners)
LayersetListeners in interface LayersetListeners in interface Modelpublic void addListeners(TrainingListener... listeners)
addListeners in interface Modellisteners - public void setListeners(TrainingListener... listeners)
LayersetListeners in interface LayersetListeners in interface Modelpublic void computeGradientAndScore(LayerWorkspaceMgr workspaceMgr)
ModelcomputeGradientAndScore in interface Modelpublic void update(Gradient gradient)
Modelpublic void update(org.nd4j.linalg.api.ndarray.INDArray gradient,
String paramType)
Modelpublic ConvexOptimizer getOptimizer()
ModelgetOptimizer in interface Modelpublic void setConf(NeuralNetConfiguration conf)
Modelpublic org.nd4j.linalg.api.ndarray.INDArray params()
public org.nd4j.linalg.api.ndarray.INDArray getParam(String param)
Modelpublic void setParam(String key, org.nd4j.linalg.api.ndarray.INDArray val)
Modelpublic void setParams(org.nd4j.linalg.api.ndarray.INDArray params)
Modelprotected void setParams(org.nd4j.linalg.api.ndarray.INDArray params,
char order)
public void setParamsViewArray(org.nd4j.linalg.api.ndarray.INDArray params)
ModelsetParamsViewArray in interface Modelparams - a 1 x nParams row vector that is a view of the larger (MLN/CG) parameters arraypublic org.nd4j.linalg.api.ndarray.INDArray getGradientsViewArray()
getGradientsViewArray in interface Modelpublic void setBackpropGradientsViewArray(org.nd4j.linalg.api.ndarray.INDArray gradients)
ModelsetBackpropGradientsViewArray in interface Modelgradients - a 1 x nParams row vector that is a view of the larger (MLN/CG) gradients arraypublic void setParamTable(Map<String,org.nd4j.linalg.api.ndarray.INDArray> paramTable)
ModelsetParamTable in interface Modelpublic void initParams()
ModelinitParams in interface Modelpublic Map<String,org.nd4j.linalg.api.ndarray.INDArray> paramTable()
ModelparamTable in interface Modelpublic Map<String,org.nd4j.linalg.api.ndarray.INDArray> paramTable(boolean backpropParamsOnly)
ModelparamTable in interface ModelbackpropParamsOnly - If true, return backprop params only. If false: return all params (equivalent to
paramsTable())protected void applyMask(org.nd4j.linalg.api.ndarray.INDArray to)
public org.nd4j.linalg.api.ndarray.INDArray activate(org.nd4j.linalg.api.ndarray.INDArray input,
boolean training,
LayerWorkspaceMgr workspaceMgr)
Layeractivate in interface Layerinput - the input to usetraining - train or test modeworkspaceMgr - Workspace manager.ArrayType.ACTIVATIONS workspace via the workspace managerpublic double calcL2(boolean backpropParamsOnly)
Layerpublic double calcL1(boolean backpropParamsOnly)
Layerpublic int batchSize()
Modelpublic NeuralNetConfiguration conf()
Modelpublic void clear()
Modelprotected void applyDropOutIfNecessary(boolean training,
LayerWorkspaceMgr workspaceMgr)
public Layer.Type type()
Layerpublic int numParams()
public int numParams(boolean backwards)
Modelpublic void fit(org.nd4j.linalg.api.ndarray.INDArray input,
LayerWorkspaceMgr workspaceMgr)
Modelpublic org.nd4j.linalg.primitives.Pair<Gradient,Double> gradientAndScore()
ModelgradientAndScore in interface Modelpublic org.nd4j.linalg.api.ndarray.INDArray input()
Modelpublic void validateInput()
ModelvalidateInput in interface Modelpublic Layer transpose()
Layerpublic void setInputMiniBatchSize(int size)
LayersetInputMiniBatchSize in interface Layerpublic int getInputMiniBatchSize()
LayergetInputMiniBatchSize in interface LayerLayer.setInputMiniBatchSize(int)public void setMaskArray(org.nd4j.linalg.api.ndarray.INDArray maskArray)
LayerLayer.feedForwardMaskArray(INDArray, MaskState, int) should be used in
preference to this.setMaskArray in interface LayermaskArray - Mask array to setpublic org.nd4j.linalg.api.ndarray.INDArray getMaskArray()
getMaskArray in interface Layerpublic org.nd4j.linalg.primitives.Pair<org.nd4j.linalg.api.ndarray.INDArray,MaskState> feedForwardMaskArray(org.nd4j.linalg.api.ndarray.INDArray maskArray, MaskState currentMaskState, int minibatchSize)
LayerfeedForwardMaskArray in interface LayermaskArray - Mask array to setcurrentMaskState - Current state of the mask - see MaskStateminibatchSize - 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 Gradient gradient()
ModelModel#computeGradientAndScore() .public void fit()
Modelpublic double score()
Modelpublic void accumulateScore(double accum)
ModelaccumulateScore in interface Modelaccum - the amount to accumpublic void applyConstraints(int iteration,
int epoch)
ModelapplyConstraints in interface Modelpublic void assertInputSet(boolean backprop)
Copyright © 2018. All rights reserved.