Kornia: Differentiable Computer Vision for PyTorch#

pip install kornia

Computer vision for
robotics & Spatial AI.

Why Kornia?

RandomGaussianBlur · batch 32 · I7 14700K Rtx 4090 CPU 1,584 img/s GPU 34,719 img/s · 21.9× faster items/s, eager mode — committed benchmark run, kornia 0.9.1 / torch 2.14.0+cu130
edges = kornia.filters.sobel(images.cuda())  # whole batch, one call

Same code, any device. Operators run wherever the tensor lives — no flags, no per-image loops.

See details

Two images progressively aligned by gradient descent

gradient descent on a homography

warped = warp_perspective(src, H, size) loss = (warped - dst).abs().mean() loss.backward(); optimizer.step()

repeat until aligned

Registration by pure gradient descent. Gradients flow through every operator, so vision ops can sit inside your model or your loss — no labels, no training data.

See details

PyTorch module → ONNX graph → one deployable file kornia module RgbToGrayscale() torch.onnx gray.onnx ONNXSequential + hf://…/Resize_512x512 runs on ONNX Runtime CPU CUDA no Python needed
torch.onnx.export(kornia.color.RgbToGrayscale(), (x,), "gray.onnx", dynamo=True)

Export once, run anywhere ONNX Runtime does — chained with Hub-hosted operators into one graph.

See details

Kornia is a non-profit building the stack for spatial AI — from differentiable vision for research to real-time perception on robots — maintained by a small team and funded by the people who use it.

Features#

1,100+ differentiable operators — functions and nn.Module layers, batched and device-agnostic — across geometry, feature matching, filtering, color, augmentation, losses and pretrained models. Six places to start below; the full map is the API reference.

Prefer to learn by example? Image matching, registration, stitching, denoising, face detection and visual prompting each walk through one task end to end — and Conventions & pitfalls is the one page to read before writing code.

When to use Kornia#

Kornia pays off where a hand-written version gets long or fragile, or where the alternatives leave the GPU.

  • Breadth — 1,100+ operators, most with no torchvision equivalent: camera and epipolar geometry, solvers, feature detection and matching, edges, morphology, Lab and Bayer color, losses and metrics.

  • Per-sample parameters in one batched call — a different blur sigma, rotation angle, warp matrix or brightness factor for every image, in one call; torchvision’s functional ops apply one parameter per call.

  • Batched minimal solvers and robust estimation — 7- and 8-point fundamental, 5-point essential, DLT homography and PnP solvers over whole batches of samples, and a RANSAC that samples and scores on the device (the whole estimation with compile=True, PyTorch ≥ 2.14).

  • Differentiable geometry — depth to 3D and back, camera models with lens distortion and Lie groups, with gradients through depth, pose and camera parameters.

  • Annotated augmentation — one sampled transform for images, masks, boxes and keypoints in 2D, and its inverse; on CUDA, with no avoidable host synchronization.

  • Local features on the GPU — SIFT, HardNet, DISK, ALIKED, XFeat, DeDoDe, LoFTR and LightGlue.

  • Compiles and exports — nearly all probed operator configurations run under torch.compile; see ONNX, torch.compile and torch.export support.

  • Fast on batched GPU tensors — in the published 0.9.1 and 0.9.2 benchmarks (RTX 4090, batch 32), many filters, warps, matching steps and metrics run about 10× to 70× faster in eager mode than per-image CPU OpenCV or scikit-image, and more under torch.compile. Results vary with hardware and workload; Performance shows every win and loss, including the small overlap with torchvision.

For a single fixed-parameter operation, such as one blur or one resize, a few lines of PyTorch or torchvision are just as good.

Support

Sponsor

Official Links

Twitter LinkedIn Newsletter (under construction)

Official libs

kornia kornia-rs