CCenterLossLayer Class
June 14, 2020 ยท View on GitHub
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.
Settings
Classes number
void SetNumberOfClasses( int numberOfClasses );
Sets the number of classes in the model.
Class centers convergence
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.
Loss weight
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.
Gradient clipping
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().
Trainable parameters
Class centers
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).
Inputs
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,ListSizeare 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, andListSizedimensions as the first input.Height,Width,Depth, andChannelsshould be equal to1.
Outputs
This layer has no output.
Getting the value of the loss function
float GetLastLoss() const;
Use this method to get the value of the loss function calculated on the network's last run.