Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pass arguments to RandomScale and RandomCrop in ResizeCropTransform #189

Merged
merged 1 commit into from
Jul 5, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 9 additions & 7 deletions alodataset/transforms.py
Original file line number Diff line number Diff line change
Expand Up @@ -664,7 +664,7 @@ def sample_params(self):
def apply(self, frame: Frame):
assert frame.normalization == "01", "frame should be normalized between 0 and 1 before color modification"

frame = frame**self.gamma
frame = frame ** self.gamma
frame = frame * self.brightness
# change color by applying different coefficients to R, G, and B channels
C = frame.shape[frame.names.index("C")]
Expand Down Expand Up @@ -718,7 +718,7 @@ def __init__(
contrast: tuple = 0.2,
saturation: tuple = 0.2,
hue: tuple = 0.2,
**kwargs
**kwargs,
):
"""Reszie the given frame to the target frame size.

Expand Down Expand Up @@ -856,13 +856,13 @@ class RandomDownScaleCrop(Compose):
"""

def __init__(self, size, preserve_ratio=False, *args, **kwargs):
transforms = [RandomDownScale(size, preserve_ratio), RandomCrop(size)]
transforms = [RandomDownScale(size, preserve_ratio, *args, **kwargs), RandomCrop(size, *args, **kwargs)]
super().__init__(transforms, *args, **kwargs)


class DynamicCropTransform(AloTransform):
""" Crop image to target crop size at chosen position.
"""
"""Crop image to target crop size at chosen position."""

def __init__(self, crop_size, *args, **kwargs):
assert all([isinstance(s, int) for s in crop_size])
self.crop_size = crop_size
Expand Down Expand Up @@ -894,7 +894,9 @@ def apply(self, frame: Frame, center: Union[Tuple[int, int], Tuple[float, float]
bot = top + crop_h - 1

if left < 0 or top < 0 or right > (frame.W - 1) or bot > (frame.H - 1):
raise ValueError(f"Crop coordinates out of image border.\
Image size: {frame.HW}, Crop coordinate (top, left, bot, right): ({top}, {left}, {bot}, {right})")
raise ValueError(
f"Crop coordinates out of image border.\
Image size: {frame.HW}, Crop coordinate (top, left, bot, right): ({top}, {left}, {bot}, {right})"
)

return F.crop(frame, top, left, crop_h, crop_w)