Skip to content

🐍 Geometric Computer Vision Library for Spatial AI

docs: add a "Try in browser" badge linking APIs to the playground

Jian Shif5c979a54170
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 8e784a22b..4f43eb124 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -10,6 +10,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Added
+* API reference entries now carry a **Try in browser** badge that links a function, its
+ `nn.Module` counterpart or a browser model to its interactive page on the kornia.org
+ playground, so readers can run the operator on a sample image without installing anything.
+ The set of linked APIs is a snapshot of the playground in `docs/source/_playground_links.json`,
+ refreshed by `docs/generate_playground_links.py`. (#PR)
* Optional-dependency extras `kornia[onnx]` and `kornia[sd]` declare the third-party packages that
the ONNX and Stable-Diffusion-dissolving wrappers lazily import, and are documented on the
installation page. Missing-dependency errors now name the extra to install, and `dev` no longer
diff --git a/docs/generate_playground_links.py b/docs/generate_playground_links.py
new file mode 100644
index 000000000..45af16c70
--- /dev/null
+++ b/docs/generate_playground_links.py
@@ -0,0 +1,87 @@
+# Copyright 2018 Kornia Team
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+"""Refresh the map of kornia APIs that have an interactive page on the playground.
+
+The kornia.org playground publishes ``playground/registry.json`` (operators) and
+``playground/models/index.json`` (browser models). Each entry carries the fully-qualified kornia
+name and the slug of its page. This script turns those into a small
+``docs/source/_playground_links.json`` mapping ``<fully-qualified name> -> <page URL>`` that the
+docs build reads to add a "Try in browser" badge to the matching function, module and model.
+
+Run it whenever the playground gains or loses operators::
+
+ # from a local checkout of kornia.github.io
+ KORNIA_SITE=~/git/kornia.github.io python docs/generate_playground_links.py
+
+ # or straight from the published site
+ python docs/generate_playground_links.py
+
+The bundled snapshot keeps the docs build offline and reproducible; refreshing it is a deliberate,
+reviewable change rather than a network call at build time.
+"""
+
+from __future__ import annotations
+
+import json
+import os
+import sys
+import urllib.request
+from pathlib import Path
+from typing import Any
+
+BASE_URL = "https://kornia.org"
+HERE = Path(__file__).resolve().parent
+OUT = HERE / "source" / "_playground_links.json"
+
+# operators whose page only records that they are not exportable have nothing to run, so no badge
+RUNNABLE_STATUS = {"live", "frames"}
+
+
+def _load(name: str) -> Any:
+ """Read a playground JSON file from ``KORNIA_SITE`` if set, otherwise from the published site."""
+ site = os.environ.get("KORNIA_SITE")
+ if site:
+ path = Path(site).expanduser() / "playground" / name
+ return json.loads(path.read_text())
+ with urllib.request.urlopen(f"{BASE_URL}/playground/{name}", timeout=60) as response: # noqa: S310 - fixed https URL
+ return json.loads(response.read())
+
+
+def build_map() -> dict[str, str]:
+ links: dict[str, str] = {}
+ registry = _load("registry.json")
+ for op in registry.get("ops", []):
+ if op.get("status") not in RUNNABLE_STATUS or op.get("alias_of"):
+ continue
+ url = f"{BASE_URL}/playground/ops/{op['slug']}/"
+ links[op["id"]] = url
+ module_name = op.get("module_name") # the nn.Module counterpart shares the page
+ if module_name:
+ links[module_name] = url
+ models = _load("models/index.json")
+ for model in models.get("models", models):
+ links[model["id"]] = f"{BASE_URL}/playground/models/{model['slug']}/"
+ return dict(sorted(links.items()))
+
+
+def main() -> None:
+ links = build_map()
+ if not links:
+ sys.exit("no playground links were produced; check KORNIA_SITE or the network")
+ OUT.write_text(json.dumps(links, indent=2, ensure_ascii=False) + "\n")
+ print(f"wrote {OUT.relative_to(HERE.parent)} with {len(links)} entries")
+
+
+if __name__ == "__main__":
+ main()
diff --git a/docs/source/_playground_links.json b/docs/source/_playground_links.json
new file mode 100644
index 000000000..6588ba9c9
--- /dev/null
+++ b/docs/source/_playground_links.json
@@ -0,0 +1,247 @@
+{
+ "kornia.augmentation.CenterCrop": "https://kornia.org/playground/ops/augmentation-CenterCrop/",
+ "kornia.augmentation.CenterCrop3D": "https://kornia.org/playground/ops/augmentation-CenterCrop3D/",
+ "kornia.augmentation.ColorJiggle": "https://kornia.org/playground/ops/augmentation-ColorJiggle/",
+ "kornia.augmentation.ColorJitter": "https://kornia.org/playground/ops/augmentation-ColorJitter/",
+ "kornia.augmentation.Denormalize": "https://kornia.org/playground/ops/augmentation-Denormalize/",
+ "kornia.augmentation.LongestMaxSize": "https://kornia.org/playground/ops/augmentation-LongestMaxSize/",
+ "kornia.augmentation.Normalize": "https://kornia.org/playground/ops/augmentation-Normalize/",
+ "kornia.augmentation.PadTo": "https://kornia.org/playground/ops/augmentation-PadTo/",
+ "kornia.augmentation.PatchMix": "https://kornia.org/playground/ops/augmentation-PatchMix/",
+ "kornia.augmentation.RandomAffine": "https://kornia.org/playground/ops/augmentation-RandomAffine/",
+ "kornia.augmentation.RandomAffine3D": "https://kornia.org/playground/ops/augmentation-RandomAffine3D/",
+ "kornia.augmentation.RandomAutoContrast": "https://kornia.org/playground/ops/augmentation-RandomAutoContrast/",
+ "kornia.augmentation.RandomBoxBlur": "https://kornia.org/playground/ops/augmentation-RandomBoxBlur/",
+ "kornia.augmentation.RandomBrightness": "https://kornia.org/playground/ops/augmentation-RandomBrightness/",
+ "kornia.augmentation.RandomChannelDropout": "https://kornia.org/playground/ops/augmentation-RandomChannelDropout/",
+ "kornia.augmentation.RandomChannelShuffle": "https://kornia.org/playground/ops/augmentation-RandomChannelShuffle/",
+ "kornia.augmentation.RandomContrast": "https://kornia.org/playground/ops/augmentation-RandomContrast/",
+ "kornia.augmentation.RandomCrop": "https://kornia.org/playground/ops/augmentation-RandomCrop/",
+ "kornia.augmentation.RandomCrop3D": "https://kornia.org/playground/ops/augmentation-RandomCrop3D/",
+ "kornia.augmentation.RandomCutMixV2": "https://kornia.org/playground/ops/augmentation-RandomCutMixV2/",
+ "kornia.augmentation.RandomDepthicalFlip3D": "https://kornia.org/playground/ops/augmentation-RandomDepthicalFlip3D/",
+ "kornia.augmentation.RandomElasticTransform": "https://kornia.org/playground/ops/augmentation-RandomElasticTransform/",
+ "kornia.augmentation.RandomEqualize": "https://kornia.org/playground/ops/augmentation-RandomEqualize/",
+ "kornia.augmentation.RandomEqualize3D": "https://kornia.org/playground/ops/augmentation-RandomEqualize3D/",
+ "kornia.augmentation.RandomErasing": "https://kornia.org/playground/ops/augmentation-RandomErasing/",
+ "kornia.augmentation.RandomFisheye": "https://kornia.org/playground/ops/augmentation-RandomFisheye/",
+ "kornia.augmentation.RandomGamma": "https://kornia.org/playground/ops/augmentation-RandomGamma/",
+ "kornia.augmentation.RandomGaussianBlur": "https://kornia.org/playground/ops/augmentation-RandomGaussianBlur/",
+ "kornia.augmentation.RandomGaussianIllumination": "https://kornia.org/playground/ops/augmentation-RandomGaussianIllumination/",
+ "kornia.augmentation.RandomGaussianNoise": "https://kornia.org/playground/ops/augmentation-RandomGaussianNoise/",
+ "kornia.augmentation.RandomGrayscale": "https://kornia.org/playground/ops/augmentation-RandomGrayscale/",
+ "kornia.augmentation.RandomHorizontalFlip": "https://kornia.org/playground/ops/augmentation-RandomHorizontalFlip/",
+ "kornia.augmentation.RandomHorizontalFlip3D": "https://kornia.org/playground/ops/augmentation-RandomHorizontalFlip3D/",
+ "kornia.augmentation.RandomHue": "https://kornia.org/playground/ops/augmentation-RandomHue/",
+ "kornia.augmentation.RandomInvert": "https://kornia.org/playground/ops/augmentation-RandomInvert/",
+ "kornia.augmentation.RandomJigsaw": "https://kornia.org/playground/ops/augmentation-RandomJigsaw/",
+ "kornia.augmentation.RandomLinearCornerIllumination": "https://kornia.org/playground/ops/augmentation-RandomLinearCornerIllumination/",
+ "kornia.augmentation.RandomLinearIllumination": "https://kornia.org/playground/ops/augmentation-RandomLinearIllumination/",
+ "kornia.augmentation.RandomMedianBlur": "https://kornia.org/playground/ops/augmentation-RandomMedianBlur/",
+ "kornia.augmentation.RandomMixUpV2": "https://kornia.org/playground/ops/augmentation-RandomMixUpV2/",
+ "kornia.augmentation.RandomMosaic": "https://kornia.org/playground/ops/augmentation-RandomMosaic/",
+ "kornia.augmentation.RandomMotionBlur": "https://kornia.org/playground/ops/augmentation-RandomMotionBlur/",
+ "kornia.augmentation.RandomMotionBlur3D": "https://kornia.org/playground/ops/augmentation-RandomMotionBlur3D/",
+ "kornia.augmentation.RandomPerspective": "https://kornia.org/playground/ops/augmentation-RandomPerspective/",
+ "kornia.augmentation.RandomPerspective3D": "https://kornia.org/playground/ops/augmentation-RandomPerspective3D/",
+ "kornia.augmentation.RandomPlanckianJitter": "https://kornia.org/playground/ops/augmentation-RandomPlanckianJitter/",
+ "kornia.augmentation.RandomPlasmaBrightness": "https://kornia.org/playground/ops/augmentation-RandomPlasmaBrightness/",
+ "kornia.augmentation.RandomPlasmaContrast": "https://kornia.org/playground/ops/augmentation-RandomPlasmaContrast/",
+ "kornia.augmentation.RandomPlasmaShadow": "https://kornia.org/playground/ops/augmentation-RandomPlasmaShadow/",
+ "kornia.augmentation.RandomPosterize": "https://kornia.org/playground/ops/augmentation-RandomPosterize/",
+ "kornia.augmentation.RandomRGBShift": "https://kornia.org/playground/ops/augmentation-RandomRGBShift/",
+ "kornia.augmentation.RandomRain": "https://kornia.org/playground/ops/augmentation-RandomRain/",
+ "kornia.augmentation.RandomResizedCrop": "https://kornia.org/playground/ops/augmentation-RandomResizedCrop/",
+ "kornia.augmentation.RandomRotation": "https://kornia.org/playground/ops/augmentation-RandomRotation/",
+ "kornia.augmentation.RandomRotation3D": "https://kornia.org/playground/ops/augmentation-RandomRotation3D/",
+ "kornia.augmentation.RandomRotation90": "https://kornia.org/playground/ops/augmentation-RandomRotation90/",
+ "kornia.augmentation.RandomSaltAndPepperNoise": "https://kornia.org/playground/ops/augmentation-RandomSaltAndPepperNoise/",
+ "kornia.augmentation.RandomSaturation": "https://kornia.org/playground/ops/augmentation-RandomSaturation/",
+ "kornia.augmentation.RandomSharpness": "https://kornia.org/playground/ops/augmentation-RandomSharpness/",
+ "kornia.augmentation.RandomShear": "https://kornia.org/playground/ops/augmentation-RandomShear/",
+ "kornia.augmentation.RandomSnow": "https://kornia.org/playground/ops/augmentation-RandomSnow/",
+ "kornia.augmentation.RandomSolarize": "https://kornia.org/playground/ops/augmentation-RandomSolarize/",
+ "kornia.augmentation.RandomThinPlateSpline": "https://kornia.org/playground/ops/augmentation-RandomThinPlateSpline/",
+ "kornia.augmentation.RandomTranslate": "https://kornia.org/playground/ops/augmentation-RandomTranslate/",
+ "kornia.augmentation.RandomVerticalFlip": "https://kornia.org/playground/ops/augmentation-RandomVerticalFlip/",
+ "kornia.augmentation.RandomVerticalFlip3D": "https://kornia.org/playground/ops/augmentation-RandomVerticalFlip3D/",
+ "kornia.augmentation.Resize": "https://kornia.org/playground/ops/augmentation-Resize/",
+ "kornia.augmentation.SmallestMaxSize": "https://kornia.org/playground/ops/augmentation-SmallestMaxSize/",
+ "kornia.color.ApplyColorMap": "https://kornia.org/playground/ops/color-apply_colormap/",
+ "kornia.color.BgrToRgb": "https://kornia.org/playground/ops/color-bgr_to_rgb/",
+ "kornia.color.GrayscaleToRgb": "https://kornia.org/playground/ops/color-grayscale_to_rgb/",
+ "kornia.color.LinearRgbToRgb": "https://kornia.org/playground/ops/color-linear_rgb_to_rgb/",
+ "kornia.color.RgbToBgr": "https://kornia.org/playground/ops/color-rgb_to_bgr/",
+ "kornia.color.RgbToGrayscale": "https://kornia.org/playground/ops/color-rgb_to_grayscale/",
+ "kornia.color.RgbToHls": "https://kornia.org/playground/ops/color-rgb_to_hls/",
+ "kornia.color.RgbToHsv": "https://kornia.org/playground/ops/color-rgb_to_hsv/",
+ "kornia.color.RgbToLab": "https://kornia.org/playground/ops/color-rgb_to_lab/",
+ "kornia.color.RgbToLinearRgb": "https://kornia.org/playground/ops/color-rgb_to_linear_rgb/",
+ "kornia.color.RgbToLuv": "https://kornia.org/playground/ops/color-rgb_to_luv/",
+ "kornia.color.RgbToRaw": "https://kornia.org/playground/ops/color-rgb_to_raw/",
+ "kornia.color.RgbToRgba": "https://kornia.org/playground/ops/color-rgb_to_rgba/",
+ "kornia.color.RgbToXyz": "https://kornia.org/playground/ops/color-rgb_to_xyz/",
+ "kornia.color.RgbToYcbcr": "https://kornia.org/playground/ops/color-rgb_to_ycbcr/",
+ "kornia.color.RgbToYuv": "https://kornia.org/playground/ops/color-rgb_to_yuv/",
+ "kornia.color.Sepia": "https://kornia.org/playground/ops/color-sepia/",
+ "kornia.color.apply_colormap": "https://kornia.org/playground/ops/color-apply_colormap/",
+ "kornia.color.bgr_to_grayscale": "https://kornia.org/playground/ops/color-bgr_to_grayscale/",
+ "kornia.color.bgr_to_rgb": "https://kornia.org/playground/ops/color-bgr_to_rgb/",
+ "kornia.color.grayscale_to_rgb": "https://kornia.org/playground/ops/color-grayscale_to_rgb/",
+ "kornia.color.hls_to_rgb": "https://kornia.org/playground/ops/color-hls_to_rgb/",
+ "kornia.color.hsv_to_rgb": "https://kornia.org/playground/ops/color-hsv_to_rgb/",
+ "kornia.color.lab_to_rgb": "https://kornia.org/playground/ops/color-lab_to_rgb/",
+ "kornia.color.linear_rgb_to_rgb": "https://kornia.org/playground/ops/color-linear_rgb_to_rgb/",
+ "kornia.color.luv_to_rgb": "https://kornia.org/playground/ops/color-luv_to_rgb/",
+ "kornia.color.rgb_to_bgr": "https://kornia.org/playground/ops/color-rgb_to_bgr/",
+ "kornia.color.rgb_to_grayscale": "https://kornia.org/playground/ops/color-rgb_to_grayscale/",
+ "kornia.color.rgb_to_hls": "https://kornia.org/playground/ops/color-rgb_to_hls/",
+ "kornia.color.rgb_to_hsv": "https://kornia.org/playground/ops/color-rgb_to_hsv/",
+ "kornia.color.rgb_to_lab": "https://kornia.org/playground/ops/color-rgb_to_lab/",
+ "kornia.color.rgb_to_linear_rgb": "https://kornia.org/playground/ops/color-rgb_to_linear_rgb/",
+ "kornia.color.rgb_to_luv": "https://kornia.org/playground/ops/color-rgb_to_luv/",
+ "kornia.color.rgb_to_raw": "https://kornia.org/playground/ops/color-rgb_to_raw/",
+ "kornia.color.rgb_to_rgba": "https://kornia.org/playground/ops/color-rgb_to_rgba/",
+ "kornia.color.rgb_to_xyz": "https://kornia.org/playground/ops/color-rgb_to_xyz/",
+ "kornia.color.rgb_to_y": "https://kornia.org/playground/ops/color-rgb_to_y/",
+ "kornia.color.rgb_to_ycbcr": "https://kornia.org/playground/ops/color-rgb_to_ycbcr/",
+ "kornia.color.rgb_to_yuv": "https://kornia.org/playground/ops/color-rgb_to_yuv/",
+ "kornia.color.sepia": "https://kornia.org/playground/ops/color-sepia/",
+ "kornia.color.xyz_to_rgb": "https://kornia.org/playground/ops/color-xyz_to_rgb/",
+ "kornia.color.ycbcr_to_rgb": "https://kornia.org/playground/ops/color-ycbcr_to_rgb/",
+ "kornia.color.yuv_to_rgb": "https://kornia.org/playground/ops/color-yuv_to_rgb/",
+ "kornia.contrib.EdgeDetectorBuilder": "https://kornia.org/playground/models/edges-dexined/",
+ "kornia.contrib.FaceDetector": "https://kornia.org/playground/models/face-detection-yunet/",
+ "kornia.contrib.connected_components": "https://kornia.org/playground/ops/contrib-connected_components/",
+ "kornia.contrib.distance_transform": "https://kornia.org/playground/ops/contrib-distance_transform/",
+ "kornia.contrib.object_detection.RTDETRDetectorBuilder": "https://kornia.org/playground/models/object-detection-rtdetr/",
+ "kornia.enhance.AddWeighted": "https://kornia.org/playground/ops/enhance-add_weighted/",
+ "kornia.enhance.AdjustBrightness": "https://kornia.org/playground/ops/enhance-adjust_brightness/",
+ "kornia.enhance.AdjustBrightnessAccumulative": "https://kornia.org/playground/ops/enhance-adjust_brightness_accumulative/",
+ "kornia.enhance.AdjustContrast": "https://kornia.org/playground/ops/enhance-adjust_contrast/",
+ "kornia.enhance.AdjustContrastWithMeanSubtraction": "https://kornia.org/playground/ops/enhance-adjust_contrast_with_mean_subtraction/",
+ "kornia.enhance.AdjustGamma": "https://kornia.org/playground/ops/enhance-adjust_gamma/",
+ "kornia.enhance.AdjustHue": "https://kornia.org/playground/ops/enhance-adjust_hue/",
+ "kornia.enhance.AdjustLog": "https://kornia.org/playground/ops/enhance-adjust_log/",
+ "kornia.enhance.AdjustSaturation": "https://kornia.org/playground/ops/enhance-adjust_saturation/",
+ "kornia.enhance.AdjustSaturationWithGraySubtraction": "https://kornia.org/playground/ops/enhance-adjust_saturation_with_gray_subtraction/",
+ "kornia.enhance.AdjustSigmoid": "https://kornia.org/playground/ops/enhance-adjust_sigmoid/",
+ "kornia.enhance.IntegralImage": "https://kornia.org/playground/ops/enhance-integral_image/",
+ "kornia.enhance.Invert": "https://kornia.org/playground/ops/enhance-invert/",
+ "kornia.enhance.JPEGCodecDifferentiable": "https://kornia.org/playground/ops/enhance-jpeg_codec_differentiable/",
+ "kornia.enhance.Normalize": "https://kornia.org/playground/ops/enhance-normalize/",
+ "kornia.enhance.Threshold": "https://kornia.org/playground/ops/enhance-threshold/",
+ "kornia.enhance.add_weighted": "https://kornia.org/playground/ops/enhance-add_weighted/",
+ "kornia.enhance.adjust_brightness": "https://kornia.org/playground/ops/enhance-adjust_brightness/",
+ "kornia.enhance.adjust_brightness_accumulative": "https://kornia.org/playground/ops/enhance-adjust_brightness_accumulative/",
+ "kornia.enhance.adjust_contrast": "https://kornia.org/playground/ops/enhance-adjust_contrast/",
+ "kornia.enhance.adjust_contrast_with_mean_subtraction": "https://kornia.org/playground/ops/enhance-adjust_contrast_with_mean_subtraction/",
+ "kornia.enhance.adjust_gamma": "https://kornia.org/playground/ops/enhance-adjust_gamma/",
+ "kornia.enhance.adjust_hue": "https://kornia.org/playground/ops/enhance-adjust_hue/",
+ "kornia.enhance.adjust_log": "https://kornia.org/playground/ops/enhance-adjust_log/",
+ "kornia.enhance.adjust_saturation": "https://kornia.org/playground/ops/enhance-adjust_saturation/",
+ "kornia.enhance.adjust_saturation_with_gray_subtraction": "https://kornia.org/playground/ops/enhance-adjust_saturation_with_gray_subtraction/",
+ "kornia.enhance.adjust_sigmoid": "https://kornia.org/playground/ops/enhance-adjust_sigmoid/",
+ "kornia.enhance.equalize": "https://kornia.org/playground/ops/enhance-equalize/",
+ "kornia.enhance.equalize3d": "https://kornia.org/playground/ops/enhance-equalize3d/",
+ "kornia.enhance.equalize_clahe": "https://kornia.org/playground/ops/enhance-equalize_clahe/",
+ "kornia.enhance.integral_image": "https://kornia.org/playground/ops/enhance-integral_image/",
+ "kornia.enhance.invert": "https://kornia.org/playground/ops/enhance-invert/",
+ "kornia.enhance.jpeg_codec_differentiable": "https://kornia.org/playground/ops/enhance-jpeg_codec_differentiable/",
+ "kornia.enhance.normalize": "https://kornia.org/playground/ops/enhance-normalize/",
+ "kornia.enhance.normalize_min_max": "https://kornia.org/playground/ops/enhance-normalize_min_max/",
+ "kornia.enhance.posterize": "https://kornia.org/playground/ops/enhance-posterize/",
+ "kornia.enhance.sharpness": "https://kornia.org/playground/ops/enhance-sharpness/",
+ "kornia.enhance.shift_rgb": "https://kornia.org/playground/ops/enhance-shift_rgb/",
+ "kornia.enhance.solarize": "https://kornia.org/playground/ops/enhance-solarize/",
+ "kornia.enhance.threshold": "https://kornia.org/playground/ops/enhance-threshold/",
+ "kornia.feature.KeyNet+HardNet": "https://kornia.org/playground/models/local-features-keynet-hardnet/",
+ "kornia.feature.LoFTR": "https://kornia.org/playground/models/local-features-loftr/",
+ "kornia.feature.XFeat": "https://kornia.org/playground/models/local-features-xfeat/",
+ "kornia.feature.dog_response_single": "https://kornia.org/playground/ops/feature-dog_response_single/",
+ "kornia.feature.gftt_response": "https://kornia.org/playground/ops/feature-gftt_response/",
+ "kornia.feature.harris_response": "https://kornia.org/playground/ops/feature-harris_response/",
+ "kornia.feature.hessian_response": "https://kornia.org/playground/ops/feature-hessian_response/",
+ "kornia.filters.BilateralBlur": "https://kornia.org/playground/ops/filters-bilateral_blur/",
+ "kornia.filters.BlurPool2D": "https://kornia.org/playground/ops/filters-blur_pool2d/",
+ "kornia.filters.BoxBlur": "https://kornia.org/playground/ops/filters-box_blur/",
+ "kornia.filters.Canny": "https://kornia.org/playground/ops/filters-canny/",
+ "kornia.filters.EdgeAwareBlurPool2D": "https://kornia.org/playground/ops/filters-edge_aware_blur_pool2d/",
+ "kornia.filters.GaussianBlur2d": "https://kornia.org/playground/ops/filters-gaussian_blur2d/",
+ "kornia.filters.GuidedBlur": "https://kornia.org/playground/ops/filters-guided_blur/",
+ "kornia.filters.InRange": "https://kornia.org/playground/ops/filters-in_range/",
+ "kornia.filters.JointBilateralBlur": "https://kornia.org/playground/ops/filters-joint_bilateral_blur/",
+ "kornia.filters.Laplacian": "https://kornia.org/playground/ops/filters-laplacian/",
+ "kornia.filters.MaxBlurPool2D": "https://kornia.org/playground/ops/filters-max_blur_pool2d/",
+ "kornia.filters.MedianBlur": "https://kornia.org/playground/ops/filters-median_blur/",
+ "kornia.filters.MotionBlur": "https://kornia.org/playground/ops/filters-motion_blur/",
+ "kornia.filters.MotionBlur3D": "https://kornia.org/playground/ops/filters-motion_blur3d/",
+ "kornia.filters.Sobel": "https://kornia.org/playground/ops/filters-sobel/",
+ "kornia.filters.UnsharpMask": "https://kornia.org/playground/ops/filters-unsharp_mask/",
+ "kornia.filters.bilateral_blur": "https://kornia.org/playground/ops/filters-bilateral_blur/",
+ "kornia.filters.blur_pool2d": "https://kornia.org/playground/ops/filters-blur_pool2d/",
+ "kornia.filters.box_blur": "https://kornia.org/playground/ops/filters-box_blur/",
+ "kornia.filters.canny": "https://kornia.org/playground/ops/filters-canny/",
+ "kornia.filters.edge_aware_blur_pool2d": "https://kornia.org/playground/ops/filters-edge_aware_blur_pool2d/",
+ "kornia.filters.fft_conv": "https://kornia.org/playground/ops/filters-fft_conv/",
+ "kornia.filters.filter2d": "https://kornia.org/playground/ops/filters-filter2d/",
+ "kornia.filters.filter2d_separable": "https://kornia.org/playground/ops/filters-filter2d_separable/",
+ "kornia.filters.filter3d": "https://kornia.org/playground/ops/filters-filter3d/",
+ "kornia.filters.gaussian_blur2d": "https://kornia.org/playground/ops/filters-gaussian_blur2d/",
+ "kornia.filters.guided_blur": "https://kornia.org/playground/ops/filters-guided_blur/",
+ "kornia.filters.in_range": "https://kornia.org/playground/ops/filters-in_range/",
+ "kornia.filters.joint_bilateral_blur": "https://kornia.org/playground/ops/filters-joint_bilateral_blur/",
+ "kornia.filters.laplacian": "https://kornia.org/playground/ops/filters-laplacian/",
+ "kornia.filters.max_blur_pool2d": "https://kornia.org/playground/ops/filters-max_blur_pool2d/",
+ "kornia.filters.median_blur": "https://kornia.org/playground/ops/filters-median_blur/",
+ "kornia.filters.motion_blur": "https://kornia.org/playground/ops/filters-motion_blur/",
+ "kornia.filters.motion_blur3d": "https://kornia.org/playground/ops/filters-motion_blur3d/",
+ "kornia.filters.sobel": "https://kornia.org/playground/ops/filters-sobel/",
+ "kornia.filters.spatial_gradient": "https://kornia.org/playground/ops/filters-spatial_gradient/",
+ "kornia.filters.unsharp_mask": "https://kornia.org/playground/ops/filters-unsharp_mask/",
+ "kornia.geometry.subpix.nms2d": "https://kornia.org/playground/ops/geometry-subpix-nms2d/",
+ "kornia.geometry.subpix.spatial_softmax2d": "https://kornia.org/playground/ops/geometry-subpix-spatial_softmax2d/",
+ "kornia.geometry.transform.CenterCrop2D": "https://kornia.org/playground/ops/geometry-transform-center_crop/",
+ "kornia.geometry.transform.Hflip": "https://kornia.org/playground/ops/geometry-transform-hflip/",
+ "kornia.geometry.transform.PyrDown": "https://kornia.org/playground/ops/geometry-transform-pyrdown/",
+ "kornia.geometry.transform.PyrUp": "https://kornia.org/playground/ops/geometry-transform-pyrup/",
+ "kornia.geometry.transform.Rescale": "https://kornia.org/playground/ops/geometry-transform-rescale/",
+ "kornia.geometry.transform.Resize": "https://kornia.org/playground/ops/geometry-transform-resize/",
+ "kornia.geometry.transform.Rot180": "https://kornia.org/playground/ops/geometry-transform-rot180/",
+ "kornia.geometry.transform.Rotate": "https://kornia.org/playground/ops/geometry-transform-rotate/",
+ "kornia.geometry.transform.Scale": "https://kornia.org/playground/ops/geometry-transform-scale/",
+ "kornia.geometry.transform.Shear": "https://kornia.org/playground/ops/geometry-transform-shear/",
+ "kornia.geometry.transform.Translate": "https://kornia.org/playground/ops/geometry-transform-translate/",
+ "kornia.geometry.transform.Vflip": "https://kornia.org/playground/ops/geometry-transform-vflip/",
+ "kornia.geometry.transform.affine3d": "https://kornia.org/playground/ops/geometry-transform-affine3d/",
+ "kornia.geometry.transform.center_crop": "https://kornia.org/playground/ops/geometry-transform-center_crop/",
+ "kornia.geometry.transform.center_crop3d": "https://kornia.org/playground/ops/geometry-transform-center_crop3d/",
+ "kornia.geometry.transform.crop_and_resize3d": "https://kornia.org/playground/ops/geometry-transform-crop_and_resize3d/",
+ "kornia.geometry.transform.crop_by_boxes3d": "https://kornia.org/playground/ops/geometry-transform-crop_by_boxes3d/",
+ "kornia.geometry.transform.crop_by_indices": "https://kornia.org/playground/ops/geometry-transform-crop_by_indices/",
+ "kornia.geometry.transform.elastic_transform2d": "https://kornia.org/playground/ops/geometry-transform-elastic_transform2d/",
+ "kornia.geometry.transform.hflip": "https://kornia.org/playground/ops/geometry-transform-hflip/",
+ "kornia.geometry.transform.pyrdown": "https://kornia.org/playground/ops/geometry-transform-pyrdown/",
+ "kornia.geometry.transform.pyrup": "https://kornia.org/playground/ops/geometry-transform-pyrup/",
+ "kornia.geometry.transform.rescale": "https://kornia.org/playground/ops/geometry-transform-rescale/",
+ "kornia.geometry.transform.resize": "https://kornia.org/playground/ops/geometry-transform-resize/",
+ "kornia.geometry.transform.rot180": "https://kornia.org/playground/ops/geometry-transform-rot180/",
+ "kornia.geometry.transform.rotate": "https://kornia.org/playground/ops/geometry-transform-rotate/",
+ "kornia.geometry.transform.rotate3d": "https://kornia.org/playground/ops/geometry-transform-rotate3d/",
+ "kornia.geometry.transform.scale": "https://kornia.org/playground/ops/geometry-transform-scale/",
+ "kornia.geometry.transform.shear": "https://kornia.org/playground/ops/geometry-transform-shear/",
+ "kornia.geometry.transform.translate": "https://kornia.org/playground/ops/geometry-transform-translate/",
+ "kornia.geometry.transform.vflip": "https://kornia.org/playground/ops/geometry-transform-vflip/",
+ "kornia.geometry.transform.warp_affine3d": "https://kornia.org/playground/ops/geometry-transform-warp_affine3d/",
+ "kornia.geometry.transform.warp_perspective3d": "https://kornia.org/playground/ops/geometry-transform-warp_perspective3d/",
+ "kornia.models.depth_estimation.DepthAnythingONNXBuilder": "https://kornia.org/playground/models/depth-estimation-depth-anything-v2/",
+ "kornia.models.small_sr.SmallSRNetWrapper": "https://kornia.org/playground/models/super-resolution-espcn/",
+ "kornia.models.tiny_vit.TinyViT": "https://kornia.org/playground/models/classification-tinyvit/",
+ "kornia.morphology.bottom_hat": "https://kornia.org/playground/ops/morphology-bottom_hat/",
+ "kornia.morphology.closing": "https://kornia.org/playground/ops/morphology-closing/",
+ "kornia.morphology.dilation": "https://kornia.org/playground/ops/morphology-dilation/",
+ "kornia.morphology.erosion": "https://kornia.org/playground/ops/morphology-erosion/",
+ "kornia.morphology.gradient": "https://kornia.org/playground/ops/morphology-gradient/",
+ "kornia.morphology.opening": "https://kornia.org/playground/ops/morphology-opening/",
+ "kornia.morphology.top_hat": "https://kornia.org/playground/ops/morphology-top_hat/"
+}
diff --git a/docs/source/_static/css/playground.css b/docs/source/_static/css/playground.css
new file mode 100644
index 000000000..95e1715dc
--- /dev/null
+++ b/docs/source/_static/css/playground.css
@@ -0,0 +1,44 @@
+/* "Try in browser" badge that links an API to its interactive kornia.org playground page.
+ Added to autodoc entries by _inject_playground_link in conf.py. */
+
+.kornia-try {
+ margin: 0.4rem 0 0.9rem;
+ text-align: right; /* sit the badge at the right edge of the content column */
+}
+
+.kornia-try a,
+.kornia-try a:visited {
+ display: inline-flex;
+ align-items: center;
+ padding: 0.15em 0.7em;
+ border: 1px solid #f5b301;
+ border-radius: 999px;
+ background: rgba(245, 179, 1, 0.12);
+ color: #8a6100;
+ font-size: 0.82em;
+ font-weight: 600;
+ line-height: 1.6;
+ text-decoration: none;
+ transition: background 0.15s ease, color 0.15s ease;
+}
+
+.kornia-try a:hover {
+ background: #f5b301;
+ color: #1a1205;
+ text-decoration: none;
+}
+
+/* dark mode: pydata-sphinx-theme sets data-theme, other themes follow the OS preference */
+html[data-theme="dark"] .kornia-try a,
+html[data-theme="dark"] .kornia-try a:visited {
+ color: #f5c94b;
+ background: rgba(245, 179, 1, 0.16);
+}
+
+@media (prefers-color-scheme: dark) {
+ html:not([data-theme="light"]) .kornia-try a,
+ html:not([data-theme="light"]) .kornia-try a:visited {
+ color: #f5c94b;
+ background: rgba(245, 179, 1, 0.16);
+ }
+}
diff --git a/docs/source/conf.py b/docs/source/conf.py
index 6af311254..0a9622664 100644
--- a/docs/source/conf.py
+++ b/docs/source/conf.py
@@ -424,7 +424,7 @@ html_extra_path = ["_extra"]
# Output file base name for HTML help builder.
htmlhelp_basename = "Kornia"
-html_css_files = ["css/pydata.css"]
+html_css_files = ["css/pydata.css", "css/playground.css"]
html_js_files = ["js/custom.js"]
# Configure viewcode extension.
@@ -677,7 +677,31 @@ def _inject_navbar_menus(app, pagename, templatename, context, doctree):
context["metatags"] = (context.get("metatags", "") or "") + "\n" + _json_script("kornia-navbar-menus", NAVBAR_MENUS)
+# --- "Try in browser" badges: link an autodoc'd API to its interactive playground page ----------
+# The map (fully-qualified name -> page URL) is a snapshot of the kornia.org playground; refresh it
+# with docs/generate_playground_links.py. Functions, their nn.Module counterparts and browser models
+# that have a page get a small badge after their summary line.
+try:
+ with open(os.path.join(os.path.dirname(__file__), "_playground_links.json"), encoding="utf-8") as _f:
+ _PLAYGROUND_LINKS = json.load(_f)
+except OSError: # the docs must still build without the snapshot
+ _PLAYGROUND_LINKS = {}
+
+
+def _inject_playground_link(app, what, name, obj, options, lines):
+ if what not in ("function", "class"):
+ return
+ url = _PLAYGROUND_LINKS.get(name)
+ if not url:
+ return
+ badge = ["", ".. container:: kornia-try", "", f" `Try in browser <{url}>`__", ""]
+ # keep the summary as the first line (autosummary uses it) and drop the badge in just after it
+ cut = next((i for i, line in enumerate(lines) if line.strip() == ""), len(lines))
+ lines[cut:cut] = badge
+
+
def setup(app):
+ app.connect("autodoc-process-docstring", _inject_playground_link)
# Run after the theme's canonical URL normalizer so redirects can replace ``pageurl``.
app.connect("html-page-context", _inject_social_metatags, priority=900)
app.connect("html-page-context", _inject_anchor_redirects)