Skip to content

fix: ensure augmentation reproducibility with Albumentations RNG#5

Merged
mandaiy merged 1 commit intomainfrom
fix/albumentations-reproducibility
Feb 28, 2026
Merged

fix: ensure augmentation reproducibility with Albumentations RNG#5
mandaiy merged 1 commit intomainfrom
fix/albumentations-reproducibility

Conversation

@mandaiy
Copy link
Owner

@mandaiy mandaiy commented Feb 28, 2026

Summary

Align custom augmentation randomness with Albumentations-managed RNG so runs can be reproduced via Compose(seed=...).

Changes

  • moved ShadesOfGray random sampling into get_params() using self.random_generator
  • updated ShadesOfGray.apply() to consume sampled p_norm instead of reading global NumPy RNG
  • removed wrapper-level random gate in ultralytics.Albumentations and delegated probability control to Albumentations transforms
  • added reproducibility test that validates deterministic outputs when using the same Compose(seed=...)

Testing

  • make format
  • make lint
  • make test
  • uv run pytest tests/albumentations/test_transforms.py

Checklist

  • I updated relevant documentation under docs/.
  • PR title follows Conventional Commits (e.g., feat: ..., fix: ...).
  • I verified that the changes are backward compatible, or documented breaking changes.
  • I confirmed this PR is ready for review.

Copy link

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 4ea5e588f8

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".


def __init__(self, transform: A.Compose, p: float = 1.0):
"""Store wrapped transform and application probability.
def __init__(self, transform: A.Compose):

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Preserve p argument for Albumentations adapter

Removing the p parameter from Albumentations.__init__ is a backward-incompatible API change: any existing training code that instantiated this wrapper as Albumentations(transform, p=...) will now raise TypeError before augmentation runs. Since this class previously documented and accepted p, keep the argument (even if deprecated and internally forwarded to compose-level probability) to avoid breaking downstream pipelines on upgrade.

Useful? React with 👍 / 👎.

@mandaiy mandaiy merged commit 8ff7c01 into main Feb 28, 2026
2 checks passed
@mandaiy mandaiy deleted the fix/albumentations-reproducibility branch February 28, 2026 14:23
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