Class AbstractLayer<I extends TensorBase, O extends TensorBase, W extends TensorBase>
java.lang.Object
deepnetts.net.layers.AbstractLayer<I,O,W>
- Type Parameters:
O- output tensor classW- weights tensor class
- All Implemented Interfaces:
Backward, Forward, Layer<O>, Serializable
- Direct Known Subclasses:
CBOWEmbeddingLayer, ConvolutionalLayer, EmbeddingLayer, FlatEmbeddingLayer, FlattenLayer, FullyConnectedLayer, InputLayer, LayerNorm, MaxPoolingLayer, OutputLayer, SkipGramEmbeddingLayer
public abstract class AbstractLayer<I extends TensorBase, O extends TensorBase, W extends TensorBase>
extends Object
implements Layer<O>, Serializable
Base class for different types of layers. Provides common functionality for
all type of layers: layer dimensions, inputs, outputs, connection to previous
and/or next layer, activation function and abstract methods for
initialization, forward and backward pass.
- See Also:
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected ActivationFunctionActivation function for this layer.protected ActivationTypeType of activation function for this layer.protected Backwardprotected booleanprotected intprotected Tensor1Dprotected AcceleratorHandleprotected Tensor1Dprotected ODeltas used for learning.protected WWeight changes for current and previous iteration.protected intprotected Forwardprotected WGradients of a loss function calculates during a backward pass.protected intprotected IInputs to this layer.protected floatLearning rate for this layer.protected Modeprotected floatprotected NetworkTypeprotected AbstractLayerNext layer in network.protected intprotected Optimizerprotected OptimizerTypeprotected OLayer outputs.protected Tensor1Dprotected WWeight changes for current and previous iteration.protected AbstractLayerPrevious layer in network.protected RandomWeightsTypeprotected floatprotected floatprotected DeepNettsThreadPoolprotected booleanprotected WInput weight matrix / connectivity matrix for previous layer.protected int -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionabstract voidApplies weight changes to current weights Must be diferent for convolutional does nothing for MaxPooling Same for FullyConnected and OutputLayerabstract voidbackward()This method should implement backward pass in subclassesabstract voidforward()This method should implement forward pass in subclassesintfinal OReturns layer deltas/errors (as a tensor).intgetDepth()final WintfloatfloatfloatfloatfloatgetMode()floatprotected intgetNumThreads(int numElements) final OReturns output of this layer (as a tensor).intgetWidth()abstract voidinit()This method should implement layer initialization in subclasses, when a layer is added to the network (create weights, outputs, deltas, randomization etc.).voidbooleanbooleanfinal voidsetActivationType(ActivationType activationType) voidsetBatchMode(boolean batchMode) voidsetBatchSize(int batchSize) voidvoidsetCudaHandles(AcceleratorHandle cudaHandles) final voidvoidsetL1Regularization(float regL1) voidsetL2Regularization(float regL2) voidsetLearningRate(float learningRate) voidvoidsetMomentum(float momentum) voidsetNetworkType(NetworkType networkType) voidsetNextlayer(AbstractLayer nextlayer) voidsetOptimizerType(OptimizerType optType) final voidsetOutputs(O outputs) voidsetPrevDeltaWeights(W prevDeltaWeights) voidsetPrevLayer(AbstractLayer prevLayer) voidsetThreadPool(DeepNettsThreadPool threadPool) voidsetTrainable(boolean trainable) Set trainable to false to freeze learned weights.voidsetWeights(String weightStr) voidsetWeights(W weights)
-
Field Details
-
prevLayer
Previous layer in network. -
nextLayer
Next layer in network. -
networkType
-
weights
Input weight matrix / connectivity matrix for previous layer. Used in FullyConnected and OutputLayer. MaxPooling does not have Weights and ConvolutionalLayer has weights in filters. -
inputs
Inputs to this layer. A reference to outputs in previous layer, or external input in input layer). -
outputs
Layer outputs. -
deltas
Deltas used for learning. -
deltaWeights
Weight changes for current and previous iteration. -
prevDeltaWeights
Weight changes for current and previous iteration. -
gradients
Gradients of a loss function calculates during a backward pass. -
activation
Activation function for this layer. -
activationType
Type of activation function for this layer. -
learningRate
protected float learningRateLearning rate for this layer. -
momentum
protected float momentum -
regL2
protected float regL2 -
regL1
protected float regL1 -
optimizerType
-
batchMode
protected boolean batchMode -
batchSize
protected int batchSize -
width
protected int width -
height
protected int height -
depth
protected int depth -
biases
-
deltaBiases
-
prevDeltaBiases
-
trainable
protected boolean trainable -
optimizer
-
randomWeightsType
-
cudaHandles
-
forwardImpl
-
backwardImpl
-
threadPool
-
numThreads
protected transient int numThreads -
mode
-
-
Constructor Details
-
AbstractLayer
-
-
Method Details
-
init
public abstract void init()This method should implement layer initialization in subclasses, when a layer is added to the network (create weights, outputs, deltas, randomization etc.). -
forward
-
backward
-
applyWeightChanges
public abstract void applyWeightChanges()Applies weight changes to current weights Must be diferent for convolutional does nothing for MaxPooling Same for FullyConnected and OutputLayer -
getWidth
public int getWidth() -
getHeight
public int getHeight() -
getDepth
public int getDepth() -
getPrevlayer
-
setPrevLayer
-
setNextlayer
-
getNextLayer
-
getNetworkType
-
setNetworkType
-
getWeights
-
getBiases
-
setBiases
-
getOutputs
Description copied from interface:LayerReturns output of this layer (as a tensor).- Specified by:
getOutputsin interfaceLayer<I extends TensorBase>- Returns:
- layer output as a tensor
-
getDeltas
-
getGradients
-
getDeltaWeights
-
getPrevDeltaWeights
-
setPrevDeltaWeights
-
getPrevDeltaBiases
-
getDeltaBiases
-
setOutputs
-
setWeights
-
setWeights
-
setDeltas
-
getActivation
-
getOptimizer
-
getLearningRate
public float getLearningRate() -
setLearningRate
public void setLearningRate(float learningRate) -
isBatchMode
public boolean isBatchMode() -
setBatchMode
public void setBatchMode(boolean batchMode) -
getBatchSize
public int getBatchSize() -
setBatchSize
public void setBatchSize(int batchSize) -
setMomentum
public void setMomentum(float momentum) -
getMomentum
public float getMomentum() -
getOptimizerType
-
setOptimizerType
-
getActivationType
-
setActivationType
-
getL1WeightSum
public float getL1WeightSum() -
getL2WeightSum
public float getL2WeightSum() -
getL2Regularization
public float getL2Regularization() -
setL2Regularization
public void setL2Regularization(float regL2) -
getL1Regularization
public float getL1Regularization() -
setL1Regularization
public void setL1Regularization(float regL1) -
isTrainable
public boolean isTrainable() -
setTrainable
public void setTrainable(boolean trainable) Set trainable to false to freeze learned weights.- Parameters:
trainable-
-
initTransientFields
public void initTransientFields() -
setCudaHandles
-
getForwardAcc
-
getBackwardAcc
-
getMode
-
setMode
-
setThreadPool
-
getNumThreads
protected int getNumThreads(int numElements)
-