Kornia: Differentiable Computer Vision That Actually Fits Your PyTorch Pipeline
You're building a vision model in PyTorch, and you need to do something slightly unusual—estimate a fundamental matrix across a batch of image pairs, or apply a different blur strength to every image in your tensor. You reach for torchvision, and it's not there. So you write it yourself, and suddenly you're maintaining a fragile pile of custom CUDA-friendly code that breaks the moment your batch shape changes. Kornia is the library that fills that gap.
What It Does
Kornia is a differentiable computer vision library built on top of PyTorch. It provides 1,200+ public operators spanning image processing, geometric vision, feature detection and matching, camera models, epipolar geometry, minimal solvers, RANSAC, morphology, color spaces, and image losses and metrics. Everything is designed to slot into your existing AI workflows with batch transformations, auto-differentiation, and GPU acceleration working out of the box.
The core idea is that these operations are differentiable and batched. You're not calling a CPU-bound preprocessing step before your model—you're calling operators that live inside the same tensor graph as everything else. That means gradients flow through your image transformations, and your whole pipeline runs on the GPU (or MPS) without bouncing back to the host.
Why It's Cool
-
The breadth is the real story. Most of Kornia's operators have no torchvision equivalent at all—camera models, epipolar geometry, minimal solvers, RANSAC, feature description and matching, edge detection, morphology, Lab and Bayer color conversions. torchvision overlaps mainly on the basics: resizing, cropping, flipping, color jitter, and blur. If your work touches geometry or calibration, Kornia is often the only game in town within the PyTorch ecosystem.
-
Per-sample parameters in a single batched call. This is the design decision that matters most day to day.
gaussian_blur2d(x, (9, 9), sigma)accepts a(B, 2)sigma tensor.rotatetakes a(B,)angle.warp_affineandwarp_perspectivetake(B, 2, 3)and(B, 3, 3)matrices, andadjust_brightnesstakes a(B,)factor. torchvision's functional ops apply one parameter per call, which means looping—and looping in Python over a batch is exactly the kind of thing that makes you question your career choices. -
Batched minimal solvers.
find_fundamental(x1, x2, method="7POINT")solves(B, 7, 2)samples and returns all real solutions in(B, 3, 3, 3), with zero matrices in unused slots. That's a genuinely non-trivial piece of numerical machinery exposed as a single differentiable call. -
Device validation without host sync. From version 0.9.1, a sigma tensor and the enhancement value checks (gamma, contrast, solarize) are validated on the device. A CUDA call—or an MPS call on PyTorch 2.13 and above—needs no host synchronization for them. Small detail, real performance consequence.
-
A stated direction toward rigor. The project describes itself as becoming the reference implementation and executable specification for differentiable computer vision in the PyTorch ecosystem—explicit conventions, conformance tests, and honest benchmarks over API growth. That's a refreshingly unglamorous goal, and it suggests the maintainers care about correctness as much as surface area.
How to Try It
Getting started is a single pip install:
pip install kornia
From there, the operators work like any PyTorch function:
import torch
import kornia
x = torch.rand(8, 3, 256, 256) # batch of 8 images
sigma = torch.rand(8, 2) * 2.0 # per-image blur strength
blurred = kornia.filters.gaussian_blur2d(x, (9, 9), sigma)
If you'd rather poke at it before installing anything, there's a browser playground at kornia.org/playground, plus a Colab notebook for a hello-world walkthrough. The docs live at kornia.readthedocs.io, and there are tutorials, a separate examples repository, and a Discord community if you get stuck.
The repository is at github.com/kornia/kornia—it's Apache 2.0 licensed.
Final Thoughts
Kornia isn't trying to replace torchvision for basic augmentation, and it doesn't pretend to. It's for the cases where you'd otherwise be writing your own geometry code or looping over a batch because the standard library only takes one parameter at a time. If your work involves camera calibration, feature matching, robust estimation, or per-sample image transformations, this is worth a serious look. The breadth is the draw; the batched, differentiable design is why you'll stay.