Evaluate the depth map using various metrics and return a depth error parity map, with an option for least squares alignment. Args: predicted_depth (numpy.ndarray or torch.Tensor): The predicted depth map. ground_truth_depth (numpy.ndarray or torch.Tensor): The ground truth
(
predicted_depth_original,
ground_truth_depth_original,
max_depth=80,
custom_mask=None,
post_clip_min=None,
post_clip_max=None,
pre_clip_min=None,
pre_clip_max=None,
align_with_lstsq=False,
align_with_lad=False,
align_with_lad2=False,
metric_scale=False,
lr=1e-4,
max_iters=1000,
use_gpu=False,
align_with_scale=False,
disp_input=False,
)
| 191 | |
| 192 | |
| 193 | def depth_evaluation( |
| 194 | predicted_depth_original, |
| 195 | ground_truth_depth_original, |
| 196 | max_depth=80, |
| 197 | custom_mask=None, |
| 198 | post_clip_min=None, |
| 199 | post_clip_max=None, |
| 200 | pre_clip_min=None, |
| 201 | pre_clip_max=None, |
| 202 | align_with_lstsq=False, |
| 203 | align_with_lad=False, |
| 204 | align_with_lad2=False, |
| 205 | metric_scale=False, |
| 206 | lr=1e-4, |
| 207 | max_iters=1000, |
| 208 | use_gpu=False, |
| 209 | align_with_scale=False, |
| 210 | disp_input=False, |
| 211 | ): |
| 212 | """ |
| 213 | Evaluate the depth map using various metrics and return a depth error parity map, with an option for least squares alignment. |
| 214 | |
| 215 | Args: |
| 216 | predicted_depth (numpy.ndarray or torch.Tensor): The predicted depth map. |
| 217 | ground_truth_depth (numpy.ndarray or torch.Tensor): The ground truth depth map. |
| 218 | max_depth (float): The maximum depth value to consider. Default is 80 meters. |
| 219 | align_with_lstsq (bool): If True, perform least squares alignment of the predicted depth with ground truth. |
| 220 | |
| 221 | Returns: |
| 222 | dict: A dictionary containing the evaluation metrics. |
| 223 | torch.Tensor: The depth error parity map. |
| 224 | """ |
| 225 | if isinstance(predicted_depth_original, np.ndarray): |
| 226 | predicted_depth_original = torch.from_numpy(predicted_depth_original) |
| 227 | if isinstance(ground_truth_depth_original, np.ndarray): |
| 228 | ground_truth_depth_original = torch.from_numpy(ground_truth_depth_original) |
| 229 | if custom_mask is not None and isinstance(custom_mask, np.ndarray): |
| 230 | custom_mask = torch.from_numpy(custom_mask) |
| 231 | |
| 232 | # if the dimension is 3, flatten to 2d along the batch dimension |
| 233 | if predicted_depth_original.dim() == 3: |
| 234 | _, h, w = predicted_depth_original.shape |
| 235 | predicted_depth_original = predicted_depth_original.view(-1, w) |
| 236 | ground_truth_depth_original = ground_truth_depth_original.view(-1, w) |
| 237 | if custom_mask is not None: |
| 238 | custom_mask = custom_mask.view(-1, w) |
| 239 | |
| 240 | # put to device |
| 241 | if use_gpu: |
| 242 | predicted_depth_original = predicted_depth_original.cuda() |
| 243 | ground_truth_depth_original = ground_truth_depth_original.cuda() |
| 244 | |
| 245 | # Filter out depths greater than max_depth |
| 246 | if max_depth is not None: |
| 247 | mask = (ground_truth_depth_original > 0) & ( |
| 248 | ground_truth_depth_original < max_depth |
| 249 | ) |
| 250 | else: |
no test coverage detected