Exemplo n.º 1
0
def compute_pairwise_loss(tgt_img, ref_img, tgt_depth, ref_depth, pose,
                          intrinsic, with_ssim, with_mask, with_auto_mask,
                          padding_mode):

    ref_img_warped, valid_mask, projected_depth, computed_depth = inverse_warp2(
        ref_img, tgt_depth, ref_depth, pose, intrinsic, padding_mode)

    diff_img = (tgt_img - ref_img_warped).abs().clamp(0, 1)

    diff_depth = ((computed_depth - projected_depth).abs() /
                  (computed_depth + projected_depth)).clamp(0, 1)

    if with_auto_mask == True:
        auto_mask = (diff_img.mean(dim=1, keepdim=True) <
                     (tgt_img - ref_img).abs().mean(
                         dim=1, keepdim=True)).float() * valid_mask
        valid_mask = auto_mask

    if with_ssim == True:
        ssim_map = compute_ssim_loss(tgt_img, ref_img_warped)
        diff_img = (0.15 * diff_img + 0.85 * ssim_map)

    if with_mask == True:
        weight_mask = (1 - diff_depth)
        diff_img = diff_img * weight_mask

    # compute all loss
    reconstruction_loss = mean_on_mask(diff_img, valid_mask)
    geometry_consistency_loss = mean_on_mask(diff_depth, valid_mask)

    return reconstruction_loss, geometry_consistency_loss
Exemplo n.º 2
0
def compute_pairwise_loss(tgt_img,
                          ref_img,
                          tgt_depth,
                          ref_depth,
                          pose,
                          with_mask,
                          intrinsic,
                          with_ssim,
                          rotation_mode='euler',
                          padding_mode='zeros'):

    ref_img_warped, valid_mask, projected_depth, computed_depth = inverse_warp2(
        ref_img, tgt_depth, ref_depth, pose, intrinsic, rotation_mode,
        padding_mode)

    diff_img = (tgt_img - ref_img_warped).abs() * valid_mask

    diff_depth = (
        (computed_depth - projected_depth).abs() /
        (computed_depth + projected_depth).abs()).clamp(0, 1) * valid_mask

    if with_ssim == True:
        ssim_map = (0.5 * (1 - ssim(tgt_img, ref_img_warped))).clamp(
            0, 1) * valid_mask
        diff_img = (0.15 * diff_img + 0.85 * ssim_map) * valid_mask

    if with_mask == True:
        weight_mask = (1 - diff_depth) * valid_mask
        diff_img = diff_img * weight_mask

    # compute loss
    reconstruction_loss = mean_on_mask(diff_img, valid_mask)
    geometry_consistency_loss = mean_on_mask(diff_depth, valid_mask)

    return reconstruction_loss, geometry_consistency_loss
Exemplo n.º 3
0
def compute_pairwise_loss(tgt_img, ref_img, tgt_depth, ref_depth, pose,
                          intrinsic, args):

    ref_img_warped, valid_mask, projected_depth, computed_depth = inverse_warp2(
        ref_img, tgt_depth, ref_depth, pose, intrinsic, args.padding_mode)

    diff_img = (tgt_img - ref_img_warped).abs()

    diff_depth = ((computed_depth - projected_depth).abs() /
                  (computed_depth + projected_depth).abs()).clamp(0, 1)

    if args.with_ssim:
        ssim_map = (0.5 * (1 - ssim(tgt_img, ref_img_warped))).clamp(0, 1)
        diff_img = (0.15 * diff_img + 0.85 * ssim_map)

    if args.with_mask:
        weight_mask = (1 - diff_depth)
        diff_img = diff_img * weight_mask

    # compute loss
    reconstruction_loss = mean_on_mask(diff_img, valid_mask)
    geometry_consistency_loss = mean_on_mask(diff_depth, valid_mask)

    return reconstruction_loss, geometry_consistency_loss