1414from .metrics import m_rel_ae , pointwise_rel_ae , thresh_inliers , sparsification
1515
1616
17- # TODO: add tensorboard logging
18-
19-
2017class MultiViewDepthEvaluation :
2118 """Multi-view depth evaluation.
2219
@@ -30,6 +27,9 @@ class MultiViewDepthEvaluation:
3027 A typical depth-from-video model would set
3128 inputs=["images", "intrinsics"], alignment="median".
3229
30+ A typical depth-from-single-view model would set
31+ inputs=["images"], max_source_views=0, alignment="median".
32+
3333 Args:
3434 out_dir: Directory where results will be written. If None, results are not written to disk.
3535 inputs: List of input modalities that are supplied to the algorithm.
@@ -39,9 +39,12 @@ class MultiViewDepthEvaluation:
3939 None evaluates predictions without any alignment.
4040 "median" scales predicted depth maps with the ratio of medians of predicted and ground truth depth maps.
4141 "translation" scales predicted depth maps with the ratio of the predicted and ground truth translation.
42+ max_source_views: Maximum number of source views to be considered. None means all available source views are
43+ considered. Default: None.
44+ min_source_views. Minimum number of source views provided to the model.
45+ If max_source_views is not None, is set to min(min_source_views, max_source_views). Default: 1.
4246 view_ordering: Ordering of source views during the evaluation.
43- Options are "quasi-optimal", "nearest" and None. Default: "quasi-optimal".
44- None: supply all source views to the model and evaluate predicted depth map.
47+ Options are "quasi-optimal" and "nearest". Default: "quasi-optimal".
4548 "quasi-optimal": evaluate predicted depth maps for all (keyview, sourceview) pairs.
4649 Order source views according to the prediction accuracy. Increase source view set based on
4750 the obtained ordering and re-evaluate for each additional source view.
@@ -50,8 +53,6 @@ class MultiViewDepthEvaluation:
5053 view set based on the ordering of views in the sample, i.e. based on the distance between source
5154 view indices and the keyview index. Log results based on the number of source views.
5255 Log best results as overall results.
53- max_source_views: Maximum number of source views to be considered in case view_ordering is
54- "quasi-optimal" or "nearest". None means all available source views are considered.
5556 eval_uncertainty: Evaluate predicted uncertainty (pred_depth_uncertainty) if available.
5657 Increases evaluation time.
5758 clip_pred_depth: Clip model predictions before evaluation to a reasonable range. This makes sense to reduce
@@ -64,12 +65,14 @@ def __init__(self,
6465 out_dir : Optional [str ] = None ,
6566 inputs : Sequence [str ] = None ,
6667 alignment : Optional [str ] = None ,
67- view_ordering : str = "quasi-optimal" ,
6868 max_source_views : Optional [int ] = None ,
69+ min_source_views : int = 1 ,
70+ view_ordering : str = "quasi-optimal" ,
6971 eval_uncertainty : bool = True ,
7072 clip_pred_depth : Union [bool , Tuple [float , float ]] = True ,
7173 sparse_pred : bool = False ,
7274 verbose : bool = True ,
75+ ** _
7376 ):
7477
7578 self .verbose = verbose
@@ -89,8 +92,9 @@ def __init__(self,
8992
9093 self .inputs = list (set (inputs + ["images" ])) if inputs is not None else ["images" ]
9194 self .alignment = alignment
92- self .view_ordering = view_ordering
9395 self .max_source_views = max_source_views
96+ self .min_source_views = min_source_views if max_source_views is None else min (min_source_views , max_source_views )
97+ self .view_ordering = view_ordering if (self .max_source_views is None ) or (self .max_source_views > 0 ) else None
9498 self .eval_uncertainty = eval_uncertainty
9599 self .clip_pred_depth = clip_pred_depth
96100 self .sparse_pred = sparse_pred
@@ -120,8 +124,9 @@ def __str__(self):
120124 ret = f"{ self .name } with settings:"
121125 ret += f"\n \t Inputs: { self .inputs } "
122126 ret += f"\n \t Alignment: { self .alignment } "
123- ret += f"\n \t View ordering : { self .view_ordering } "
127+ ret += f"\n \t Min source views : { self .min_source_views } "
124128 ret += f"\n \t Max source views: { self .max_source_views } "
129+ ret += f"\n \t View ordering: { self .view_ordering } "
125130 ret += f"\n \t Evaluate uncertainty: { self .eval_uncertainty } "
126131 ret += f"\n \t Clip predicted depth: { self .clip_pred_depth } "
127132 ret += f"\n \t Predicted depth is sparse: { self .sparse_pred } "
@@ -222,7 +227,7 @@ def _evaluate(self):
222227 ordered_source_indices = self ._get_source_view_ordering (sample_inputs = sample_inputs , sample_gt = sample_gt )
223228 max_source_views = min (len (ordered_source_indices ), self .max_source_views ) \
224229 if self .max_source_views is not None else len (ordered_source_indices )
225- min_source_views = 1 if self .view_ordering is not None else max_source_views
230+ min_source_views = self .min_source_views
226231
227232 best_metrics = None
228233 best_num_source_views = np .nan
@@ -234,7 +239,7 @@ def _evaluate(self):
234239 cur_keyview_idx = cur_view_indices .index (keyview_idx )
235240
236241 if self .verbose :
237- print (f"\t Evaluating with { num_source_views } / { len ( ordered_source_indices ) } source views:" )
242+ print (f"\t Evaluating with { num_source_views } / { max_source_views } source views:" )
238243 print (f"\t \t Source view indices: { cur_source_indices } ." )
239244
240245 self ._reset_memory_stats ()
@@ -371,7 +376,7 @@ def _init_results(self):
371376 def _get_source_view_ordering (self , sample_inputs , sample_gt ):
372377 if self .view_ordering == 'quasi-optimal' :
373378 return self ._get_quasi_optimal_source_view_ordering (sample_inputs = sample_inputs , sample_gt = sample_gt )
374- else :
379+ elif ( self . view_ordering == 'nearest' ) or ( self . view_ordering is None ) :
375380 return self ._get_nearest_source_view_ordering (sample_inputs = sample_inputs , sample_gt = sample_gt )
376381
377382 def _get_nearest_source_view_ordering (self , sample_inputs , sample_gt ):
@@ -389,13 +394,17 @@ def _get_quasi_optimal_source_view_ordering(self, sample_inputs, sample_gt):
389394 # construct temporary sample with a single source view:
390395 cur_sample_inputs = deepcopy (sample_inputs )
391396 cur_sample_gt = deepcopy (sample_gt )
392- cur_sample_inputs ['images' ] = [cur_sample_inputs ['images' ][keyview_idx ],
393- cur_sample_inputs ['images' ][source_idx ]]
394- cur_sample_inputs ['poses' ] = [cur_sample_inputs ['poses' ][keyview_idx ],
395- cur_sample_inputs ['poses' ][source_idx ]]
396- cur_sample_inputs ['intrinsics' ] = [cur_sample_inputs ['intrinsics' ][keyview_idx ],
397- cur_sample_inputs ['intrinsics' ][source_idx ]]
397+ if "images" in self .inputs :
398+ cur_sample_inputs ['images' ] = [cur_sample_inputs ['images' ][keyview_idx ],
399+ cur_sample_inputs ['images' ][source_idx ]]
400+ if "poses" in self .inputs :
401+ cur_sample_inputs ['poses' ] = [cur_sample_inputs ['poses' ][keyview_idx ],
402+ cur_sample_inputs ['poses' ][source_idx ]]
403+ if "intrinsics" in self .inputs :
404+ cur_sample_inputs ['intrinsics' ] = [cur_sample_inputs ['intrinsics' ][keyview_idx ],
405+ cur_sample_inputs ['intrinsics' ][source_idx ]]
398406 cur_sample_inputs ['keyview_idx' ] = np .array ([0 ])
407+ # depth_range is not changed
399408
400409 # run model:
401410 pred , _ , _ = self ._run_model (cur_sample_inputs )
0 commit comments