Skip to content

Calibration

Source

Calibration

Calibrate the uncertainty computed over samples from LVAE model.

Calibration is done by learning a scalar that maps the pixel-wise standard deviation of the the predicted samples into the actual prediction error.

compute_bin_boundaries(predict_std)

Compute the bin boundaries for num_bins bins and predicted std values.

compute_stats(pred, pred_std, target)

It computes the bin-wise RMSE and RMV for each channel of the predicted image.

Recall that: - RMSE = np.sqrt((pred - target)2 / num_pixels) - RMV = np.sqrt(np.mean(pred_std2))

ALGORITHM - For each channel: - Given the bin boundaries, assign pixels of std_ch array to a specific bin index. - For each bin index: - Compute the RMSE, RMV, and number of pixels for that bin.

NOTE: each channel of the predicted image/logvar has its own stats.

Parameters:

  • pred (ndarray) –

    Predicted patches, shape (n, h, w, c).

  • pred_std (ndarray) –

    Std computed over the predicted patches, shape (n, h, w, c).

  • target (ndarray) –

    Target GT image, shape (n, h, w, c).

get_calibrated_factor_for_stdev(pred=None, pred_std=None, target=None, q_s=1e-05, q_e=0.99999)

Calibrate the uncertainty by multiplying the predicted std with a scalar.

Parameters:

  • stats_dict (dict[int, dict[str, Union[ndarray, list]]]) –

    Dictionary containing the stats for each channel.

  • q_s (float, default: 1e-05 ) –

    Start quantile, by default 0.00001.

  • q_e (float, default: 0.99999 ) –

    End quantile, by default 0.99999.

Returns:

  • dict[str, float]

    Calibrated factor for each channel (slope + intercept).

get_factors_array(factors_dict)

Get the calibration factors as a numpy array.