ConformalClsTHR#

class torch_uncertainty.post_processing.ConformalClsTHR(alpha, model=None, ts_init_val=1.0, ts_lr=0.1, ts_max_iter=100, enable_ts=True, device=None)[source]#

Conformal prediction post-processing for calibrated models.

Parameters:
  • alpha (float) – The confidence level, meaning we allow \(1-\alpha\) error.

  • model (nn.Module, optional) – Model to be calibrated. Defaults to None.

  • ts_init_val (float, optional) – Initial value for the temperature. Defaults to 1.0.

  • ts_lr (float, optional) – Learning rate for the optimizer. Defaults to 0.1.

  • ts_max_iter (int, optional) – Maximum number of iterations for the optimizer. Defaults to 100.

  • enable_ts (bool) – Whether to scale the logits. Defaults to True.

  • device (Literal["cpu", "cuda"] | torch.device | None, optional) – device. Defaults to None.

Reference:

Code inspired by TorchCP.

conformal(inputs)[source]#

Perform conformal prediction on the test set.

model_forward(inputs)#

Apply the model and return the scores.