What is Kornia?

Kornia is a differentiable computer vision library for PyTorch.

It consists of a set of routines and differentiable modules to solve generic computer vision problems. At its core, the package uses PyTorch as its main backend both for efficiency and to take advantage of the reverse-mode auto-differentiation to define and compute the gradient of complex functions.

Overview

Inspired by OpenCV, this library is composed by a subset of packages containing operators that can be inserted within neural networks to train models to perform image transformations, epipolar geometry, depth estimation, and low level image processing such as filtering and edge detection that operate directly on tensors.

At a granular level, Kornia is a library that consists of the following components:

Component Description
kornia a Differentiable Computer Vision library like OpenCV, with strong GPU support
kornia.color a set of routines to perform color space conversions
kornia.contrib a compilation of user contrib and experimental operators
kornia.feature a module to perform feature detection
kornia.filters a module to perform image filtering and edge detection
kornia.geometry a geometric computer vision library to perform image transformations, 3D linear algebra and conversions using different camera models
kornia.losses a stack of loss functions to solve different vision tasks
kornia.utils image to tensor utilities and metrics for vision problems

 

How can I install Kornia?

Kornia can be installed in different ways, but depends on you to choose. Pip solution has versions on release status, and of course, git cloning from github gets you the latest pre-release / beta version of Kornia.

From pip, the easiest one:

pip install kornia

From source, if you want to maintain the source code and modify it:

git clone https://github.com/arraiyopensource/kornia
cd kornia
python setup.py install

From source using pip, a mix of the two:

pip install git+https://github.com/arraiyopensource/kornia

The moment of truth.

Does it work? Try it out by running this sample code:

import torch
import kornia

x_rad = kornia.pi * torch.rand(1, 3, 3)
x_deg = kornia.rad2deg(x_rad)

torch.allclose(x_rad, kornia.deg2rad(x_deg))  # True

Examples

Run kornia’s Jupyter notebooks examples to learn to use the library. Also I’ll be posting more tutorials on this blog as the library develops furthermore.

Cite

If you are using kornia in your research-related documents, it is recommended that you cite the poster.

@misc{Arraiy2018,
 author    = {E. Riba, M. Fathollahi, W. Chaney, E. Rublee and G. Bradski}
 title     = {torchgeometry: when PyTorch meets geometry},
 booktitle = {PyTorch Developer Conference},
 year      = {2018},
 url       = {https://drive.google.com/file/d/1xiao1Xj9WzjJ08YY_nYwsthE-wxfyfhG/view?usp=sharing}
}