Skip to content

fix: replace kornia.io.load_image and missing utils with PIL-based loading#110

Merged
ducha-aiki merged 8 commits intomasterfrom
fix/ci-notebook-compatibility
Mar 20, 2026
Merged

fix: replace kornia.io.load_image and missing utils with PIL-based loading#110
ducha-aiki merged 8 commits intomasterfrom
fix/ci-notebook-compatibility

Conversation

@ducha-aiki
Copy link
Copy Markdown
Member

Summary

This PR fixes several CI notebook execution failures caused by incompatibilities between kornia versions used in CI and the notebook code.

  • Replace K.io.load_image with PIL-based loading across all 43 notebooks — kornia_rs raises FileExistsError (data length mismatch) on certain PNGs in CI. Uses K.image_to_tensor(np.array(Image.open(fname).convert("RGB"))).float() / 255.0 as a portable replacement that preserves float32 [0, 1] tensors.
  • Fix K.utils.get_cuda_or_mps_device_if_available in 4 notebooks (homography, image_matching_disk, image_matching_lightglue, visual_prompter) — the function was absent in some kornia builds. Replaced with an inline torch.device(...) expression.
  • Fix import ordering and formatting — all notebooks pass nbqa-isort and nbqa-black pre-commit hooks.
  • Update .gitignore — add **/.ipynb_checkpoints/, __pycache__/, venv/, .DS_Store, and other common temp files.

Test plan

  • All notebooks execute without error locally (jupyter nbconvert --execute)
  • pre-commit run --all-files passes (isort, black, pyupgrade)
  • CI build passes on the PR

🤖 Generated with Claude Code

… equivalent

The function was missing in some kornia versions used in CI, causing
AttributeError. Replace with:
  torch.device("cuda" if torch.cuda.is_available() else "mps" if torch.backends.mps.is_available() else "cpu")

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@review-notebook-app
Copy link
Copy Markdown

Check out this pull request on  ReviewNB

See visual diffs & provide feedback on Jupyter Notebooks.


Powered by ReviewNB

ducha-aiki and others added 7 commits March 19, 2026 23:51
LoFTR and K.geometry.resize require float32 tensors. The image loading
cells (outdoor and indoor examples) were missing the float conversion,
causing a silent failure inside %%capture that left correspondences
undefined in the next cell.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
%%capture was incorrectly inserted mid-cell (must be first line).
Also add .float() / 255.0 to load_images so LoFTR receives float tensors.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Add .float() / 255.0 to image loading in notebooks where PIL uint8
tensors were passed to kornia ops requiring float32 (lerp, grid_sample,
color conversions, SAM model etc).

Affected: unsharp_mask, color_conversions, extract_combine_patches,
gaussian_blur, image_enhancement, resize_antialias, warp_perspective,
visual_prompter.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
…odels

kornia.contrib.models was moved to kornia.models in newer kornia versions.
Update SamConfig and SegmentationResults imports accordingly.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
- visual_prompter: SamConfig -> kornia.models.sam, SegmentationResults
  -> kornia.models.structures (module paths updated in newer kornia)
- Add .float() / 255.0 to 7 more notebooks: color_conversions,
  extract_combine_patches, gaussian_blur, image_enhancement,
  resize_antialias, warp_perspective, visual_prompter

All locally-runnable notebooks pass (37/43). Remaining 6 require
either optional deps (rawpy, py7zr, pytorch_lightning,
kornia.augmentation.presets) or a GPU (image_registration,
visual_prompter) available only in CI.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
…deadlock

DataLoader with num_workers>0 deadlocks in notebook context on macOS
due to multiprocessing spawn issues. Set num_workers=0 for all three
DataLoaders (train/val/test).

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
PIL-based image loading uses K.image_to_tensor but the kornia alias
was never imported in this notebook. Add it to the imports cell.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@ducha-aiki
Copy link
Copy Markdown
Member Author

Basically many tutorials were obsolete and required updates. Now done

@ducha-aiki ducha-aiki merged commit e1cc4b3 into master Mar 20, 2026
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant