Calculate Boundary F1 score. Args: ---- pr (np.ndarray): Predicted depth matrix. gt (np.ndarray): Ground truth depth matrix. t (float): Threshold for comparison. return_p (bool, optional): If True, return precision. Defaults to False. return_r (bool,
(
pr: np.ndarray,
gt: np.ndarray,
t: float,
return_p: bool = False,
return_r: bool = False,
)
| 176 | |
| 177 | |
| 178 | def boundary_f1( |
| 179 | pr: np.ndarray, |
| 180 | gt: np.ndarray, |
| 181 | t: float, |
| 182 | return_p: bool = False, |
| 183 | return_r: bool = False, |
| 184 | ) -> float: |
| 185 | """Calculate Boundary F1 score. |
| 186 | |
| 187 | Args: |
| 188 | ---- |
| 189 | pr (np.ndarray): Predicted depth matrix. |
| 190 | gt (np.ndarray): Ground truth depth matrix. |
| 191 | t (float): Threshold for comparison. |
| 192 | return_p (bool, optional): If True, return precision. Defaults to False. |
| 193 | return_r (bool, optional): If True, return recall. Defaults to False. |
| 194 | |
| 195 | Returns: |
| 196 | ------- |
| 197 | float: Boundary F1 score, or precision, or recall depending on the flags. |
| 198 | |
| 199 | """ |
| 200 | ap, bp, cp, dp = fgbg_depth(pr, t) |
| 201 | ag, bg, cg, dg = fgbg_depth(gt, t) |
| 202 | |
| 203 | r = 0.25 * ( |
| 204 | np.count_nonzero(ap & ag) / max(np.count_nonzero(ag), 1) |
| 205 | + np.count_nonzero(bp & bg) / max(np.count_nonzero(bg), 1) |
| 206 | + np.count_nonzero(cp & cg) / max(np.count_nonzero(cg), 1) |
| 207 | + np.count_nonzero(dp & dg) / max(np.count_nonzero(dg), 1) |
| 208 | ) |
| 209 | p = 0.25 * ( |
| 210 | np.count_nonzero(ap & ag) / max(np.count_nonzero(ap), 1) |
| 211 | + np.count_nonzero(bp & bg) / max(np.count_nonzero(bp), 1) |
| 212 | + np.count_nonzero(cp & cg) / max(np.count_nonzero(cp), 1) |
| 213 | + np.count_nonzero(dp & dg) / max(np.count_nonzero(dp), 1) |
| 214 | ) |
| 215 | if r + p == 0: |
| 216 | return 0.0 |
| 217 | if return_p: |
| 218 | return p |
| 219 | if return_r: |
| 220 | return r |
| 221 | return 2 * (r * p) / (r + p) |
| 222 | |
| 223 | |
| 224 | def get_thresholds_and_weights( |
no test coverage detected