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 srict to Compose #2327

Merged
merged 2 commits into from
Feb 2, 2025
Merged

Added srict to Compose #2327

merged 2 commits into from
Feb 2, 2025

Conversation

ternaus
Copy link
Collaborator

@ternaus ternaus commented Feb 2, 2025

Summary by Sourcery

Add rain and mud effects to the Spatter transform.

New Features:

  • Added get_rain_params function to generate rain effect parameters.
  • Added get_mud_params function to generate mud effect parameters.
  • Added rain and mud modes to the Spatter transform.

Tests:

  • Added tests for get_rain_params and get_mud_params functions.
  • Added tests for the Spatter transform with rain and mud modes.

Copy link
Contributor

sourcery-ai bot commented Feb 2, 2025

Reviewer's Guide by Sourcery

This pull request introduces a strict mode to the Compose class, which validates input keys and transform parameters. It also adds new rain and mud spatter effects with corresponding tests and refactors the spatter implementation.

Sequence diagram for strict mode validation flow

sequenceDiagram
    participant C as Compose
    participant BT as BasicTransform
    participant V as Validator

    C->>C: set strict=True
    activate C
    C->>C: _validate_strict()
    loop For each transform
        C->>BT: check_transform()
        alt has invalid args
            BT-->>C: raise ValueError
        end
    end
    deactivate C

    C->>C: preprocess(data)
    activate C
    alt strict mode enabled
        C->>V: validate data
        V-->>C: validation result
        alt validation fails
            C-->>C: raise ValueError
        end
    end
    deactivate C
Loading

Class diagram for Compose and BasicTransform changes

classDiagram
    class Compose {
        -bool _strict
        +bool strict
        +__init__(transforms, strict=False)
        +_validate_strict()
        +preprocess(data)
    }

    class BasicTransform {
        -bool _strict
        +bool strict
        +list[str] invalid_args
        +__init__(p=0.5, **kwargs)
    }

    note for Compose "Added strict mode validation"
    note for BasicTransform "Added strict mode and invalid args tracking"
Loading

State diagram for transform validation

stateDiagram-v2
    [*] --> Init: Create transform
    Init --> Configured: Set parameters
    Configured --> ValidatingArgs: Enable strict mode
    ValidatingArgs --> Invalid: Has invalid args
    ValidatingArgs --> Valid: No invalid args
    Invalid --> Error: Raise ValueError
    Valid --> Ready: Continue execution
    Ready --> [*]
    Error --> [*]
Loading

File-Level Changes

Change Details Files
Added strict mode to Compose class for input validation.
  • Added a strict parameter to the Compose class.
  • Implemented input key validation in Compose when strict is enabled.
  • Added validation for transform parameters when strict is enabled.
  • Modified tests to include strict parameter.
  • Added strict parameter to BasicTransform.
  • Added invalid_args attribute to BasicTransform to store invalid parameters.
  • Added validation for invalid parameters in BasicTransform when strict is enabled.
tests/test_core.py
albumentations/core/composition.py
albumentations/core/transforms_interface.py
tests/test_pytorch.py
tests/test_bbox.py
tests/test_keypoint.py
tests/test_augmentations.py
tests/test_crop.py
tests/test_serialization.py
tests/test_mixing.py
Implemented new rain and mud spatter effects.
  • Added get_rain_params function to generate rain effect parameters.
  • Added get_mud_params function to generate mud effect parameters.
  • Refactored spatter function into spatter_rain and spatter_mud.
  • Added new tests for rain and mud spatter effects.
  • Modified Spatter transform to use new functions and parameters.
  • Added new parameters to Spatter transform.
  • Added new SpatterMode type definition.
tests/functional/test_functional.py
albumentations/augmentations/functional.py
albumentations/augmentations/transforms.py
tests/test_transforms.py
albumentations/core/type_definitions.py
tests/aug_definitions.py
Refactored and improved existing transforms.
  • Modified unsharp_mask to copy the input image.
  • Improved the blur effect in get_rain_params.
  • Improved the blur effect in get_mud_params.
  • Added a check for zero mask in get_mud_params.
  • Added a check for zero input in get_rain_params.
  • Modified UnsharpMask to use a range for blur_limit and sigma_limit.
  • Modified SaltAndPepper to use a range for amount and salt_vs_pepper.
  • Modified PlasmaBrightnessContrast to use a range for brightness_range and contrast_range.
albumentations/augmentations/functional.py
albumentations/augmentations/transforms.py
tests/test_transforms.py
tests/aug_definitions.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. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the 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 exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!
  • Generate a plan of action for an issue: Comment @sourcery-ai plan on
    an issue to generate a plan of action for it.

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 documentation examples showing how the new strict validation mode helps catch common configuration errors
Here's what I looked at during the review
  • 🟢 General issues: all looks good
  • 🟢 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/functional/test_functional.py Show resolved Hide resolved
tests/functional/test_functional.py Show resolved Hide resolved
tests/functional/test_functional.py Show resolved Hide resolved
tests/functional/test_functional.py Show resolved Hide resolved
tests/test_augmentations.py Show resolved Hide resolved
albumentations/core/transforms_interface.py Show resolved Hide resolved
tests/functional/test_functional.py Outdated Show resolved Hide resolved
@ternaus ternaus merged commit e85ec53 into main Feb 2, 2025
14 checks passed
@ternaus ternaus deleted the extand_strict_in_compose branch February 2, 2025 00:14
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