Remove redundant get_indexes functions in augment.py (#20389)

Co-authored-by: UltralyticsAssistant <web@ultralytics.com>
This commit is contained in:
Laughing 2025-04-28 16:09:53 +08:00 committed by GitHub
parent c55dd9255c
commit e700646ea2
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 8 additions and 35 deletions

View File

@ -31,6 +31,10 @@ keywords: Ultralytics, image augmentation, MixUp, Mosaic, Random Perspective, de
<br><br><hr><br>
## ::: ultralytics.data.augment.CutMix
<br><br><hr><br>
## ::: ultralytics.data.augment.RandomPerspective
<br><br><hr><br>

View File

@ -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

View File

@ -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]