Jump to content

Connect Leeroopedia MCP: Equip your AI agents to search best practices, build plans, verify code, diagnose failures, and look up hyperparameter defaults.

Implementation:Kornia Kornia DexiNed Detector

From Leeroopedia


Knowledge Sources
Domains Vision Deep_Learning Edge_Detection
Last Updated 2026-02-09 15:00 GMT

Overview

Concrete tool for deep learning-based edge detection using the DexiNed architecture provided by Kornia.

Description

The DexiNed class implements the Dense Extreme Inception Network for edge detection. It processes RGB images through 6 dense blocks with progressive downsampling, skip connections, and upsampling blocks that restore the original resolution. The outputs from all 6 scales are concatenated and fused through a 1x1 convolution to produce the final edge map (B, 1, H, W). Pretrained weights trained on the BIPED dataset are available.

The higher-level EdgeDetector class wraps DexiNed with pre/post-processing (resizing, normalization, sigmoid).

Usage

Use DexiNed directly for raw edge logits, or EdgeDetectorBuilder.build() for a ready-to-use pipeline with preprocessing.

Code Reference

Source Location

  • Repository: kornia
  • File: kornia/filters/dexined.py (DexiNed L208-325), kornia/contrib/edge_detection.py (EdgeDetector L37-249)

Signature

DexiNed:

class DexiNed(nn.Module):
    def __init__(self, pretrained: bool) -> None

    def forward(self, x: torch.Tensor) -> torch.Tensor

EdgeDetector:

class EdgeDetector(ModelBase):
    def __init__(
        self,
        model: nn.Module,
        pre_processor: nn.Module,
        post_processor: nn.Module,
        name: Optional[str] = None,
    ) -> None

EdgeDetectorBuilder:

EdgeDetectorBuilder.build(
    model_name="dexined",
    pretrained=True,
    image_size=352,
) -> EdgeDetector

Import

from kornia.filters import DexiNed
from kornia.contrib import EdgeDetector, EdgeDetectorBuilder

I/O Contract

Inputs

DexiNed forward parameters:

Name Type Required Description
x torch.Tensor Yes RGB image tensor of shape (B, 3, H, W)

EdgeDetector forward parameters:

Name Type Required Description
images list[torch.Tensor] Yes RGB images for edge detection

Outputs

DexiNed:

Name Type Description
output torch.Tensor Edge logits of shape (B, 1, H, W)

EdgeDetector:

Name Type Description
output torch.Tensor Processed edge maps (sigmoid-normalized)

Usage Examples

Using EdgeDetectorBuilder

from kornia.contrib import EdgeDetectorBuilder
import torch

# Build a ready-to-use edge detector
detector = EdgeDetectorBuilder.build(pretrained=True, image_size=352)

# Detect edges
img = torch.rand(1, 3, 480, 640)
edges = detector(img)  # (1, 1, 480, 640)

# Visualize
pil_images = detector.visualize(img, edges, output_type="pil")

Direct DexiNed Usage

import torch
from kornia.filters import DexiNed

# Load DexiNed with pretrained weights
model = DexiNed(pretrained=True).eval()

# Run inference
img = torch.rand(1, 3, 352, 352)
with torch.no_grad():
    logits = model(img)  # (1, 1, 352, 352)

# Apply sigmoid for normalized edge map
edges = torch.sigmoid(logits)

Related Pages

Implements Principle

Page Connections

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