Updates `scaleFill` argument to `snake_case` (#19401)

pull/19418/head
Burhan 2 weeks ago committed by GitHub
parent c15fc952e1
commit 679ab796e8
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
  1. 14
      ultralytics/data/augment.py
  2. 4
      ultralytics/models/rtdetr/predict.py
  3. 2
      ultralytics/models/rtdetr/val.py

@ -1484,7 +1484,7 @@ class LetterBox:
Attributes:
new_shape (tuple): Target shape (height, width) for resizing.
auto (bool): Whether to use minimum rectangle.
scaleFill (bool): Whether to stretch the image to new_shape.
scale_fill (bool): Whether to stretch the image to new_shape.
scaleup (bool): Whether to allow scaling up. If False, only scale down.
stride (int): Stride for rounding padding.
center (bool): Whether to center the image or align to top-left.
@ -1499,7 +1499,7 @@ class LetterBox:
>>> updated_instances = result["instances"]
"""
def __init__(self, new_shape=(640, 640), auto=False, scaleFill=False, scaleup=True, center=True, stride=32):
def __init__(self, new_shape=(640, 640), auto=False, scale_fill=False, scaleup=True, center=True, stride=32):
"""
Initialize LetterBox object for resizing and padding images.
@ -1509,7 +1509,7 @@ class LetterBox:
Args:
new_shape (Tuple[int, int]): Target size (height, width) for the resized image.
auto (bool): If True, use minimum rectangle to resize. If False, use new_shape directly.
scaleFill (bool): If True, stretch the image to new_shape without padding.
scale_fill (bool): If True, stretch the image to new_shape without padding.
scaleup (bool): If True, allow scaling up. If False, only scale down.
center (bool): If True, center the placed image. If False, place image in top-left corner.
stride (int): Stride of the model (e.g., 32 for YOLOv5).
@ -1517,17 +1517,17 @@ class LetterBox:
Attributes:
new_shape (Tuple[int, int]): Target size for the resized image.
auto (bool): Flag for using minimum rectangle resizing.
scaleFill (bool): Flag for stretching image without padding.
scale_fill (bool): Flag for stretching image without padding.
scaleup (bool): Flag for allowing upscaling.
stride (int): Stride value for ensuring image size is divisible by stride.
Examples:
>>> letterbox = LetterBox(new_shape=(640, 640), auto=False, scaleFill=False, scaleup=True, stride=32)
>>> letterbox = LetterBox(new_shape=(640, 640), auto=False, scale_fill=False, scaleup=True, stride=32)
>>> resized_img = letterbox(original_img)
"""
self.new_shape = new_shape
self.auto = auto
self.scaleFill = scaleFill
self.scale_fill = scale_fill
self.scaleup = scaleup
self.stride = stride
self.center = center # Put the image in the middle or top-left
@ -1573,7 +1573,7 @@ class LetterBox:
dw, dh = new_shape[1] - new_unpad[0], new_shape[0] - new_unpad[1] # wh padding
if self.auto: # minimum rectangle
dw, dh = np.mod(dw, self.stride), np.mod(dh, self.stride) # wh padding
elif self.scaleFill: # stretch
elif self.scale_fill: # stretch
dw, dh = 0.0, 0.0
new_unpad = (new_shape[1], new_shape[0])
ratio = new_shape[1] / shape[1], new_shape[0] / shape[0] # width, height ratios

@ -72,7 +72,7 @@ class RTDETRPredictor(BasePredictor):
def pre_transform(self, im):
"""
Pre-transforms the input images before feeding them into the model for inference. The input images are
letterboxed to ensure a square aspect ratio and scale-filled. The size must be square(640) and scaleFilled.
letterboxed to ensure a square aspect ratio and scale-filled. The size must be square(640) and scale_filled.
Args:
im (list[np.ndarray] |torch.Tensor): Input images of shape (N,3,h,w) for tensor, [(h,w,3) x N] for list.
@ -80,5 +80,5 @@ class RTDETRPredictor(BasePredictor):
Returns:
(list): List of pre-transformed images ready for model inference.
"""
letterbox = LetterBox(self.imgsz, auto=False, scaleFill=True)
letterbox = LetterBox(self.imgsz, auto=False, scale_fill=True)
return [letterbox(image=x) for x in im]

@ -34,7 +34,7 @@ class RTDETRDataset(YOLODataset):
hyp.mixup = hyp.mixup if self.augment and not self.rect else 0.0
transforms = v8_transforms(self, self.imgsz, hyp, stretch=True)
else:
# transforms = Compose([LetterBox(new_shape=(self.imgsz, self.imgsz), auto=False, scaleFill=True)])
# transforms = Compose([LetterBox(new_shape=(self.imgsz, self.imgsz), auto=False, scale_fill=True)])
transforms = Compose([])
transforms.append(
Format(

Loading…
Cancel
Save