Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
OpenDAS
vision
Commits
20414024
"projects/vscode:/vscode.git/clone" did not exist on "e4a329814978934b2fda8fb92c2c14ebb42fa0b2"
Commit
20414024
authored
Nov 24, 2017
by
Alykhan Tejani
Committed by
Francisco Massa
Nov 24, 2017
Browse files
add scale and ratio params to RandomResizedCrop.get_params (#345)
parent
aae0dc65
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
6 additions
and
4 deletions
+6
-4
torchvision/transforms/transforms.py
torchvision/transforms/transforms.py
+6
-4
No files found.
torchvision/transforms/transforms.py
View file @
20414024
...
...
@@ -342,11 +342,13 @@ class RandomResizedCrop(object):
self
.
ratio
=
ratio
@
staticmethod
def
get_params
(
img
):
def
get_params
(
img
,
scale
,
ratio
):
"""Get parameters for ``crop`` for a random sized crop.
Args:
img (PIL Image): Image to be cropped.
scale (tuple): range of size of the origin size cropped
ratio (tuple): range of aspect ratio of the origin aspect ratio cropped
Returns:
tuple: params (i, j, h, w) to be passed to ``crop`` for a random
...
...
@@ -354,8 +356,8 @@ class RandomResizedCrop(object):
"""
for
attempt
in
range
(
10
):
area
=
img
.
size
[
0
]
*
img
.
size
[
1
]
target_area
=
random
.
uniform
(
*
self
.
scale
)
*
area
aspect_ratio
=
random
.
uniform
(
*
self
.
ratio
)
target_area
=
random
.
uniform
(
*
scale
)
*
area
aspect_ratio
=
random
.
uniform
(
*
ratio
)
w
=
int
(
round
(
math
.
sqrt
(
target_area
*
aspect_ratio
)))
h
=
int
(
round
(
math
.
sqrt
(
target_area
/
aspect_ratio
)))
...
...
@@ -382,7 +384,7 @@ class RandomResizedCrop(object):
Returns:
PIL Image: Randomly cropped and resize image.
"""
i
,
j
,
h
,
w
=
self
.
get_params
(
img
)
i
,
j
,
h
,
w
=
self
.
get_params
(
img
,
self
.
scale
,
self
.
ratio
)
return
F
.
resized_crop
(
img
,
i
,
j
,
h
,
w
,
self
.
size
,
self
.
interpolation
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment