Depth

packnet_sfm.utils.depth.calc_smoothness(inv_depths, images, num_scales)[source]

Calculate smoothness values for inverse depths

Parameters
  • inv_depths (list of torch.Tensor [B,1,H,W]) – Inverse depth maps

  • images (list of torch.Tensor [B,3,H,W]) – Inverse depth maps

  • num_scales (int) – Number of scales considered

Returns

  • smoothness_x (list of torch.Tensor [B,1,H,W]) – Smoothness values in direction x

  • smoothness_y (list of torch.Tensor [B,1,H,W]) – Smoothness values in direction y

packnet_sfm.utils.depth.compute_depth_metrics(config, gt, pred, use_gt_scale=True)[source]

Compute depth metrics from predicted and ground-truth depth maps

Parameters
  • config (CfgNode) – Metrics parameters

  • gt (torch.Tensor [B,1,H,W]) – Ground-truth depth map

  • pred (torch.Tensor [B,1,H,W]) – Predicted depth map

  • use_gt_scale (bool) – True if ground-truth median-scaling is to be used

Returns

metrics – Depth metrics (abs_rel, sq_rel, rmse, rmse_log, a1, a2, a3)

Return type

torch.Tensor [7]

packnet_sfm.utils.depth.depth2inv(depth)[source]

Invert a depth map to produce an inverse depth map

Parameters

depth (torch.Tensor or list of torch.Tensor [B,1,H,W]) – Depth map

Returns

inv_depth – Inverse depth map

Return type

torch.Tensor or list of torch.Tensor [B,1,H,W]

packnet_sfm.utils.depth.fuse_inv_depth(inv_depth, inv_depth_hat, method='mean')[source]

Fuse inverse depth and flipped inverse depth maps

Parameters
  • inv_depth (torch.Tensor [B,1,H,W]) – Inverse depth map

  • inv_depth_hat (torch.Tensor [B,1,H,W]) – Flipped inverse depth map produced from a flipped image

  • method (str) – Method that will be used to fuse the inverse depth maps

Returns

fused_inv_depth – Fused inverse depth map

Return type

torch.Tensor [B,1,H,W]

packnet_sfm.utils.depth.inv2depth(inv_depth)[source]

Invert an inverse depth map to produce a depth map

Parameters

inv_depth (torch.Tensor or list of torch.Tensor [B,1,H,W]) – Inverse depth map

Returns

depth – Depth map

Return type

torch.Tensor or list of torch.Tensor [B,1,H,W]

packnet_sfm.utils.depth.inv_depths_normalize(inv_depths)[source]

Inverse depth normalization

Parameters

inv_depths (list of torch.Tensor [B,1,H,W]) – Inverse depth maps

Returns

norm_inv_depths – Normalized inverse depth maps

Return type

list of torch.Tensor [B,1,H,W]

packnet_sfm.utils.depth.post_process_inv_depth(inv_depth, inv_depth_flipped, method='mean')[source]

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 – Post-processed inverse depth map

Return type

torch.Tensor [B,1,H,W]

packnet_sfm.utils.depth.viz_inv_depth(inv_depth, normalizer=None, percentile=95, colormap='plasma', filter_zeros=False)[source]

Converts an inverse depth map to a colormap for visualization.

Parameters
  • inv_depth (torch.Tensor [B,1,H,W]) – Inverse depth map to be converted

  • normalizer (float) – Value for inverse depth map normalization

  • percentile (float) – Percentile value for automatic normalization

  • colormap (str) – Colormap to be used

  • filter_zeros (bool) – If True, do not consider zero values during normalization

Returns

colormap – Colormap generated from the inverse depth map

Return type

np.array [H,W,3]