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

Add keypoints to 3d #2217

Merged
merged 9 commits into from
Dec 24, 2024
Merged

Add keypoints to 3d #2217

merged 9 commits into from
Dec 24, 2024

Conversation

ternaus
Copy link
Collaborator

@ternaus ternaus commented Dec 24, 2024

Summary by Sourcery

New Features:

  • Added keypoint support to 3D augmentations such as Pad3D, PadIfNeeded3D, CenterCrop3D, RandomCrop3D, CoarseDropout3D, and CubicSymmetry. Keypoints are now correctly transformed along with volumes and masks, ensuring consistency after augmentation. Transforms now handle keypoints outside the volume boundaries correctly, filtering them out as needed. Improved handling of empty keypoint arrays and edge cases like points exactly on volume boundaries. Added tests to verify keypoint transformations match expected behavior and volume transformations.

Copy link
Contributor

sourcery-ai bot commented Dec 24, 2024

Reviewer's Guide by Sourcery

This pull request adds keypoint support to various 3D augmentations, ensuring keypoint positions are correctly updated after transformations like padding, cropping, and rotations. It also introduces a new function to filter keypoints located within specified 3D holes/bounding boxes.

Sequence diagram for keypoint filtering in CoarseDropout3D

sequenceDiagram
    participant T as Transform
    participant F as filter_keypoints_in_holes3d
    participant K as Keypoints
    T->>F: Pass keypoints and holes
    F->>K: Check keypoint positions
    Note over F,K: Compare each keypoint against hole boundaries
    F-->>T: Return filtered keypoints
    Note over T: Only keypoints outside
    Note over T: holes are preserved
Loading

Class diagram showing updated Transform3D hierarchy with keypoint support

classDiagram
    class Transform3D {
        +apply_to_volume()
        +apply_to_mask3d()
        +apply_to_keypoints()
    }
    class BasePad3D {
        -_targets: (VOLUME, MASK3D, KEYPOINTS)
        +apply_to_keypoints()
    }
    class BaseCropAndPad3D {
        -_targets: (VOLUME, MASK3D, KEYPOINTS)
        +apply_to_keypoints()
    }
    class CoarseDropout3D {
        -_targets: (VOLUME, MASK3D, KEYPOINTS)
        +apply_to_keypoints()
    }
    class CubicSymmetry {
        -_targets: (VOLUME, MASK3D, KEYPOINTS)
        +apply_to_keypoints()
    }
    Transform3D <|-- BasePad3D
    Transform3D <|-- BaseCropAndPad3D
    Transform3D <|-- CoarseDropout3D
    Transform3D <|-- CubicSymmetry
    note for Transform3D "Added keypoints support"
    note for BasePad3D "Handles keypoint shifting during padding"
    note for BaseCropAndPad3D "Handles keypoint transformation during crop/pad"
    note for CoarseDropout3D "Filters keypoints in dropout regions"
    note for CubicSymmetry "Transforms keypoints during cube rotations"
Loading

File-Level Changes

Change Details Files
Added keypoint transforms to 3D augmentations
  • Added apply_to_keypoints methods to Pad3D, PadIfNeeded3D, CenterCrop3D, RandomCrop3D, CoarseDropout3D, and CubicSymmetry to handle keypoint transformations.
  • Updated _targets to include Targets.KEYPOINTS for these augmentations to indicate keypoint support
albumentations/augmentations/transforms3d/transforms.py
Implemented keypoint filtering within 3D holes
  • Added filter_keypoints_in_holes3d function to remove keypoints inside specified 3D bounding boxes (holes).
  • Added tests for filter_keypoints_in_holes3d to verify its behavior with various inputs and edge cases
albumentations/augmentations/transforms3d/functional.py
tests/transforms3d/test_functions.py
Added keypoint rotation utility function
  • Added keypoints_rot90 function to rotate keypoints by multiples of 90 degrees around specified axes.
  • Added tests to verify keypoints_rot90 behavior and its consistency with np.rot90
albumentations/augmentations/transforms3d/functional.py
tests/transforms3d/test_functions.py
Extended keypoint support for cubic symmetry transformations
  • Added transform_cube_keypoints function to transform keypoints according to cubic symmetry operations.
  • Added tests to verify that transform_cube_keypoints correctly transforms keypoints and preserves extra columns in the keypoint array
albumentations/augmentations/transforms3d/functional.py
tests/transforms3d/test_functions.py
Updated tests and documentation
  • Added tests for keypoint transformations in test_transforms.py.
  • Updated serialization tests in test_serialization.py to include keypoints.
  • Modified test_targets.py to reflect keypoint support.
  • Updated documentation in README.md to include keypoints in the supported targets table.
  • Modified make_transforms_docs.py to generate documentation for keypoint support.
  • Added keypoints to targets in transforms_interface.py
tests/transforms3d/test_transforms.py
tests/test_serialization.py
tests/transforms3d/test_targets.py
README.md
tools/make_transforms_docs.py
albumentations/core/transforms_interface.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: 2 issues found
  • 🟢 Security: all looks good
  • 🟡 Testing: 2 issues found
  • 🟢 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/transforms3d/test_functions.py Show resolved Hide resolved
tests/transforms3d/test_functions.py Show resolved Hide resolved
tests/transforms3d/test_functions.py Show resolved Hide resolved
tests/transforms3d/test_functions.py Show resolved Hide resolved
tests/transforms3d/test_functions.py Show resolved Hide resolved
tests/transforms3d/test_transforms.py Show resolved Hide resolved
tests/transforms3d/test_transforms.py Show resolved Hide resolved
tests/transforms3d/test_transforms.py Show resolved Hide resolved
Copy link

codecov bot commented Dec 24, 2024

Codecov Report

Attention: Patch coverage is 93.13725% with 7 lines in your changes missing coverage. Please review.

Project coverage is 89.81%. Comparing base (b1a79c2) to head (b39351a).
Report is 327 commits behind head on main.

Files with missing lines Patch % Lines
...entations/augmentations/transforms3d/transforms.py 76.92% 6 Missing ⚠️
...entations/augmentations/transforms3d/functional.py 98.68% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff            @@
##           main    #2217       +/-   ##
=========================================
+ Coverage      0   89.81%   +89.81%     
=========================================
  Files         0       50       +50     
  Lines         0     9095     +9095     
=========================================
+ Hits          0     8169     +8169     
- Misses        0      926      +926     

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

@ternaus ternaus merged commit e997452 into main Dec 24, 2024
16 checks passed
@ternaus ternaus deleted the add_keypoints_to_3d branch December 24, 2024 03:35
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