MatrixScaler#
- class torch_uncertainty.post_processing.MatrixScaler(num_classes, model=None, init_weight_temperature=1, init_bias_temperature=None, lr=0.1, max_iter=200, eps=1e-08, device=None)[source]#
Matrix scaling post-processing for calibrated probabilities.
- Parameters:
num_classes (
int) – Number of classes.model (
Module|None) – Model to calibrate. Defaults toNone.init_weight_temperature (
float|Tensor) – Initial value for the weights. Defaults to1.init_bias_temperature (
float|Tensor|None) – Initial value for the bias. The inverse bias will be set to the0vector if set toNone. Defaults toNone.lr (
float) – Learning rate for the optimizer. Defaults to0.1.max_iter (
int) – Maximum number of iterations for the optimizer. Defaults to100.eps (
float) – Small value for stability. Defaults to1e-8.device (
Union[Literal['cpu','cuda'],device,None]) – Device to use for optimization. Defaults toNone.
References
[1] On calibration of modern neural networks. In ICML 2017.
Warning
If the model is binary, we will by default apply the sigmoid before transposing the prediction to the 2-class case.
- fit(dataloader, save_logits=False, progress=True)#
Fit the temperature parameters to the calibration data.
- Parameters:
dataloader (
DataLoader) – Dataloader with the logits and target of the calibration data.save_logits (
bool) – Whether to save the logits and labels in memory. Defaults toFalse.progress (
bool) – Whether to show a progress bar. Defaults toTrue.
- Return type:
None
Warning
Please provide logits and not probabilities/likelihoods within the dataloader, otherwise the Scaler might converge to negative temperatures.
- set_model(model)#
Attach a model to the post-processing module.
- Return type:
None