Extend image augmentation module and definitely fix device bug#32
Extend image augmentation module and definitely fix device bug#32PeterCalifano merged 25 commits intomainfrom
Conversation
- Add new config entry to deactivate random apply (default selection) - Requires modification of random apply due to random order (previously misunderstood behaviour)
- Move method to static and review - Start some refactoring
- Minor improvements in augs helper - Start implementation of BorderAwareRandomAffine to replace RandomAffine
- Implement test for border crossing detection method - Rework class methods to comply with kornia Geometric Augmentation 2D base class - Minor fixes of output shapes
- Change interface to add new input options - Add assertions on parameters validity - Fix incorrect indexing (not needed for intensity augs)
- Reimplement factory function for AugsSequential from legacy function - Add interfaces in augs helper class for SoftBinarize module - Complete implementation of RandomSoftBinarizeImage augmentation module (blended binarization) with major bug fixes - Add implementation of unit test and general improvements
- Improves robustness to spurious 1s in the background (as caused by Blender)
- Add assertion on execution device for module - Add timing test to compare cpu vs gpu execution
- Add methods to resolve and move to device - Add move to device wherever relevant - Fix implementation of "to" method of the helper class - Implement tests and timing benchmark in test module
There was a problem hiding this comment.
Pull request overview
This PR extends the image augmentation module with new capabilities, fixes device management issues, and adds comprehensive tests. The changes enable border-aware affine transformations for space images, introduce soft-binarization for texture removal, and ensure correct device placement throughout the augmentation pipeline.
Key Changes:
- Implemented
BorderAwareRandomAffinewith border crossing detection to prevent unrealistic transformations - Added
RandomSoftBinarizeImageaugmentation for texture content reduction - Fixed device management bugs in
ImageAugmentationsHelperto properly handle CPU/CUDA placement - Restructured code by moving augmentation classes to dedicated modules under
noise_models/
Reviewed changes
Copilot reviewed 9 out of 11 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
| tests/datasets/test_ImagesAugmentation.py | Added comprehensive tests for new augmentations, device handling, and CPU vs CUDA timing benchmarks |
| pyTorchAutoForge/datasets/noise_models/OpticsErrorsAugs.py | New module containing optics-related augmentation imports and base setup |
| pyTorchAutoForge/datasets/noise_models/NoiseErrorsAugs.py | Relocated noise augmentation classes (PoissonShotNoise, RandomGaussianNoiseVariableSigma) |
| pyTorchAutoForge/datasets/noise_models/IntensityAugs.py | New intensity augmentations including RandomSoftBinarizeImage |
| pyTorchAutoForge/datasets/noise_models/GeometricAugs.py | New BorderAwareRandomAffine implementation with border detection logic |
| pyTorchAutoForge/datasets/auxiliary_functions.py | Updated pixel zero threshold from 7 to 1.0 |
| pyTorchAutoForge/datasets/ImagesAugmentation.py | Major refactoring: moved augmentation classes to separate modules, fixed device handling with new helper methods |
| lib/CommManager4MATLAB | Updated submodule commit reference |
| TODO | Updated task tracking for v0.2.X and v0.3.X milestones |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| # Overload "to" method | ||
| def to(self, *args, **kwargs): | ||
| """Overload to method to apply to all submodules.""" | ||
| device, _, _, _ = torch._C._nn._parse_to(*args, **kwargs) |
There was a problem hiding this comment.
Using private/internal PyTorch API torch._C._nn._parse_to. This may break in future PyTorch versions. Consider using public APIs or reimplementing device parsing logic.
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
List of changes for this PR: