henry000 commited on
Commit
489f14b
·
1 Parent(s): c627401

🦺 [Add] a RemoveOutlier handle outside bbox

Browse files
Files changed (1) hide show
  1. yolo/tools/data_augmentation.py +24 -1
yolo/tools/data_augmentation.py CHANGED
@@ -25,7 +25,30 @@ class AugmentationComposer:
25
  return image, boxes, rev_tensor
26
 
27
 
28
- # TODO: RandomCrop, Resize, ... etc.
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
29
 
30
 
31
  class PadAndResize:
 
25
  return image, boxes, rev_tensor
26
 
27
 
28
+ class RemoveOutliers:
29
+ """Removes outlier bounding boxes that are too small or have invalid dimensions."""
30
+
31
+ def __init__(self, min_box_area=1e-8):
32
+ """
33
+ Args:
34
+ min_box_area (float): Minimum area for a box to be kept, as a fraction of the image area.
35
+ """
36
+ self.min_box_area = min_box_area
37
+
38
+ def __call__(self, image, boxes):
39
+ """
40
+ Args:
41
+ image (PIL.Image): The cropped image.
42
+ boxes (torch.Tensor): Bounding boxes in normalized coordinates (x_min, y_min, x_max, y_max).
43
+ Returns:
44
+ PIL.Image: The input image (unchanged).
45
+ torch.Tensor: Filtered bounding boxes.
46
+ """
47
+ box_areas = (boxes[:, 3] - boxes[:, 1]) * (boxes[:, 4] - boxes[:, 2])
48
+
49
+ valid_boxes = (box_areas > self.min_box_area) & (boxes[:, 3] > boxes[:, 1]) & (boxes[:, 4] > boxes[:, 2])
50
+
51
+ return image, boxes[valid_boxes]
52
 
53
 
54
  class PadAndResize: