✨ [Add] A instance of dataarguments
Browse files- utils/dataargument.py +15 -0
utils/dataargument.py
CHANGED
@@ -26,3 +26,18 @@ class RandomHorizontalFlip:
|
|
26 |
# Assuming boxes are in the format [cls, xmin, ymin, xmax, ymax]
|
27 |
boxes[:, [1, 3]] = 1 - boxes[:, [3, 1]]
|
28 |
return image, boxes
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
26 |
# Assuming boxes are in the format [cls, xmin, ymin, xmax, ymax]
|
27 |
boxes[:, [1, 3]] = 1 - boxes[:, [3, 1]]
|
28 |
return image, boxes
|
29 |
+
|
30 |
+
class RandomVerticalFlip:
|
31 |
+
"""Randomly vertically flips the image along with the bounding boxes."""
|
32 |
+
|
33 |
+
def __init__(self, p=0.5):
|
34 |
+
self.p = p
|
35 |
+
|
36 |
+
def __call__(self, image, boxes):
|
37 |
+
if torch.rand(1) < self.p:
|
38 |
+
image = TF.vflip(image)
|
39 |
+
# Assuming boxes are in the format [cls, xmin, ymin, xmax, ymax]
|
40 |
+
boxes[:, [2, 4]] = 1 - boxes[:, [2, 4]]
|
41 |
+
return image, boxes
|
42 |
+
|
43 |
+
|