Skip to content
This repository has been archived by the owner on Apr 19, 2023. It is now read-only.

Commit

Permalink
- RandomSizedCrop can now accept an arg to alter the target aspect ratio
Browse files Browse the repository at this point in the history
  • Loading branch information
nasimrahaman committed Sep 20, 2017
1 parent 4bb194e commit 830dba8
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion inferno/io/transform/image.py
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ class RandomSizedCrop(Transform):
with `Scale`.
"""
def __init__(self, ratio_between=None, height_ratio_between=None, width_ratio_between=None,
preserve_aspect_ratio=False, **super_kwargs):
preserve_aspect_ratio=False, relative_target_aspect_ratio=None, **super_kwargs):
"""
Parameters
----------
Expand All @@ -186,6 +186,12 @@ def __init__(self, ratio_between=None, height_ratio_between=None, width_ratio_be
Whether to preserve aspect ratio. If both `height_ratio_between`
and `width_ratio_between` are specified, the former is used if this
is set to True.
relative_target_aspect_ratio : float
Specify the target aspect ratio (W x H) relative to the input image
(i.e. by mapping the input image ratio to 1:1). For instance, if an image
has the size 1024 (H) x 2048 (W), a relative target aspect ratio of 0.5
might yield images of size 1024 x 1024. Note that this only applies if
`preserve_aspect_ratio` is set to False.
super_kwargs : dict
Keyword arguments for the super class.
"""
Expand All @@ -206,6 +212,7 @@ def __init__(self, ratio_between=None, height_ratio_between=None, width_ratio_be
self.height_ratio_between = height_ratio_between
self.width_ratio_between = width_ratio_between
self.preserve_aspect_ratio = preserve_aspect_ratio
self.relative_target_aspect_ratio = relative_target_aspect_ratio

def build_random_variables(self, image_shape):
# Seed RNG
Expand All @@ -216,6 +223,8 @@ def build_random_variables(self, image_shape):
high=self.height_ratio_between[1])
if self.preserve_aspect_ratio:
width_ratio = height_ratio
elif self.relative_target_aspect_ratio is not None:
width_ratio = height_ratio * self.relative_target_aspect_ratio
else:
width_ratio = np.random.uniform(low=self.width_ratio_between[0],
high=self.width_ratio_between[1])
Expand Down

0 comments on commit 830dba8

Please sign in to comment.