lucytuan commited on
Commit
120ff32
·
1 Parent(s): ccb0db9

✨ [Add] RandomVerticalFlip in dataargument.py

Browse files
Files changed (1) hide show
  1. utils/dataargument.py +13 -0
utils/dataargument.py CHANGED
@@ -36,6 +36,19 @@ class RandomHorizontalFlip:
36
  return image, boxes
37
 
38
 
 
 
 
 
 
 
 
 
 
 
 
 
 
39
  class Mosaic:
40
  """Applies the Mosaic augmentation to a batch of images and their corresponding boxes."""
41
 
 
36
  return image, boxes
37
 
38
 
39
+ class RandomVerticalFlip:
40
+ """Randomly vertically flips the image along with the bounding boxes."""
41
+
42
+ def __init__(self, prob=0.5):
43
+ self.prob = prob
44
+
45
+ def __call__(self, image, boxes):
46
+ if torch.rand(1) < self.prob:
47
+ image = TF.vflip(image)
48
+ boxes[:, [2, 4]] = 1 - boxes[:, [4, 2]]
49
+ return image, boxes
50
+
51
+
52
  class Mosaic:
53
  """Applies the Mosaic augmentation to a batch of images and their corresponding boxes."""
54