Adhering to API standards: Kornia, a library with over 1200 micro-operators, aims to be the visual standard solution within the PyTorch ecosystem.

Adhering to API standards: Kornia, a library with over 1200 micro-operators, aims to be the visual standard solution within the PyTorch ecosystem.

1 week ago
duguying
5 views
Source: GitHub

Kornia, a PyTorch-compatible visual library, is transitioning to an executable specification for operator positioning: featuring over 1200 operators, single-batch processing with per-sample parameters, and device-side validation without requiring host synchronization.

Related tags

#GitHub#Trending#PyTorch#计算机视觉

When an open-source library accumulates 11,824 stars, the typical path is to continue aggressively adding APIs. The computer vision library Kornia took a different approach: in its README, it formally announced that it would provide "differentiable computer vision and geometry with a reference implementation and executable specifications" within the PyTorch ecosystem—explicit conventions, consistency tests, and honest benchmark tests, prioritizing these over simply increasing the number of APIs. This Python project has recently returned to trending on GitHub with an increase of 101 stars per day.

Another selling point is its focus on engineering efficiency: Kornia supports passing parameters for each sample in a single batch processing call. For example, the `gaussian_blur2d(x, (9, 9), sigma)` function can have `sigma` as a (B, 2) tensor, while `rotate` accepts an angle tensor of shape (B,), and functions like `warp_affine` and `warp_perspective` accept matrices of shapes (B, 2, 3) or (B, 3, 3)—whereas torchvision's functional operators can only handle a single set of parameters per call, requiring developers to write loops to apply different parameters to each image in the batch.

Starting from version 0.9.1, validation checks for tensors like `sigma` and parameters such as gamma, contrast, and solarize are performed directly on the device, eliminating the need to synchronize back to the host (including CUDA calls and MPS calls in PyTorch ≥ 2.13).

The benefits of batch processing are even more apparent in robust estimation: `find_fundamental(x1, x2, method="7POINT")` can directly process (B, 7, 2) samples and returns a (B, 3, 3, 3) tensor containing all real solutions, with unused slots filled with zero matrices.

What Do "Executable Specifications" Mean?

In traditional computer vision libraries, solutions for a rotation matrix and a fundamental matrix are scattered across their respective documentation, often with minor inconsistencies between implementations. Kornia's ambition is to explicitly define these conventions: code as specification, tests as standards, and benchmark tests that are free from bias. For teams working on SLAM, 3D reconstruction, data augmentation, or any other AI task requiring geometric vision, this means they can confidently hand over the geometric aspects of their work to the library without worrying about "hand-written versions becoming fragile."

With its support for batch transformations, automatic differentiation, and GPU acceleration, Kornia is easy to install with just pip install kornia. The official website also provides a Playground, Colab tutorials, and comprehensive documentation. If your workflow involves image enhancement or geometric computation, it's worth adding this layer on top of torchvision.

Repository: https://github.com/kornia/kornia

More News

Want to see more quality content?

Browse all news