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,
)
| 124 | |
| 125 | |
| 126 | def depth_evaluation( |
| 127 | predicted_depth_original, |
| 128 | ground_truth_depth_original, |
| 129 | max_depth=80, |
| 130 | custom_mask=None, |
| 131 | post_clip_min=None, |
| 132 | post_clip_max=None, |
| 133 | pre_clip_min=None, |
| 134 | pre_clip_max=None, |
| 135 | align_with_lstsq=False, |
| 136 | align_with_lad=False, |
| 137 | align_with_lad2=False, |
| 138 | metric_scale=False, |
| 139 | lr=1e-4, |
| 140 | max_iters=1000, |
| 141 | use_gpu=False, |
| 142 | align_with_scale=False, |
| 143 | disp_input=False, |
| 144 | ): |
| 145 | """ |
| 146 | Evaluate the depth map using various metrics and return a depth error parity map, with an option for least squares alignment. |
| 147 | |
| 148 | Args: |
| 149 | predicted_depth (numpy.ndarray or torch.Tensor): The predicted depth map. |
| 150 | ground_truth_depth (numpy.ndarray or torch.Tensor): The ground truth depth map. |
| 151 | max_depth (float): The maximum depth value to consider. Default is 80 meters. |
| 152 | align_with_lstsq (bool): If True, perform least squares alignment of the predicted depth with ground truth. |
| 153 | |
| 154 | Returns: |
| 155 | dict: A dictionary containing the evaluation metrics. |
| 156 | torch.Tensor: The depth error parity map. |
| 157 | """ |
| 158 | if isinstance(predicted_depth_original, np.ndarray): |
| 159 | predicted_depth_original = torch.from_numpy(predicted_depth_original) |
| 160 | if isinstance(ground_truth_depth_original, np.ndarray): |
| 161 | ground_truth_depth_original = torch.from_numpy(ground_truth_depth_original) |
| 162 | if custom_mask is not None and isinstance(custom_mask, np.ndarray): |
| 163 | custom_mask = torch.from_numpy(custom_mask) |
| 164 | |
| 165 | # if the dimension is 3, flatten to 2d along the batch dimension |
| 166 | if predicted_depth_original.dim() == 3: |
| 167 | _, h, w = predicted_depth_original.shape |
| 168 | predicted_depth_original = predicted_depth_original.view(-1, w) |
| 169 | ground_truth_depth_original = ground_truth_depth_original.view(-1, w) |
| 170 | if custom_mask is not None: |
| 171 | custom_mask = custom_mask.view(-1, w) |
| 172 | |
| 173 | # put to device |
| 174 | if use_gpu: |
| 175 | predicted_depth_original = predicted_depth_original.cuda() |
| 176 | ground_truth_depth_original = ground_truth_depth_original.cuda() |
| 177 | |
| 178 | # Filter out depths greater than max_depth |
| 179 | if max_depth is not None: |
| 180 | mask = (ground_truth_depth_original > 0) & ( |
| 181 | ground_truth_depth_original < max_depth |
| 182 | ) |
| 183 | else: |
no test coverage detected