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
c4b86b07
Commit
c4b86b07
authored
Nov 23, 2017
by
Zheng Qin
Committed by
Alykhan Tejani
Nov 23, 2017
Browse files
add tunable crop scale and aspect ratio in RandomSizedCrop (#343)
* add tunable crop scale and aspect ratio in
parent
64862b5a
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
9 additions
and
5 deletions
+9
-5
torchvision/transforms/transforms.py
torchvision/transforms/transforms.py
+9
-5
No files found.
torchvision/transforms/transforms.py
View file @
c4b86b07
...
...
@@ -323,19 +323,23 @@ class RandomVerticalFlip(object):
class
RandomResizedCrop
(
object
):
"""Crop the given PIL Image to random size and aspect ratio.
A crop of random size of
(
0.08 to 1.0) of the original size and a random
aspect ratio of 3/4 to 4/3 of the original aspect ratio is made. This crop
A crop of random size
(default:
of 0.08 to 1.0) of the original size and a random
aspect ratio
(default:
of 3/4 to 4/3
)
of the original aspect ratio is made. This crop
is finally resized to given size.
This is popularly used to train the Inception networks.
Args:
size: expected output size of each edge
scale: range of size of the origin size cropped
ratio: range of aspect ratio of the origin aspect ratio cropped
interpolation: Default: PIL.Image.BILINEAR
"""
def
__init__
(
self
,
size
,
interpolation
=
Image
.
BILINEAR
):
def
__init__
(
self
,
size
,
scale
=
(
0.08
,
1.0
),
ratio
=
(
3.
/
4.
,
4.
/
3.
),
interpolation
=
Image
.
BILINEAR
):
self
.
size
=
(
size
,
size
)
self
.
interpolation
=
interpolation
self
.
scale
=
scale
self
.
ratio
=
ratio
@
staticmethod
def
get_params
(
img
):
...
...
@@ -350,8 +354,8 @@ class RandomResizedCrop(object):
"""
for
attempt
in
range
(
10
):
area
=
img
.
size
[
0
]
*
img
.
size
[
1
]
target_area
=
random
.
uniform
(
0.08
,
1.0
)
*
area
aspect_ratio
=
random
.
uniform
(
3.
/
4
,
4.
/
3
)
target_area
=
random
.
uniform
(
*
self
.
scale
)
*
area
aspect_ratio
=
random
.
uniform
(
*
self
.
ratio
)
w
=
int
(
round
(
math
.
sqrt
(
target_area
*
aspect_ratio
)))
h
=
int
(
round
(
math
.
sqrt
(
target_area
/
aspect_ratio
)))
...
...
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