[docs]defapply_garg_crop(mask:NDArrayNumber)->NDArrayNumber:"""Apply Garg ECCV16 crop to the mask. Args: mask (np.array): Mask to be cropped, in shape (..., H, W). Returns: np.array: Cropped mask, in shape (..., H', W'). """# crop used by Garg ECCV16h,w=mask.shape[-2:]crop=np.array([0.40810811*h,0.99189189*h,0.03594771*w,0.96405229*w]).astype(np.int32)mask[...,crop[0]:crop[1],crop[2]:crop[3]]=1returnmask
[docs]defapply_eigen_crop(mask:NDArrayNumber)->NDArrayNumber:"""Apply Eigen NIPS14 crop to the mask. Args: mask (np.array): Mask to be cropped, in shape (N, H, W). Returns: np.array: Cropped mask, in shape (N, H', W'). """# https://github.com/mrharicot/monodepth/utils/evaluate_kitti.pyh,w=mask.shape[-2:]crop=np.array([0.3324324*h,0.91351351*h,0.0359477*w,0.96405229*w]).astype(np.int32)mask[...,crop[0]:crop[1],crop[2]:crop[3]]=1returnmask
[docs]def__repr__(self)->str:"""Concise representation of the dataset evaluator."""return"KITTI evaluation for depth"
def_get_eval_mask(self,valid_mask:NDArrayNumber)->NDArrayNumber:"""Do Grag or Eigen cropping for testing."""eval_mask=np.zeros_like(valid_mask)ifself.eval_crop=="garg_crop":eval_mask=apply_garg_crop(eval_mask)elifself.eval_crop=="eigen_crop":eval_mask=apply_eigen_crop(eval_mask)else:eval_mask=np.ones_like(valid_mask)returnnp.logical_and(valid_mask,eval_mask)def_apply_mask(self,prediction:NDArrayFloat,target:NDArrayFloat)->tuple[NDArrayFloat,NDArrayFloat]:"""Apply mask to prediction and target."""valid_mask=(target>self.min_depth)&(target<self.max_depth)eval_mask=self._get_eval_mask(valid_mask)prediction=prediction[eval_mask]target=target[eval_mask]returnprediction,target