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

Update piecewise affine #2010

Merged
merged 3 commits into from
Oct 23, 2024
Merged

Update piecewise affine #2010

merged 3 commits into from
Oct 23, 2024

Conversation

ternaus
Copy link
Collaborator

@ternaus ternaus commented Oct 23, 2024

Summary by Sourcery

Replace the piecewise affine transformation with a remap-based approach and update related functions and tests.

Enhancements:

  • Replace the piecewise affine transformation with a new remap-based approach for image, keypoints, and bounding boxes.

Tests:

  • Add tests for the new create_piecewise_affine_maps function to ensure correct map shapes, bounds, and reproducibility.

Copy link
Contributor

sourcery-ai bot commented Oct 23, 2024

Reviewer's Guide by Sourcery

This pull request updates the piecewise affine transformation implementation in the albumentations library. The main changes include replacing the skimage-based implementation with a custom OpenCV-based solution, renaming functions for clarity, and improving the overall efficiency of the transformation process.

Class diagram for updated geometric functions

classDiagram
    class GeometricFunctions {
        +remap(img: np.ndarray, map_x: np.ndarray, map_y: np.ndarray, interpolation: int, border_mode: int, value: ColorType | None)
        +remap_keypoints(keypoints: np.ndarray, map_x: np.ndarray, map_y: np.ndarray, image_shape: tuple[int, int])
        +remap_bboxes(bboxes: np.ndarray, map_x: np.ndarray, map_y: np.ndarray, image_shape: tuple[int, int])
        +create_piecewise_affine_maps(image_shape: tuple[int, int], grid: tuple[int, int], scale: float, absolute_scale: bool, random_generator: np.random.Generator | None)
    }
    note for GeometricFunctions "Replaced skimage-based piecewise affine with OpenCV-based remap functions"
Loading

Class diagram for PiecewiseAffine transform

classDiagram
    class PiecewiseAffine {
        -nb_rows: int
        -nb_cols: int
        -scale: float
        -absolute_scale: bool
        -cval: float
        -mode: str
        +apply(img: np.ndarray, map_x: np.ndarray | None, map_y: np.ndarray | None, border_mode: int)
        +apply_to_mask(mask: np.ndarray, map_x: np.ndarray | None, map_y: np.ndarray | None, border_mode: int)
        +apply_to_bboxes(bboxes: np.ndarray, map_x: np.ndarray | None, map_y: np.ndarray | None, border_mode: int)
        +apply_to_keypoints(keypoints: np.ndarray, map_x: np.ndarray | None, map_y: np.ndarray | None, border_mode: int)
        +get_params_dependent_on_data(params: dict[str, Any], data: dict[str, Any])
    }
    note for PiecewiseAffine "Updated to use remap functions instead of skimage's piecewise affine"
Loading

File-Level Changes

Change Details Files
Replace skimage-based piecewise affine implementation with custom OpenCV-based solution
  • Remove skimage dependency for piecewise affine transformation
  • Implement create_piecewise_affine_maps function using OpenCV
  • Update PiecewiseAffine class to use the new implementation
  • Modify apply methods to use remap instead of piecewise_affine
albumentations/augmentations/geometric/functional.py
albumentations/augmentations/geometric/transforms.py
Rename distortion-related functions to remap for clarity
  • Rename distortion to remap
  • Rename distortion_keypoints to remap_keypoints
  • Rename distortion_bboxes to remap_bboxes
  • Update function calls and imports accordingly
albumentations/augmentations/geometric/functional.py
albumentations/augmentations/geometric/transforms.py
tests/test_bbox.py
Improve efficiency of remap function
  • Combine map_x and map_y into a single map array
  • Use None as the second map parameter in cv2.remap
albumentations/augmentations/geometric/functional.py
Add comprehensive tests for the new piecewise affine implementation
  • Add tests for create_piecewise_affine_maps function
  • Test various aspects such as shapes, bounds, reproducibility, and grid points
tests/functional/test_geometric.py
Update PiecewiseAffine class parameters and documentation
  • Remove keypoints_threshold parameter
  • Update interpolation parameter description
  • Modify get_params_dependent_on_data method to use new implementation
albumentations/augmentations/geometric/transforms.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 and they look great!

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.

tests/functional/test_geometric.py Show resolved Hide resolved
tests/functional/test_geometric.py Show resolved Hide resolved
tests/functional/test_geometric.py Show resolved Hide resolved
tests/functional/test_geometric.py Show resolved Hide resolved
tests/functional/test_geometric.py Show resolved Hide resolved
@ternaus ternaus merged commit ff9bb8a into main Oct 23, 2024
14 checks passed
@ternaus ternaus deleted the update_piecewise_affine branch October 23, 2024 02:29
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