From e700646ea265326aad8822aa6db2a7d4fabacf85 Mon Sep 17 00:00:00 2001 From: Laughing <61612323+Laughing-q@users.noreply.github.com> Date: Mon, 28 Apr 2025 16:09:53 +0800 Subject: [PATCH] Remove redundant `get_indexes` functions in `augment.py` (#20389) Co-authored-by: UltralyticsAssistant --- docs/en/reference/data/augment.md | 4 ++++ docs/mkdocs_github_authors.yaml | 3 +++ ultralytics/data/augment.py | 36 +------------------------------ 3 files changed, 8 insertions(+), 35 deletions(-) diff --git a/docs/en/reference/data/augment.md b/docs/en/reference/data/augment.md index 73cb30f7a9..3845f1eacd 100644 --- a/docs/en/reference/data/augment.md +++ b/docs/en/reference/data/augment.md @@ -31,6 +31,10 @@ keywords: Ultralytics, image augmentation, MixUp, Mosaic, Random Perspective, de



+## ::: ultralytics.data.augment.CutMix + +



+ ## ::: ultralytics.data.augment.RandomPerspective



diff --git a/docs/mkdocs_github_authors.yaml b/docs/mkdocs_github_authors.yaml index 36ea902c95..13685cc73a 100644 --- a/docs/mkdocs_github_authors.yaml +++ b/docs/mkdocs_github_authors.yaml @@ -1,6 +1,9 @@ 107626595+pderrenger@users.noreply.github.com: avatar: https://avatars.githubusercontent.com/u/107626595?v=4 username: pderrenger +114614220+artzuros@users.noreply.github.com: + avatar: https://avatars.githubusercontent.com/u/114614220?v=4 + username: artzuros 116908874+jk4e@users.noreply.github.com: avatar: https://avatars.githubusercontent.com/u/116908874?v=4 username: jk4e diff --git a/ultralytics/data/augment.py b/ultralytics/data/augment.py index 7c72505d53..7b560dd64a 100644 --- a/ultralytics/data/augment.py +++ b/ultralytics/data/augment.py @@ -439,7 +439,7 @@ class BaseMixTransform: >>> indexes = transform.get_indexes() >>> print(indexes) # [3, 18, 7, 2] """ - raise NotImplementedError + return random.randint(0, len(self.dataset) - 1) @staticmethod def _update_label_text(labels): @@ -877,7 +877,6 @@ class MixUp(BaseMixTransform): p (float): Probability of applying MixUp augmentation. Methods: - get_indexes: Returns a random index from the dataset. _mix_transform: Applies MixUp augmentation to the input labels. Examples: @@ -906,24 +905,6 @@ class MixUp(BaseMixTransform): """ super().__init__(dataset=dataset, pre_transform=pre_transform, p=p) - def get_indexes(self): - """ - Get a random index from the dataset. - - This method returns a single random index from the dataset, which is used to select an image for MixUp - augmentation. - - Returns: - (int): A random integer index within the range of the dataset length. - - Examples: - >>> mixup = MixUp(dataset) - >>> index = mixup.get_indexes() - >>> print(index) - 42 - """ - return random.randint(0, len(self.dataset) - 1) - def _mix_transform(self, labels): """ Applies MixUp augmentation to the input labels. @@ -963,7 +944,6 @@ class CutMix(BaseMixTransform): beta (float): Beta distribution parameter for sampling the mixing ratio (default=1.0). Methods: - get_indexes: Returns a random index from the dataset. _mix_transform: Applies CutMix augmentation to the input labels. _rand_bbox: Generates random bounding box coordinates for the cut region. @@ -987,15 +967,6 @@ class CutMix(BaseMixTransform): super().__init__(dataset=dataset, pre_transform=pre_transform, p=p) self.beta = beta - def get_indexes(self): - """ - Get a random index from the dataset. - - Returns: - (int): A random integer index within the range of the dataset length. - """ - return random.randint(0, len(self.dataset) - 1) - def _rand_bbox(self, width, height, lam): """ Generates random bounding box coordinates for the cut region. @@ -1766,7 +1737,6 @@ class CopyPaste(BaseMixTransform): p (float): Probability of applying Copy-Paste augmentation. Methods: - get_indexes: Returns a random index from the dataset. _mix_transform: Applies Copy-Paste augmentation to the input labels. __call__: Applies the Copy-Paste transformation to images and annotations. @@ -1783,10 +1753,6 @@ class CopyPaste(BaseMixTransform): assert mode in {"flip", "mixup"}, f"Expected `mode` to be `flip` or `mixup`, but got {mode}." self.mode = mode - def get_indexes(self): - """Returns a list of random indexes from the dataset for CopyPaste augmentation.""" - return random.randint(0, len(self.dataset) - 1) - def _mix_transform(self, labels): """Applies Copy-Paste augmentation to combine objects from another image into the current image.""" labels2 = labels["mix_labels"][0]