Skip to content

Commit

Permalink
Fix DetectionRandomAffine target-size to be in row-column format (#2012)
Browse files Browse the repository at this point in the history
* Fix the target size to be in row-column format and work with all aspect ratios

Fix the target size to be in row-column format and work with all aspect ratios signed

* added more precise comment and unpacked values for more clarity

* clarified docstring in random_affine as well
  • Loading branch information
cansik authored Jun 5, 2024
1 parent af93ec3 commit 9e8efe0
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions src/super_gradients/training/transforms/transforms.py
Original file line number Diff line number Diff line change
Expand Up @@ -609,7 +609,7 @@ class DetectionRandomAffine(AbstractDetectionTransform, LegacyDetectionTransform
(center-translate, center+translate)
:param scales: Values for random rescale, when float the random values are drawn uniformly from (1-scales, 1+scales)
:param shear: Degrees for random shear, when float the random values are drawn uniformly from (-shear, shear)
:param target_size: Desired output shape.
:param target_size: Desired output shape tuple formatted as (rows, cols).
:param filter_box_candidates: Whether to filter out transformed bboxes by edge size, area ratio, and aspect ratio (default=False).
:param wh_thr: Edge size threshold when filter_box_candidates = True.
Bounding oxes with edges smaller than this values will be filtered out.
Expand Down Expand Up @@ -660,7 +660,7 @@ def apply_to_sample(self, sample: DetectionSample) -> DetectionSample:
targets=targets,
targets_seg=None,
crowd_targets=crowd_targets,
target_size=self.target_size or tuple(reversed(sample.image.shape[:2])),
target_size=self.target_size or tuple(sample.image.shape[:2]),
degrees=self.degrees,
translate=self.translate,
scales=self.scale,
Expand Down Expand Up @@ -1483,7 +1483,7 @@ def random_affine(
:param img: Input image of shape [h, w, c]
:param targets: Input target
:param targets_seg: Targets derived from segmentation masks
:param target_size: Desired output shape
:param target_size: Desired output shape tuple formatted as (rows, cols).
:param degrees: Degrees for random rotation, when float the random values are drawn uniformly
from (-degrees, degrees).
:param translate: Translate size (in pixels) for random translation, when float the random values
Expand All @@ -1510,7 +1510,8 @@ def random_affine(

M = get_affine_matrix(img.shape[:2], target_size, degrees, translate, scales, shear)

img = cv2.warpAffine(img, M, dsize=target_size, borderValue=(border_value, border_value, border_value))
rows, cols = target_size[:2]
img = cv2.warpAffine(img, M, dsize=(cols, rows), borderValue=(border_value, border_value, border_value))

# Transform label coordinates
if len(targets) > 0:
Expand Down

0 comments on commit 9e8efe0

Please sign in to comment.