This class implements a layer that penalizes large differences between objects of the same class. See the paper for details.
The layer may be used as a loss function.
void SetNumberOfClasses( int numberOfClasses );
Sets the number of classes in the model.
void SetClassCentersConvergenceRate( float classCentersConvergenceRate );
Sets the multiplier used for calculating the moving mean of the class centers for each subsequent iteration. This value must be between 0 and 1.
void SetLossWeight( float lossWeight );
Sets the multiplier for this function gradient during training. The default value is 1
. You may wish to change the default if you are using several loss functions in your network.
void SetMaxGradientValue( float maxValue );
Sets the upper limit for the absolute value of the function gradient. Whenever the gradient exceeds this limit its absolute value will be reduced to GetMaxGradientValue()
.
CPtr<const CDnnBlob> GetClassCenters();
Retrieves the class centers that were calculated during the operation of the other layers of the network. The resulting blob is a two-dimensional matrix with GetNumberOfClasses()
rows and Height * Width * Depth * Channels
columns (calculated from the dimensions of the first input blob).
The layer may have 2 to 3 inputs:
-
The network output for which you are calculating the loss function.
-
The class labels represented by a blob with integer data. Each element in the blob contains the number of the class to which the object with this index in the input belongs. The dimensions of the blob are:
BatchLength
,BatchWidth
,ListSize
are equal to the corresponding dimensions of the first input.- all other dimensions are equal to
1
.
-
[Optional] The objects' weights. This input should have the same
BatchLength
,BatchWidth
, andListSize
dimensions as the first input.Height
,Width
,Depth
, andChannels
should be equal to1
.
This layer has no output.
float GetLastLoss() const;
Use this method to get the value of the loss function calculated on the network's last run.