fix: replace kornia.io.load_image and missing utils with PIL-based loading#110
Merged
ducha-aiki merged 8 commits intomasterfrom Mar 20, 2026
Merged
fix: replace kornia.io.load_image and missing utils with PIL-based loading#110ducha-aiki merged 8 commits intomasterfrom
ducha-aiki merged 8 commits intomasterfrom
Conversation
… 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>
|
Check out this pull request on See visual diffs & provide feedback on Jupyter Notebooks. Powered by ReviewNB |
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>
Member
Author
|
Basically many tutorials were obsolete and required updates. Now done |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
This PR fixes several CI notebook execution failures caused by incompatibilities between kornia versions used in CI and the notebook code.
K.io.load_imagewith PIL-based loading across all 43 notebooks —kornia_rsraisesFileExistsError(data length mismatch) on certain PNGs in CI. UsesK.image_to_tensor(np.array(Image.open(fname).convert("RGB"))).float() / 255.0as a portable replacement that preserves float32[0, 1]tensors.K.utils.get_cuda_or_mps_device_if_availablein 4 notebooks (homography,image_matching_disk,image_matching_lightglue,visual_prompter) — the function was absent in some kornia builds. Replaced with an inlinetorch.device(...)expression.nbqa-isortandnbqa-blackpre-commit hooks..gitignore— add**/.ipynb_checkpoints/,__pycache__/,venv/,.DS_Store, and other common temp files.Test plan
jupyter nbconvert --execute)pre-commit run --all-filespasses (isort, black, pyupgrade)🤖 Generated with Claude Code