Jump to content

Connect SuperML | Leeroopedia MCP: Equip your AI agents with best practices, code verification, and debugging knowledge. Powered by Leeroo — building Organizational Superintelligence. Contact us at founders@leeroo.com.

Implementation:Kornia Kornia Depth Smoothness Loss

From Leeroopedia


Knowledge Sources
Domains Vision, Loss_Functions
Last Updated 2026-02-09 15:00 GMT

Overview

Inverse Depth Smoothness Loss computes an image-aware smoothness loss on inverse depth maps, penalizing depth discontinuities in regions where the image is smooth.

Description

The image-aware inverse depth smoothness loss encourages smooth depth predictions while preserving edges that are present in the corresponding image. It works by computing the gradients of the inverse depth map and weighting them by the exponential of the negative image gradients.

The mathematical formulation is:

loss=|xdij|exIij+|ydij|eyIij

Where d is the inverse depth map and I is the corresponding image. The image gradient term acts as an edge-aware weighting: in areas where the image has strong edges, the depth smoothness penalty is reduced, allowing depth discontinuities to align with image edges.

This loss is inspired by the implementation from TensorFlow's struct2depth model.

Usage

Import this loss for monocular depth estimation and self-supervised depth prediction tasks. It is commonly used alongside photometric losses in self-supervised monocular depth estimation pipelines to regularize the predicted depth maps.

Code Reference

Source Location

Signature

def inverse_depth_smoothness_loss(
    idepth: torch.Tensor,
    image: torch.Tensor,
) -> torch.Tensor: ...

class InverseDepthSmoothnessLoss(nn.Module):
    def forward(self, idepth: torch.Tensor, image: torch.Tensor) -> torch.Tensor: ...

Import

from kornia.losses import InverseDepthSmoothnessLoss
from kornia.losses import inverse_depth_smoothness_loss

I/O Contract

Inputs

Name Type Required Description
idepth torch.Tensor Yes Inverse depth tensor with shape (N, 1, H, W)
image torch.Tensor Yes Input image tensor with shape (N, 3, H, W); must share spatial dimensions and device with idepth

Outputs

Name Type Description
loss torch.Tensor Scalar loss value representing the mean image-aware depth smoothness

Usage Examples

import torch
from kornia.losses import InverseDepthSmoothnessLoss

# Create sample inverse depth and image tensors
idepth = torch.rand(1, 1, 4, 5)
image = torch.rand(1, 3, 4, 5)

# Using the module API
smooth = InverseDepthSmoothnessLoss()
loss = smooth(idepth, image)

# Using the functional API
from kornia.losses import inverse_depth_smoothness_loss
loss = inverse_depth_smoothness_loss(idepth, image)

Related Pages

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment