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

Added mask3d #2200

Merged
merged 4 commits into from
Dec 15, 2024
Merged

Added mask3d #2200

merged 4 commits into from
Dec 15, 2024

Conversation

ternaus
Copy link
Collaborator

@ternaus ternaus commented Dec 15, 2024

Summary by Sourcery

Add support for 3D masks and volumes in the transformation library, enabling operations on 3D data. Update the codebase to handle 3D data consistently alongside 2D data, and enhance documentation and tests to reflect these changes.

New Features:

  • Introduce support for 3D masks and volumes in transformations, allowing operations on 3D data similar to 2D images.

Enhancements:

  • Refactor transformation methods to handle both 2D and 3D data consistently, improving code maintainability and flexibility.

Documentation:

  • Update documentation to reflect the addition of 3D mask and volume support in transformations, including changes in the README and docstrings.

Tests:

  • Modify existing tests and add new ones to ensure the correct functionality of transformations with 3D masks and volumes.

Copy link
Contributor

sourcery-ai bot commented Dec 15, 2024

Reviewer's Guide by Sourcery

This PR adds support for 3D data transformations by introducing new volume and mask3d targets, refactoring the Transform3D class, and updating all existing transforms to handle 3D data consistently. The implementation maintains backward compatibility while providing a cleaner API for working with volumetric data.

Class diagram for updated Transform3D and DualTransform classes

classDiagram
    class DualTransform {
        +apply_to_images(images: np.ndarray, **params: Any) np.ndarray
        +apply_to_mask(mask: np.ndarray, **params: Any) np.ndarray
        +apply_to_masks(masks: np.ndarray, **params: Any) np.ndarray
        +apply_to_volume(volume: np.ndarray, **params: Any) np.ndarray
        +apply_to_volumes(volumes: np.ndarray, **params: Any) np.ndarray
        +apply_to_mask3d(mask: np.ndarray, **params: Any) np.ndarray
        +apply_to_masks3d(masks: np.ndarray, **params: Any) np.ndarray
    }
    class Transform3D {
        +apply_to_volume(volume: np.ndarray, *args: Any, **params: Any) np.ndarray
        +apply_to_volumes(volumes: np.ndarray, *args: Any, **params: Any) np.ndarray
        +apply_to_mask3d(mask3d: np.ndarray, *args: Any, **params: Any) np.ndarray
        +apply_to_masks3d(masks3d: np.ndarray, *args: Any, **params: Any) np.ndarray
    }
    DualTransform <|-- Transform3D
Loading

Class diagram for updated BasePad3D and BaseCropAndPad3D classes

classDiagram
    class BasePad3D {
        +apply_to_volume(volume: np.ndarray, padding: tuple[int, int, int, int, int, int], **params: Any) np.ndarray
        +apply_to_mask3d(mask3d: np.ndarray, padding: tuple[int, int, int, int, int, int], **params: Any) np.ndarray
    }
    class BaseCropAndPad3D {
        +apply_to_volume(volume: np.ndarray, crop_coords: tuple[int, int, int, int, int, int], pad_params: dict[str, int] | None, **params: Any) np.ndarray
        +apply_to_mask3d(mask3d: np.ndarray, crop_coords: tuple[int, int, int, int, int, int], pad_params: dict[str, int] | None, **params: Any) np.ndarray
    }
Loading

File-Level Changes

Change Details Files
Added new volume and mask3d targets to support 3D data transformations
  • Added VOLUME and MASK3D to Targets enum
  • Updated ALL_TARGETS to include new volume and mask3d targets
  • Added volume and mask3d to AVAILABLE_KEYS
  • Added new target checking methods for volume and mask3d data
albumentations/core/types.py
albumentations/core/composition.py
Refactored Transform3D class to use consistent volume/mask3d terminology
  • Renamed images/masks methods to volume/mask3d for clarity
  • Updated Transform3D to inherit from DualTransform
  • Added apply_to_volume and apply_to_mask3d methods
  • Removed deprecated 3D bboxes and keypoints support
albumentations/core/transforms_interface.py
Updated all transforms to support 3D data operations
  • Added volume and mask3d support to all existing transforms
  • Updated transform docstrings to include new targets
  • Modified shape handling to work with both 2D and 3D data
  • Updated tests to use new volume/mask3d terminology
albumentations/augmentations/geometric/transforms.py
albumentations/augmentations/transforms3d/transforms.py
tests/transforms3d/test_transforms.py
tests/test_targets.py
Improved parameter handling and shape validation
  • Added separate shape checks for 2D and 3D data
  • Updated update_params_shape to handle volume dimensions
  • Removed redundant rows/cols parameters in favor of shape
  • Added validation for volume shapes consistency
albumentations/core/composition.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 - here's some feedback:

Overall Comments:

  • Consider adding migration guide documentation to help users transition from the old 'images'/'masks' API to the new 'volume'/'mask3d' API for 3D data
Here's what I looked at during the review
  • 🟡 General issues: 1 issue found
  • 🟢 Security: all looks good
  • 🟡 Testing: 1 issue 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_transforms.py Show resolved Hide resolved
README.md Outdated Show resolved Hide resolved
tests/test_core.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
tools/make_transforms_docs.py Outdated Show resolved Hide resolved
albumentations/core/transforms_interface.py Outdated Show resolved Hide resolved
tests/test_serialization.py Show resolved Hide resolved
tests/test_serialization.py Show resolved Hide resolved
Copy link

codecov bot commented Dec 15, 2024

Codecov Report

Attention: Patch coverage is 73.33333% with 40 lines in your changes missing coverage. Please review.

Project coverage is 89.08%. Comparing base (b1a79c2) to head (e814ce0).
Report is 313 commits behind head on main.

Files with missing lines Patch % Lines
albumentations/core/transforms_interface.py 46.51% 23 Missing ⚠️
albumentations/core/composition.py 68.08% 15 Missing ⚠️
...entations/augmentations/transforms3d/functional.py 66.66% 1 Missing ⚠️
...entations/augmentations/transforms3d/transforms.py 92.85% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff            @@
##           main    #2200       +/-   ##
=========================================
+ Coverage      0   89.08%   +89.08%     
=========================================
  Files         0       50       +50     
  Lines         0     8834     +8834     
=========================================
+ Hits          0     7870     +7870     
- Misses        0      964      +964     

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

@ternaus ternaus merged commit bc6bf77 into main Dec 15, 2024
16 checks passed
@ternaus ternaus deleted the added_mask3d branch December 15, 2024 04:28
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