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.
Source code in src/careamics/lvae_training/calibration.py
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 |
|
compute_bin_boundaries(predict_std)
#
Compute the bin boundaries for num_bins
bins and predicted std values.
Source code in src/careamics/lvae_training/calibration.py
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 |
Source code in src/careamics/lvae_training/calibration.py
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). |
Source code in src/careamics/lvae_training/calibration.py
get_factors_array(factors_dict)
#
Get the calibration factors as a numpy array.