{"id":2559,"library":"kornia","title":"Kornia","description":"Kornia is an open-source differentiable computer vision library built on PyTorch, providing a rich set of differentiable image processing and geometric vision algorithms. It seamlessly integrates into AI workflows for tasks like image transformations, augmentations, and AI-driven image processing. Currently at version 0.8.2, Kornia is actively maintained with regular updates and is shifting towards end-to-end vision models.","status":"active","version":"0.8.2","language":"en","source_language":"en","source_url":"https://github.com/kornia/kornia","tags":["computer-vision","pytorch","deep-learning","image-processing","augmentation","spatial-ai","differentiable"],"install":[{"cmd":"pip install kornia","lang":"bash","label":"Install stable version"}],"dependencies":[{"reason":"Kornia is built on top of PyTorch, requiring a compatible PyTorch installation (>=2.0.0).","package":"torch","optional":false},{"reason":"Required for some advanced I/O functionalities, such as `kornia.io.load_image`, which uses Rust-based low-level computer vision operations.","package":"kornia_rs","optional":true},{"reason":"Dependency for certain internal packaging utilities.","package":"packaging","optional":true}],"imports":[{"note":"Standard alias for Kornia.","symbol":"kornia","correct":"import kornia as K"},{"note":"Most functionalities are within Kornia's submodules, like `augmentation`.","wrong":"from kornia import AugmentationSequential","symbol":"AugmentationSequential","correct":"from kornia.augmentation import AugmentationSequential"},{"note":"Color conversions are found in the `kornia.color` submodule.","wrong":"from kornia import rgb_to_grayscale","symbol":"rgb_to_grayscale","correct":"from kornia.color import rgb_to_grayscale"}],"quickstart":{"code":"import torch\nimport kornia as K\nimport numpy as np\nfrom PIL import Image\nimport matplotlib.pyplot as plt\n\n# Simulate loading an image or create a dummy tensor\n# In a real scenario, replace this with actual image loading (e.g., with Pillow/OpenCV)\n# and conversion using K.image_to_tensor.\n# Example with a dummy tensor:\nimage_tensor = torch.rand(1, 3, 256, 256, dtype=torch.float32)\n\n# Convert image to grayscale\ngrayscale_tensor = K.color.rgb_to_grayscale(image_tensor)\n\n# Apply a Gaussian blur\nblurred_tensor = K.filters.gaussian_blur2d(grayscale_tensor, kernel_size=(7, 7), sigma=(1.5, 1.5))\n\nprint(f\"Original image shape: {image_tensor.shape}\")\nprint(f\"Grayscale image shape: {grayscale_tensor.shape}\")\nprint(f\"Blurred image shape: {blurred_tensor.shape}\")\n\n# --- Optional: Visualization (requires matplotlib and numpy) ---\n# Convert tensors to NumPy arrays for display\n# You might need to detach from GPU and move to CPU if applicable:\n# grayscale_np = K.tensor_to_image(grayscale_tensor.detach().cpu())\n# blurred_np = K.tensor_to_image(blurred_tensor.detach().cpu())\n\n# fig, axs = plt.subplots(1, 2, figsize=(10, 5))\n# axs[0].imshow(grayscale_np)\n# axs[0].set_title('Grayscale Image')\n# axs[0].axis('off')\n# axs[1].imshow(blurred_np)\n# axs[1].set_title('Blurred Image')\n# axs[1].axis('off')\n# plt.show()","lang":"python","description":"This quickstart demonstrates basic Kornia usage: creating a dummy image tensor, converting it to grayscale, and applying a Gaussian blur filter. It highlights common imports and tensor operations. For actual image loading, libraries like Pillow or OpenCV are typically used, followed by `K.image_to_tensor`."},"warnings":[{"fix":"Refer to Kornia's documentation on coordinate conventions for keypoints and bounding boxes. Be mindful of how your input coordinates align with Kornia's assumed convention, especially when integrating with other libraries or performing precise geometric tasks.","message":"Kornia's keypoint and bounding box operations, while using float coordinates, often assume an underlying pixel-center (index-based) convention (e.g., pixel (3,4) center is at (3.5, 4.5)). This can lead to slight inaccuracies or off-by-one errors if precise sub-pixel float coordinates are expected, potentially affecting model accuracy or geometric transformations.","severity":"gotcha","affected_versions":"All versions"},{"fix":"Explicitly install `kornia_rs`: `pip install kornia_rs`.","message":"While `pip install kornia` is the primary installation, functionalities like `kornia.io.load_image` (for robust image I/O) internally rely on `kornia_rs`. If you encounter errors related to image loading, ensure `kornia_rs` is also installed (e.g., `pip install kornia kornia_rs`).","severity":"gotcha","affected_versions":"All versions"},{"fix":"Carefully define your augmentation parameters; use `nn.Parameter` for trainable parameters and regular `torch.Tensor` for fixed ones. Consult the differentiable data augmentation tutorials for examples.","message":"When using `kornia.augmentation` for differentiable data augmentation, distinguish between `torch.nn.Parameter` (for parameters that should be optimized/differentiated) and `torch.Tensor` (for static parameters). Incorrect usage can lead to unintended optimization behavior in meta-learning or differentiable augmentation pipelines.","severity":"gotcha","affected_versions":"All versions"},{"fix":"Ensure your PyTorch version is up-to-date and compatible with your Kornia version. For Kornia 0.8.x, ensure `torch>=2.0.0` is installed. Check the official Kornia documentation or `pyproject.toml` for precise `torch` version requirements for your specific Kornia version.","message":"Kornia continuously evolves. Older versions of PyTorch might not be compatible with the latest Kornia releases. Specifically, Kornia 0.8.x requires PyTorch >=2.0.0.","severity":"breaking","affected_versions":"<0.8.0 with PyTorch <2.0.0"}],"env_vars":null,"last_verified":"2026-04-10T00:00:00.000Z","next_check":"2026-07-09T00:00:00.000Z"}