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 bboxes to grid shuffle #2057

Merged
merged 6 commits into from
Nov 4, 2024
Merged

Add bboxes to grid shuffle #2057

merged 6 commits into from
Nov 4, 2024

Conversation

ternaus
Copy link
Collaborator

@ternaus ternaus commented Nov 4, 2024

Fixes: #1948

Summary by Sourcery

Add support for grid shuffle transformations on bounding boxes and enhance the RandomGridShuffle transformation to include bounding boxes as a target. Introduce a new function bboxes_grid_shuffle and provide comprehensive tests for its functionality.

New Features:

  • Introduce a new function bboxes_grid_shuffle to apply grid shuffle transformations to bounding boxes, allowing for more flexible data augmentation.

Enhancements:

  • Refactor the RandomGridShuffle transformation to include bounding boxes as a target, enhancing its functionality.

Tests:

  • Add comprehensive tests for the new bboxes_grid_shuffle function, covering various scenarios including basic functionality, minimum area and visibility filters, and handling of extra fields.

Copy link
Contributor

sourcery-ai bot commented Nov 4, 2024

Reviewer's Guide by Sourcery

This PR adds support for bounding boxes in the RandomGridShuffle transform by implementing a new bboxes_grid_shuffle function and reorganizing related code. The implementation handles splitting and merging of bounding boxes when they cross tile boundaries, with options to filter based on minimum area and visibility requirements.

Class diagram for RandomGridShuffle and related functions

classDiagram
    class RandomGridShuffle {
        - grid: tuple[int, int]
        - p: float
        - always_apply: bool | None
        + apply(img: np.ndarray, tiles: np.ndarray, mapping: list[int], **params: Any) np.ndarray
        + apply_to_bboxes(bboxes: np.ndarray, tiles: np.ndarray, mapping: np.ndarray, **params: Any) np.ndarray
        + apply_to_keypoints(keypoints: np.ndarray, tiles: np.ndarray, mapping: np.ndarray, **params: Any) np.ndarray
        + get_params_dependent_on_data(params: dict[str, Any], data: dict[str, Any]) dict[str, np.ndarray]
        + get_transform_init_args_names() tuple[str, ...]
    }

    class fgeometric {
        + swap_tiles_on_image(image: np.ndarray, tiles: np.ndarray, mapping: list[int] | None) np.ndarray
        + swap_tiles_on_keypoints(keypoints: np.ndarray, tiles: np.ndarray, mapping: np.ndarray) np.ndarray
        + bboxes_grid_shuffle(bboxes: np.ndarray, tiles: np.ndarray, mapping: list[int], image_shape: tuple[int, int], min_area: float | None, min_visibility: float | None) np.ndarray
        + create_shape_groups(tiles: np.ndarray) dict[tuple[int, int], list[int]]
        + shuffle_tiles_within_shape_groups(shape_groups: dict[tuple[int, int], list[int]], random_generator: np.random.Generator) list[int]
    }

    RandomGridShuffle --> fgeometric : uses
Loading

File-Level Changes

Change Details Files
Added bounding box support to RandomGridShuffle transform
  • Implemented bboxes_grid_shuffle function to handle bbox transformations
  • Added min_area and min_visibility filtering options for split bboxes
  • Updated transform targets to include bboxes
  • Added comprehensive test cases for bbox handling
albumentations/augmentations/geometric/functional.py
albumentations/augmentations/geometric/transforms.py
tests/test_bbox.py
README.md
Reorganized code structure for better maintainability
  • Moved geometric-related functions from functional.py to geometric/functional.py
  • Moved RandomGridShuffle from transforms.py to geometric/transforms.py
  • Updated import statements and references accordingly
albumentations/augmentations/geometric/functional.py
albumentations/augmentations/geometric/transforms.py
albumentations/augmentations/transforms.py
albumentations/augmentations/functional.py
Enhanced test coverage
  • Added tests for basic bbox grid shuffle functionality
  • Added tests for min_area and min_visibility filtering
  • Added tests for bbox splitting and component handling
  • Updated existing tests to reflect code reorganization
tests/test_bbox.py
tests/test_targets.py
tests/test_transforms.py
tests/test_serialization.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: 2 issues found
  • 🟡 Complexity: 1 issue found
  • 🟢 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/test_bbox.py Show resolved Hide resolved
tests/test_bbox.py Outdated Show resolved Hide resolved
Copy link

codecov bot commented Nov 4, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 90.39%. Comparing base (b1a79c2) to head (71125c1).
Report is 252 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff            @@
##           main    #2057       +/-   ##
=========================================
+ Coverage      0   90.39%   +90.39%     
=========================================
  Files         0       46       +46     
  Lines         0     7652     +7652     
=========================================
+ Hits          0     6917     +6917     
- Misses        0      735      +735     

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

@ternaus ternaus merged commit 2e1bbec into main Nov 4, 2024
16 checks passed
@ternaus ternaus deleted the add_bboxes_to_grid_shuffle branch November 4, 2024 23:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
1 participant