mednet.models.loss_weights¶
Functions
|
Compute the positive weights when using binary targets. |
|
Compute the positive weights when using exclusive, multiclass targets. |
Compute the positive weights when using non-exclusive, multiclass targets. |
|
|
Compute the weights of each class of a DataLoader. |
|
Given a [C x n] tensor of integer targets, checks whether samples can only belong to a single class. |
|
Convert a torch.Tensor to a list. |
- mednet.models.loss_weights.compute_binary_weights(targets)[source]¶
Compute the positive weights when using binary targets.
- Parameters:
targets – A tensor of integer values of length n.
- Returns:
The positive weights per class.
- mednet.models.loss_weights.compute_multiclass_weights(targets)[source]¶
Compute the positive weights when using exclusive, multiclass targets.
- Parameters:
targets – A [C x n] tensor of integer values, where C is the number of target classes and n the number of samples.
- Returns:
The positive weights per class.
- mednet.models.loss_weights.compute_non_exclusive_multiclass_weights(targets)[source]¶
Compute the positive weights when using non-exclusive, multiclass targets.
- Parameters:
targets – A [C x n] tensor of integer values, where C is the number of target classes and n the number of samples.
- Returns:
The positive weights per class.
- mednet.models.loss_weights.is_multicalss_exclusive(targets)[source]¶
Given a [C x n] tensor of integer targets, checks whether samples can only belong to a single class.
- mednet.models.loss_weights.tensor_to_list(tensor)[source]¶
Convert a torch.Tensor to a list.
This is necessary, as torch.tolist returns an int when then tensor contains a single value.
- mednet.models.loss_weights.get_positive_weights(dataloader)[source]¶
Compute the weights of each class of a DataLoader.
This function inputs a pytorch DataLoader and computes the ratio between number of negative and positive samples (scalar). The weight can be used to adjust minimisation criteria to in cases there is a huge data imbalance.
It returns a vector with weights (inverse counts) for each target.
- Parameters:
dataloader (
DataLoader) – A DataLoader from which to compute the positive weights. Entries must be a dictionary which must contain atargetkey.- Return type:
- Returns:
The positive weight of each class in the dataset given as input.