spine.utils.weighting
Module which contains methods to compute class weights.
All methods compute the weights based on the relative abundance of each class.
Functions
|
Computes class-wise weights based on their relative abundance. |
- spine.utils.weighting.get_class_weights(labels, num_classes, mode='const', per_class=True)[source]
Computes class-wise weights based on their relative abundance.
- Parameters:
labels (Union[np.ndarray, torch.Tensor]) –
Array of class values to base the weighting scheme on
num_classes (int) – Total number of classes (needed if there are some missing)
mode (str, default const) – Weigthing mode (one of ‘const’, ‘log’, ‘sqrt’
per_class (bool, default True) – If True, returns one valuer per class. Otherwise, this function returns one value per input in the classes array