Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

More inplace #2048

Merged
merged 4 commits into from
Nov 1, 2024
Merged

More inplace #2048

merged 4 commits into from
Nov 1, 2024

Conversation

ternaus
Copy link
Collaborator

@ternaus ternaus commented Nov 1, 2024

Summary by Sourcery

Improve performance by using in-place operations in several functions and update albucore dependency version.

Enhancements:

  • Enhance various functions to use in-place operations for improved performance and memory efficiency.

Build:

  • Update albucore dependency version to 0.0.21 in setup.py.

Copy link
Contributor

sourcery-ai bot commented Nov 1, 2024

Reviewer's Guide by Sourcery

This PR optimizes memory usage by modifying various numpy operations to perform calculations in-place where possible. The main changes involve adding the inplace=True parameter to existing function calls and utilizing numpy's out parameter for clip operations to modify arrays in-place rather than creating new copies.

Class diagram for updated numpy operations

classDiagram
    class Functional {
        +shift_hsv(img: np.ndarray, hue_shift: float, sat_shift: float, val_shift: float)
        +evaluate_bez(t: np.ndarray, low_y: float | np.ndarray, high_y: float | np.ndarray)
        +add_snow_bleach(img: np.ndarray, snow_point: float, brightness_coeff: float)
        +add_fog()
        +add_shadow(img: np.ndarray, vertices_list: list[np.ndarray], intensities: np.ndarray)
        +iso_noise()
        +fancy_pca(img: np.ndarray, alpha_vector: np.ndarray)
        +unsharp_mask()
        +add_noise(img: np.ndarray, noise: np.ndarray)
    }
    class GeometricFunctional {
        +remap_keypoints()
        +distort_image_keypoints()
        +create_piecewise_affine_maps()
    }
    class DomainAdaptationFunctional {
        +to_colorspace(self, img: np.ndarray)
        +from_colorspace(self, img: np.ndarray)
        +flatten(self, img: np.ndarray)
        +reconstruct(self, pixels: np.ndarray, height: int, width: int)
    }
    class Transforms {
        +get_params_dependent_on_data(self, params: dict[str, Any], data: dict[str, Any])
    }
    class BboxUtils {
        +clip_bboxes(bboxes: np.ndarray, image_shape: tuple[int, int])
    }
    note for Functional "In-place operations added to shift_hsv, evaluate_bez, add_snow_bleach, add_fog, add_shadow, iso_noise, fancy_pca, unsharp_mask, add_noise"
    note for GeometricFunctional "In-place operations added to remap_keypoints, distort_image_keypoints, create_piecewise_affine_maps"
    note for DomainAdaptationFunctional "In-place operations added to from_colorspace, flatten, reconstruct"
    note for Transforms "In-place operations added to get_params_dependent_on_data"
    note for BboxUtils "In-place operations added to clip_bboxes"
Loading

File-Level Changes

Change Details Files
Modified numpy clip operations to use in-place modifications
  • Added out parameter to np.clip calls to modify arrays in-place
  • Updated clip operations in coordinate transformations to use in-place modifications
  • Modified bbox clipping operations to use in-place array modifications
albumentations/augmentations/functional.py
albumentations/augmentations/geometric/functional.py
albumentations/core/bbox_utils.py
Updated various image processing functions to use in-place operations
  • Modified HSV shift operations to use in-place addition
  • Updated snow and fog effect calculations to use in-place modifications
  • Modified image noise and PCA operations to use in-place array modifications
albumentations/augmentations/functional.py
albumentations/augmentations/domain_adaptation/functional.py
Updated dependency version
  • Upgraded albucore dependency from version 0.0.20 to 0.0.21
setup.py

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time. You can also use
    this command to specify where the summary should be inserted.

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

Copy link
Contributor

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

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

Hey @ternaus - I've reviewed your changes - here's some feedback:

Overall Comments:

  • Consider using a more descriptive PR title like 'Optimize memory usage with in-place NumPy operations' to better reflect the changes
Here's what I looked at during the review
  • 🟢 General issues: all looks good
  • 🟢 Security: all looks good
  • 🟢 Testing: all looks good
  • 🟢 Complexity: all looks good
  • 🟢 Documentation: all looks good

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

Copy link

codecov bot commented Nov 1, 2024

Codecov Report

Attention: Patch coverage is 96.00000% with 1 line in your changes missing coverage. Please review.

Project coverage is 90.28%. Comparing base (b1a79c2) to head (92e304f).
Report is 247 commits behind head on main.

Files with missing lines Patch % Lines
...ions/augmentations/domain_adaptation/functional.py 50.00% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff            @@
##           main    #2048       +/-   ##
=========================================
+ Coverage      0   90.28%   +90.28%     
=========================================
  Files         0       46       +46     
  Lines         0     7597     +7597     
=========================================
+ Hits          0     6859     +6859     
- Misses        0      738      +738     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@ternaus ternaus merged commit 1efe69a into main Nov 1, 2024
16 checks passed
@ternaus ternaus deleted the more_inplace branch November 1, 2024 23:17
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