def calculate_depth_loss(est_depths, gt_depths, loss_type="l1"):
    """Calculate loss between estimated depthmap and GT depthmap

    Args:
        est_depths: [B,1,H,W]
        gt_depths: [B,1,H,W]
        loss_type: Choose loss type from ['l1','l2']
    """
    assert est_depths.dim() == gt_depths.dim(), "inconsistent dimensions"
    assert loss_type in ["l1", "l2"], "loss_type should be l1/l2"

    valid_mask = (gt_depths > 0).detach()
    diff = est_depths - gt_depths

    if loss_type == "l1":
        return diff[valid_mask].abs().mean()
    elif loss_type == "l2":
        return (diff[valid_mask] ** 2).mean()