TemperatureScaler#
- class torch_uncertainty.post_processing.TemperatureScaler(model=None, init_temperature=1, lr=0.1, max_iter=100, eps=1e-08, device=None)[source]#
Temperature scaling post-processing for calibrated probabilities.
- Parameters:
model (
Module|None) – Model to calibrate.init_temperature (
float|Tensor) – Initial value for the temperature. Defaults to1.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 corresponding 2-class logits.
Note
The Scaler will log an error if the temperature after fitting is negative.
- set_model(model)#
Attach a model to the post-processing module.
- Return type:
None