def post_process_inv_depth(inv_depth, inv_depth_flipped, method='mean'): """ Post-process an inverse and flipped inverse depth map Parameters ---------- inv_depth : torch.Tensor [B,1,H,W] Inverse depth map inv_depth_flipped : torch.Tensor [B,1,H,W] Inverse depth map produced from a flipped image method : str Method that will be used to fuse the inverse depth maps Returns ------- inv_depth_pp : torch.Tensor [B,1,H,W] Post-processed inverse depth map """ B, C, H, W = inv_depth.shape inv_depth_hat = flip_lr(inv_depth_flipped) inv_depth_fused = fuse_inv_depth(inv_depth, inv_depth_hat, method=method) xs = torch.linspace(0., 1., W, device=inv_depth.device, dtype=inv_depth.dtype).repeat(B, C, H, 1) mask = 1.0 - torch.clamp(20. * (xs - 0.05), 0., 1.) mask_hat = flip_lr(mask) return mask_hat * inv_depth + mask * inv_depth_hat + \ (1.0 - mask - mask_hat) * inv_depth_fused
def evaluate_depth(self, batch): """Evaluate batch to produce depth metrics.""" # Get predicted depth inv_depths = self.model(batch)['inv_depths'] depth = inv2depth(inv_depths[0]) # Post-process predicted depth batch['rgb'] = flip_lr(batch['rgb']) inv_depths_flipped = self.model(batch)['inv_depths'] inv_depth_pp = post_process_inv_depth(inv_depths[0], inv_depths_flipped[0], method='mean') depth_pp = inv2depth(inv_depth_pp) batch['rgb'] = flip_lr(batch['rgb']) # Calculate predicted metrics metrics = OrderedDict() if 'depth' in batch: for mode in self.metrics_modes: if self.config.model.loss.mask_ego: metrics[self.metrics_name + mode] = compute_ego_depth_metrics( self.config.model.params, gt=batch['depth'], pred=depth_pp if 'pp' in mode else depth, path_to_ego_masks=batch['path_to_ego_mask'], use_gt_scale='gt' in mode) else: metrics[self.metrics_name + mode] = compute_depth_metrics( self.config.model.params, gt=batch['depth'], pred=depth_pp if 'pp' in mode else depth, use_gt_scale='gt' in mode) # Return metrics and extra information return {'metrics': metrics, 'inv_depth': inv_depth_pp}
def evaluate_depth(self, batch): """Evaluate batch to produce depth metrics.""" # Get predicted depth inv_depths = self.model(batch)["inv_depths"] save_image(inv_depths[0], "inv_depths.png") # new depth = inv2depth(inv_depths[0]) # Post-process predicted depth batch["rgb"] = flip_lr(batch["rgb"]) inv_depths_flipped = self.model(batch)["inv_depths"] inv_depth_pp = post_process_inv_depth(inv_depths[0], inv_depths_flipped[0], method="mean") depth_pp = inv2depth(inv_depth_pp) batch["rgb"] = flip_lr(batch["rgb"]) # Calculate predicted metrics metrics = OrderedDict() if "depth" in batch: for mode in self.metrics_modes: metrics[self.metrics_name + mode] = compute_depth_metrics( self.config.model.params, gt=batch["depth"], pred=depth_pp if "pp" in mode else depth, use_gt_scale="gt" in mode, ) # Return metrics and extra information return {"metrics": metrics, "inv_depth": inv_depth_pp}