Kornia: Differentiable Computer Vision for PyTorch#
pip install kornia
Computer vision for
robotics & Spatial AI.
Why Kornia?
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.
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.
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.
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.
Cameras, homographies, Lie groups, RANSAC, depth-to-3D — every transform differentiable, so a pose is something you optimise.
Detect with KeyNet, DISK or ALIKED, match with LightGlue or LoFTR — classical SIFT and HardNet are there too.
Canny, Sobel, Gaussian, bilateral and morphology, batched and differentiable — usable as a layer or inside a loss.
One sampled transform applied to image, mask, boxes and keypoints alike — on the GPU, in 2D or 3D.
YuNet faces, RT-DETR objects, SAM masks, DexiNed edges — one line to build, weights on first use.
Lab, HSV, YUV and color maps; CLAHE, histogram equalisation, gamma and contrast — all trainable.
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
RANSACthat samples and scores on the device (the whole estimation withcompile=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