Skip to content

Extend image augmentation module and definitely fix device bug#32

Merged
PeterCalifano merged 25 commits intomainfrom
dev_improve_debug_augmentations
Jan 3, 2026
Merged

Extend image augmentation module and definitely fix device bug#32
PeterCalifano merged 25 commits intomainfrom
dev_improve_debug_augmentations

Conversation

@PeterCalifano
Copy link
Owner

@PeterCalifano PeterCalifano commented Dec 28, 2025

List of changes for this PR:

  • Introduces extended version of RandomAffine (reimplemented) aware of target body location in the image plane. This ensures that unrealistic affine transformations are not applied by constraining the allowed motion and rotation depending on which border is touched by the body shape. Tailored for space images. Addresses Implement RandomAffine "border aware" from kornia #31
  • Adds new soft-binarization augmentation to remove or reduce the texture content of the illuminated part of the image, addressing issue Implement "binarize" augmentation with kornia classes #28
  • Fixes issues with device management in the images augmentation helper class. Now works correctly on the specified device.
  • Adds more tests for augmentation module and timing test cpu vs cuda

- 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
@PeterCalifano PeterCalifano self-assigned this Dec 28, 2025
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 BorderAwareRandomAffine with border crossing detection to prevent unrealistic transformations
  • Added RandomSoftBinarizeImage augmentation for texture content reduction
  • Fixed device management bugs in ImageAugmentationsHelper to 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)
Copy link

Copilot AI Dec 28, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copilot uses AI. Check for mistakes.
PeterCalifano and others added 3 commits January 3, 2026 09:56
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>
@PeterCalifano PeterCalifano merged commit 9317709 into main Jan 3, 2026
1 of 2 checks passed
@PeterCalifano
Copy link
Owner Author

Note: it addresses issues #32 and #31.

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