Calibration
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:
| Name | Type | Description | Default |
|---|---|---|---|
pred
|
ndarray
|
Predicted patches, shape (n, h, w, c). |
required |
pred_std
|
ndarray
|
Std computed over the predicted patches, shape (n, h, w, c). |
required |
target
|
ndarray
|
Target GT image, shape (n, h, w, c). |
required |
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:
| Name | Type | Description | Default |
|---|---|---|---|
stats_dict
|
dict[int, dict[str, Union[ndarray, list]]]
|
Dictionary containing the stats for each channel. |
required |
q_s
|
float
|
Start quantile, by default 0.00001. |
1e-05
|
q_e
|
float
|
End quantile, by default 0.99999. |
0.99999
|
Returns:
| Type | Description |
|---|---|
dict[str, float]
|
Calibrated factor for each channel (slope + intercept). |
get_factors_array(factors_dict)
Get the calibration factors as a numpy array.