public abstract class BaseLayer<LayerConfT extends BaseLayer> extends AbstractLayer<LayerConfT>
Layer.TrainingMode, Layer.Type
Modifier and Type | Field and Description |
---|---|
protected Gradient |
gradient |
protected INDArray |
gradientsFlattened |
protected Map<String,INDArray> |
gradientViews |
protected ConvexOptimizer |
optimizer |
protected Map<String,INDArray> |
params |
protected INDArray |
paramsFlattened |
protected double |
score |
protected Solver |
solver |
protected Map<String,INDArray> |
weightNoiseParams |
cacheMode, conf, dataType, dropoutApplied, epochCount, index, input, inputModificationAllowed, iterationCount, maskArray, maskState, preOutput, trainingListeners
Constructor and Description |
---|
BaseLayer(NeuralNetConfiguration conf,
org.nd4j.linalg.api.buffer.DataType dataType) |
Modifier and Type | Method and Description |
---|---|
INDArray |
activate(boolean training,
LayerWorkspaceMgr workspaceMgr)
Perform forward pass and return the activations array with the last set input
|
Pair<Gradient,INDArray> |
backpropGradient(INDArray epsilon,
LayerWorkspaceMgr workspaceMgr)
Calculate the gradient relative to the error in the next layer
|
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 |
void |
clear()
Clear input
|
void |
clearNoiseWeightParams() |
Layer |
clone() |
void |
computeGradientAndScore(LayerWorkspaceMgr workspaceMgr)
Update the score
|
void |
fit()
All models have a fit method
|
void |
fit(INDArray input,
LayerWorkspaceMgr workspaceMgr)
Fit the model to the given data
|
INDArray |
getGradientsViewArray() |
ConvexOptimizer |
getOptimizer()
Returns this models optimizer
|
INDArray |
getParam(String param)
Get the parameter
|
protected INDArray |
getParamWithNoise(String param,
boolean training,
LayerWorkspaceMgr workspaceMgr)
Get the parameter, after applying any weight noise (such as DropConnect) if necessary.
|
Gradient |
gradient()
Get the gradient.
|
boolean |
hasBias()
Does this layer have no bias term? Many layers (dense, convolutional, output, embedding) have biases by
default, but no-bias versions are possible via configuration
|
boolean |
hasLayerNorm()
Does this layer support and is it enabled layer normalization? Only Dense and SimpleRNN Layers support
layer normalization.
|
LayerConfT |
layerConf() |
long |
numParams()
The number of parameters for the model
|
INDArray |
params()
Returns the parameters of the neural network as a flattened row vector
|
Map<String,INDArray> |
paramTable()
The param table
|
Map<String,INDArray> |
paramTable(boolean backpropParamsOnly)
Table of parameters by key, for backprop
For many models (dense layers, etc) - all parameters are backprop parameters
|
protected INDArray |
preOutput(boolean training,
LayerWorkspaceMgr workspaceMgr) |
protected Pair<INDArray,INDArray> |
preOutputWithPreNorm(boolean training,
boolean forBackprop,
LayerWorkspaceMgr workspaceMgr) |
double |
score()
Objective function: the specified objective
|
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 |
setParam(String key,
INDArray val)
Set the parameter with a new ndarray
|
void |
setParams(INDArray params)
Set the parameters for this model.
|
protected void |
setParams(INDArray params,
char order) |
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)
Setter for the param table
|
protected void |
setScoreWithZ(INDArray z) |
String |
toString() |
void |
update(Gradient gradient)
Update layer weights and biases with gradient change
|
void |
update(INDArray gradient,
String paramType)
Perform one update applying the gradient
|
activate, addListeners, allowInputModification, applyConstraints, applyDropOutIfNecessary, applyMask, assertInputSet, backpropDropOutIfPresent, batchSize, conf, feedForwardMaskArray, getConfig, getEpochCount, getHelper, getIndex, getInput, getInputMiniBatchSize, getListeners, getMaskArray, gradientAndScore, init, input, layerId, numParams, setCacheMode, setConf, setEpochCount, setIndex, setInput, setInputMiniBatchSize, setListeners, setListeners, setMaskArray, type, updaterDivideByMinibatch
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
getIterationCount, isPretrainLayer, setIterationCount
protected INDArray paramsFlattened
protected INDArray gradientsFlattened
protected double score
protected ConvexOptimizer optimizer
protected Gradient gradient
protected Solver solver
public BaseLayer(NeuralNetConfiguration conf, org.nd4j.linalg.api.buffer.DataType dataType)
public LayerConfT layerConf()
layerConf
in class AbstractLayer<LayerConfT extends BaseLayer>
public Pair<Gradient,INDArray> backpropGradient(INDArray epsilon, LayerWorkspaceMgr workspaceMgr)
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 fit()
Model
fit
in interface Model
fit
in class AbstractLayer<LayerConfT extends BaseLayer>
public void computeGradientAndScore(LayerWorkspaceMgr workspaceMgr)
Model
computeGradientAndScore
in interface Model
computeGradientAndScore
in class AbstractLayer<LayerConfT extends BaseLayer>
protected void setScoreWithZ(INDArray z)
public double score()
score
in interface Model
score
in class AbstractLayer<LayerConfT extends BaseLayer>
public Gradient gradient()
Model
Model.computeGradientAndScore(LayerWorkspaceMgr)
} .gradient
in interface Model
gradient
in class AbstractLayer<LayerConfT extends BaseLayer>
public void update(Gradient gradient)
Model
update
in interface Model
update
in class AbstractLayer<LayerConfT extends BaseLayer>
public void update(INDArray gradient, String paramType)
Model
update
in interface Model
update
in class AbstractLayer<LayerConfT extends BaseLayer>
gradient
- the gradient to applypublic ConvexOptimizer getOptimizer()
Model
getOptimizer
in interface Model
getOptimizer
in class AbstractLayer<LayerConfT extends BaseLayer>
public INDArray params()
params
in interface Model
params
in interface Trainable
params
in class AbstractLayer<LayerConfT extends BaseLayer>
public INDArray getParam(String param)
Model
getParam
in interface Model
getParam
in class AbstractLayer<LayerConfT extends BaseLayer>
param
- the key of the parameterpublic void setParam(String key, INDArray val)
Model
setParam
in interface Model
setParam
in class AbstractLayer<LayerConfT extends BaseLayer>
key
- the key to se tval
- the new ndarraypublic void setParams(INDArray params)
Model
setParams
in interface Model
setParams
in class AbstractLayer<LayerConfT extends BaseLayer>
params
- the parameters for the modelprotected void setParams(INDArray params, char order)
setParams
in class AbstractLayer<LayerConfT extends BaseLayer>
public void setParamsViewArray(INDArray params)
Model
setParamsViewArray
in interface Model
setParamsViewArray
in class AbstractLayer<LayerConfT extends BaseLayer>
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
getGradientsViewArray
in class AbstractLayer<LayerConfT extends BaseLayer>
public void setBackpropGradientsViewArray(INDArray gradients)
Model
setBackpropGradientsViewArray
in interface Model
setBackpropGradientsViewArray
in class AbstractLayer<LayerConfT extends BaseLayer>
gradients
- a 1 x nParams row vector that is a view of the larger (MLN/CG) gradients arraypublic void setParamTable(Map<String,INDArray> paramTable)
Model
setParamTable
in interface Model
setParamTable
in class AbstractLayer<LayerConfT extends BaseLayer>
public Map<String,INDArray> paramTable()
Model
paramTable
in interface Model
paramTable
in class AbstractLayer<LayerConfT extends BaseLayer>
public Map<String,INDArray> paramTable(boolean backpropParamsOnly)
Model
paramTable
in interface Model
paramTable
in interface Trainable
paramTable
in class AbstractLayer<LayerConfT extends BaseLayer>
backpropParamsOnly
- If true, return backprop params only. If false: return all params (equivalent to
paramsTable())protected INDArray getParamWithNoise(String param, boolean training, LayerWorkspaceMgr workspaceMgr)
param
- Parameter keytraining
- If true: during trainingprotected INDArray preOutput(boolean training, LayerWorkspaceMgr workspaceMgr)
protected Pair<INDArray,INDArray> preOutputWithPreNorm(boolean training, boolean forBackprop, LayerWorkspaceMgr workspaceMgr)
public INDArray activate(boolean training, LayerWorkspaceMgr workspaceMgr)
Layer
training
- training or test modeworkspaceMgr
- Workspace managerArrayType.ACTIVATIONS
workspace via the workspace managerpublic double calcRegularizationScore(boolean backpropParamsOnly)
Layer
calcRegularizationScore
in interface Layer
calcRegularizationScore
in class AbstractLayer<LayerConfT extends BaseLayer>
backpropParamsOnly
- If true: calculate regularization score based on backprop params only. If false: calculate
based on all params (including pretrain params, if any)public long numParams()
numParams
in interface Model
numParams
in interface Trainable
numParams
in class AbstractLayer<LayerConfT extends BaseLayer>
public void fit(INDArray input, LayerWorkspaceMgr workspaceMgr)
Model
fit
in interface Model
fit
in class AbstractLayer<LayerConfT extends BaseLayer>
input
- the data to fit the model topublic void clear()
Model
clear
in interface Model
clear
in class AbstractLayer<LayerConfT extends BaseLayer>
public void clearNoiseWeightParams()
public boolean hasBias()
public boolean hasLayerNorm()
Copyright © 2019. All rights reserved.