Class Yolo2OutputLayer
- java.lang.Object
-
- org.deeplearning4j.nn.layers.AbstractLayer<Yolo2OutputLayer>
-
- org.deeplearning4j.nn.layers.objdetect.Yolo2OutputLayer
-
- All Implemented Interfaces:
Serializable
,Cloneable
,Classifier
,Layer
,IOutputLayer
,Model
,Trainable
public class Yolo2OutputLayer extends AbstractLayer<Yolo2OutputLayer> implements Serializable, IOutputLayer
- See Also:
- Serialized Form
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from interface org.deeplearning4j.nn.api.Layer
Layer.TrainingMode, Layer.Type
-
-
Field Summary
Fields Modifier and Type Field Description protected INDArray
labels
-
Fields inherited from class org.deeplearning4j.nn.layers.AbstractLayer
cacheMode, conf, dataType, dropoutApplied, epochCount, index, input, inputModificationAllowed, iterationCount, maskArray, maskState, preOutput, trainingListeners
-
-
Constructor Summary
Constructors Constructor Description Yolo2OutputLayer(NeuralNetConfiguration conf, DataType dataType)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description INDArray
activate(boolean training, LayerWorkspaceMgr workspaceMgr)
Perform forward pass and return the activations array with the last set inputPair<Gradient,INDArray>
backpropGradient(INDArray epsilon, LayerWorkspaceMgr workspaceMgr)
Calculate the gradient relative to the error in the next layervoid
clearNoiseWeightParams()
Layer
clone()
void
computeGradientAndScore(LayerWorkspaceMgr workspaceMgr)
Update the scoredouble
computeScore(double fullNetRegTerm, boolean training, LayerWorkspaceMgr workspaceMgr)
Compute score after labels and input have been set.INDArray
computeScoreForExamples(double fullNetRegTerm, LayerWorkspaceMgr workspaceMgr)
Compute the score for each example individually, after labels and input have been set.double
f1Score(INDArray examples, INDArray labels)
Returns the f1 score for the given examples.double
f1Score(DataSet data)
Sets the input and labels and returns a score for the prediction wrt true labelsvoid
fit(INDArray examples, int[] labels)
Fit the modelvoid
fit(INDArray examples, INDArray labels)
Fit the modelvoid
fit(DataSet data)
Fit the modelvoid
fit(DataSetIterator iter)
Train the model based on the datasetiteratorINDArray
getConfidenceMatrix(INDArray networkOutput, int example, int bbNumber)
Get the confidence matrix (confidence for all x/y positions) for the specified bounding box, from the network output activations arrayList<DetectedObject>
getPredictedObjects(INDArray networkOutput, double threshold)
INDArray
getProbabilityMatrix(INDArray networkOutput, int example, int classNumber)
Get the probability matrix (probability of the specified class, assuming an object is present, for all x/y positions), from the network output activations arrayPair<Gradient,Double>
gradientAndScore()
Get the gradient and scoreboolean
isPretrainLayer()
Returns true if the layer can be trained in an unsupervised/pretrain manner (AE, VAE, etc)boolean
needsLabels()
Returns true if labels are required for this output layerint
numLabels()
Returns the number of possible labelsint[]
predict(INDArray examples)
Takes in a list of examples For each row, returns a labelList<String>
predict(DataSet dataSet)
Takes in a DataSet of examples For each row, returns a labeldouble
score()
The score for the model-
Methods inherited from class org.deeplearning4j.nn.layers.AbstractLayer
activate, addListeners, allowInputModification, applyConstraints, applyDropOutIfNecessary, applyMask, assertInputSet, backpropDropOutIfPresent, batchSize, calcRegularizationScore, clear, close, conf, feedForwardMaskArray, fit, fit, getConfig, getEpochCount, getGradientsViewArray, getHelper, getIndex, getInput, getInputMiniBatchSize, getListeners, getMaskArray, getOptimizer, getParam, gradient, init, input, layerConf, layerId, numParams, numParams, params, paramTable, paramTable, setBackpropGradientsViewArray, setCacheMode, setConf, setEpochCount, setIndex, setInput, setInputMiniBatchSize, setListeners, setListeners, setMaskArray, setParam, setParams, setParams, setParamsViewArray, setParamTable, type, update, update, updaterDivideByMinibatch
-
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface org.deeplearning4j.nn.api.layers.IOutputLayer
getLabels, setLabels
-
Methods inherited from interface org.deeplearning4j.nn.api.Layer
activate, allowInputModification, calcRegularizationScore, feedForwardMaskArray, getEpochCount, getHelper, getIndex, getInputMiniBatchSize, getIterationCount, getListeners, getMaskArray, setCacheMode, setEpochCount, setIndex, setInput, setInputMiniBatchSize, setIterationCount, setListeners, setListeners, setMaskArray, type
-
Methods inherited from interface org.deeplearning4j.nn.api.Model
addListeners, applyConstraints, batchSize, clear, close, conf, fit, fit, getGradientsViewArray, getOptimizer, getParam, gradient, init, input, numParams, numParams, params, paramTable, paramTable, setBackpropGradientsViewArray, setConf, setParam, setParams, setParamsViewArray, setParamTable, update, update
-
Methods inherited from interface org.deeplearning4j.nn.api.Trainable
getConfig, getGradientsViewArray, numParams, params, paramTable, updaterDivideByMinibatch
-
-
-
-
Field Detail
-
labels
protected INDArray labels
-
-
Constructor Detail
-
Yolo2OutputLayer
public Yolo2OutputLayer(NeuralNetConfiguration conf, DataType dataType)
-
-
Method Detail
-
backpropGradient
public Pair<Gradient,INDArray> backpropGradient(INDArray epsilon, LayerWorkspaceMgr workspaceMgr)
Description copied from interface:Layer
Calculate the gradient relative to the error in the next layer- Specified by:
backpropGradient
in interfaceLayer
- Parameters:
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 manager- Returns:
- Pair
where Gradient is gradient for this layer, INDArray is epsilon (activation gradient) needed by next layer, but before element-wise multiply by sigmaPrime(z). So for standard feed-forward layer, if this layer is L, then return.getSecond() == dL/dIn = (w^(L)*(delta^(L))^T)^T. Note that the returned array should be placed in the ArrayType.ACTIVATION_GRAD
workspace via the workspace manager
-
activate
public INDArray activate(boolean training, LayerWorkspaceMgr workspaceMgr)
Description copied from interface:Layer
Perform forward pass and return the activations array with the last set input- Specified by:
activate
in interfaceLayer
- Parameters:
training
- training or test modeworkspaceMgr
- Workspace manager- Returns:
- the activation (layer output) of the last specified input. Note that the returned array should be placed
in the
ArrayType.ACTIVATIONS
workspace via the workspace manager
-
needsLabels
public boolean needsLabels()
Description copied from interface:IOutputLayer
Returns true if labels are required for this output layer- Specified by:
needsLabels
in interfaceIOutputLayer
- Returns:
- true if this output layer needs labels or not
-
computeScore
public double computeScore(double fullNetRegTerm, boolean training, LayerWorkspaceMgr workspaceMgr)
Description copied from interface:IOutputLayer
Compute score after labels and input have been set.- Specified by:
computeScore
in interfaceIOutputLayer
- Parameters:
fullNetRegTerm
- Regularization score (l1/l2/weight decay) for the entire networktraining
- whether score should be calculated at train or test time (this affects things like application of dropout, etc)- Returns:
- score (loss function)
-
score
public double score()
Description copied from interface:Model
The score for the model- Specified by:
score
in interfaceModel
- Overrides:
score
in classAbstractLayer<Yolo2OutputLayer>
- Returns:
- the score for the model
-
computeGradientAndScore
public void computeGradientAndScore(LayerWorkspaceMgr workspaceMgr)
Description copied from interface:Model
Update the score- Specified by:
computeGradientAndScore
in interfaceModel
- Overrides:
computeGradientAndScore
in classAbstractLayer<Yolo2OutputLayer>
-
gradientAndScore
public Pair<Gradient,Double> gradientAndScore()
Description copied from interface:Model
Get the gradient and score- Specified by:
gradientAndScore
in interfaceModel
- Overrides:
gradientAndScore
in classAbstractLayer<Yolo2OutputLayer>
- Returns:
- the gradient and score
-
computeScoreForExamples
public INDArray computeScoreForExamples(double fullNetRegTerm, LayerWorkspaceMgr workspaceMgr)
Description copied from interface:IOutputLayer
Compute the score for each example individually, after labels and input have been set.- Specified by:
computeScoreForExamples
in interfaceIOutputLayer
- Parameters:
fullNetRegTerm
- Regularization score (l1/l2/weight decay) for the entire network- Returns:
- A column INDArray of shape [numExamples,1], where entry i is the score of the ith example
-
f1Score
public double f1Score(DataSet data)
Description copied from interface:Classifier
Sets the input and labels and returns a score for the prediction wrt true labels- Specified by:
f1Score
in interfaceClassifier
- Parameters:
data
- the data to score- Returns:
- the score for the given input,label pairs
-
f1Score
public double f1Score(INDArray examples, INDArray labels)
Description copied from interface:Classifier
Returns the f1 score for the given examples. Think of this to be like a percentage right. The higher the number the more it got right. This is on a scale from 0 to 1.- Specified by:
f1Score
in interfaceClassifier
- Parameters:
examples
- te the examples to classify (one example in each row)labels
- the true labels- Returns:
- the scores for each ndarray
-
numLabels
public int numLabels()
Description copied from interface:Classifier
Returns the number of possible labels- Specified by:
numLabels
in interfaceClassifier
- Returns:
- the number of possible labels for this classifier
-
fit
public void fit(DataSetIterator iter)
Description copied from interface:Classifier
Train the model based on the datasetiterator- Specified by:
fit
in interfaceClassifier
- Parameters:
iter
- the iterator to train on
-
predict
public int[] predict(INDArray examples)
Description copied from interface:Classifier
Takes in a list of examples For each row, returns a label- Specified by:
predict
in interfaceClassifier
- Parameters:
examples
- the examples to classify (one example in each row)- Returns:
- the labels for each example
-
predict
public List<String> predict(DataSet dataSet)
Description copied from interface:Classifier
Takes in a DataSet of examples For each row, returns a label- Specified by:
predict
in interfaceClassifier
- Parameters:
dataSet
- the examples to classify- Returns:
- the labels for each example
-
fit
public void fit(INDArray examples, INDArray labels)
Description copied from interface:Classifier
Fit the model- Specified by:
fit
in interfaceClassifier
- Parameters:
examples
- the examples to classify (one example in each row)labels
- the example labels(a binary outcome matrix)
-
fit
public void fit(DataSet data)
Description copied from interface:Classifier
Fit the model- Specified by:
fit
in interfaceClassifier
- Parameters:
data
- the data to train on
-
fit
public void fit(INDArray examples, int[] labels)
Description copied from interface:Classifier
Fit the model- Specified by:
fit
in interfaceClassifier
- Parameters:
examples
- the examples to classify (one example in each row)labels
- the labels for each example (the number of labels must match the number of rows in the example
-
isPretrainLayer
public boolean isPretrainLayer()
Description copied from interface:Layer
Returns true if the layer can be trained in an unsupervised/pretrain manner (AE, VAE, etc)- Specified by:
isPretrainLayer
in interfaceLayer
- Returns:
- true if the layer can be pretrained (using fit(INDArray), false otherwise
-
clearNoiseWeightParams
public void clearNoiseWeightParams()
- Specified by:
clearNoiseWeightParams
in interfaceLayer
-
getPredictedObjects
public List<DetectedObject> getPredictedObjects(INDArray networkOutput, double threshold)
-
getConfidenceMatrix
public INDArray getConfidenceMatrix(INDArray networkOutput, int example, int bbNumber)
Get the confidence matrix (confidence for all x/y positions) for the specified bounding box, from the network output activations array- Parameters:
networkOutput
- Network output activationsexample
- Example number, in minibatchbbNumber
- Bounding box number- Returns:
- Confidence matrix
-
getProbabilityMatrix
public INDArray getProbabilityMatrix(INDArray networkOutput, int example, int classNumber)
Get the probability matrix (probability of the specified class, assuming an object is present, for all x/y positions), from the network output activations array- Parameters:
networkOutput
- Network output activationsexample
- Example number, in minibatchclassNumber
- Class number- Returns:
- Confidence matrix
-
-