(metric_func)
| 158 | |
| 159 | # a wrapper to compute metrics for each image individually |
| 160 | def compute_metrics_for_each_image(metric_func): |
| 161 | def wrapper(depth_est, depth_gt, mask, *args): |
| 162 | batch_size = depth_gt.shape[0] |
| 163 | results = [] |
| 164 | # compute result one by one |
| 165 | for idx in range(batch_size): |
| 166 | ret = metric_func(depth_est[idx], depth_gt[idx], mask[idx], *args) |
| 167 | if torch.isnan(ret): |
| 168 | results.append(torch.zeros_like(ret)) |
| 169 | else: |
| 170 | results.append(ret) |
| 171 | return torch.stack(results).mean() |
| 172 | |
| 173 | return wrapper |
| 174 | |
| 175 | |
| 176 | @torch.no_grad() |
nothing calls this directly
no outgoing calls
no test coverage detected