Implementation:Kornia Kornia Transpiler
| Knowledge Sources | |
|---|---|
| Domains | Vision, Interoperability, Framework_Conversion |
| Last Updated | 2026-02-09 15:00 GMT |
Overview
This module provides functions to transpile the entire Kornia library from PyTorch to other deep learning frameworks (JAX, NumPy, TensorFlow) using the Ivy transpilation engine.
Description
The transpiler module in the Kornia transpiler package exposes three functions: to_jax(), to_numpy(), and to_tensorflow(). Each function uses the Ivy library to lazily transpile the entire Kornia library from its native PyTorch implementation to the target framework. The transpilation occurs lazily, meaning the actual conversion of a given function or class happens only when it is first called or instantiated. This results in slower first-time execution but normal performance on subsequent calls. The module imports ivy from kornia.core.external.
Usage
Import these functions when you need to use Kornia operations in a JAX, NumPy, or TensorFlow environment. Note that NumPy transpilation does not support trainable modules.
Code Reference
Source Location
- Repository: Kornia
- File: kornia/transpiler/transpiler.py
- Lines: 1-117
Signature
def to_jax() -> ModuleType: ...
def to_numpy() -> ModuleType: ...
def to_tensorflow() -> ModuleType: ...
Import
from kornia.transpiler.transpiler import to_jax, to_numpy, to_tensorflow
I/O Contract
Inputs
| Name | Type | Required | Description |
|---|---|---|---|
| (none) | - | - | All three functions take no arguments. |
Outputs
| Function | Return Type | Description |
|---|---|---|
| to_jax | ModuleType | The Kornia library transpiled to JAX. |
| to_numpy | ModuleType | The Kornia library transpiled to NumPy. |
| to_tensorflow | ModuleType | The Kornia library transpiled to TensorFlow. |
Supported Targets
| Target | Function | Trainable Modules | Notes |
|---|---|---|---|
| JAX | to_jax() | Yes | Uses jax.numpy and jax.random. |
| NumPy | to_numpy() | No | Ivy does not currently support transpiling trainable modules to NumPy. |
| TensorFlow | to_tensorflow() | Yes | Uses tf.Tensor and tf.random. |
Usage Examples
# Transpile to JAX
import kornia
jax_kornia = kornia.to_jax()
import jax
input_data = jax.random.normal(jax.random.key(42), shape=(2, 3, 4, 5))
gray = jax_kornia.color.gray.rgb_to_grayscale(input_data)
# Transpile to NumPy
np_kornia = kornia.to_numpy()
import numpy as np
input_data = np.random.normal(size=(2, 3, 4, 5))
gray = np_kornia.color.gray.rgb_to_grayscale(input_data)
# Transpile to TensorFlow
tf_kornia = kornia.to_tensorflow()
import tensorflow as tf
input_data = tf.random.normal((2, 3, 4, 5))
gray = tf_kornia.color.gray.rgb_to_grayscale(input_data)