CMultiHingeLossLayer Class
June 14, 2020 ยท View on GitHub
This class implements a layer that calculates a hinge loss function for a classification scenario with multiple classes.
The function is calculated according to the formula:
loss = max(0, 1 - (x_right - x_max_wrong))
where:
x_rightis the network response for the class to which the object belongs.x_max_wrongis the largest of the responses for the other classes.
Settings
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
This layer has no trainable parameters.
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 in one of the two formats:
- the blob contains
floatdata, withBatchLength,BatchWidth, andListSizeequal to these dimensions of the first input, andGetObjectSize()equal to the number of classes. It should contain the probability distribution for an object to belong to any of those classes. - the blob contains
intdata withBatchLength,BatchWidth, andListSizeequal to these dimensions of the first input, and the other dimensions equal to1. Each object in the blob contains the number of the class to which the corresponding object from the first input belongs.
- the blob contains
-
[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.