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
6eac421c
Commit
6eac421c
authored
Mar 20, 2019
by
Michał Zientkiewicz
Committed by
Francisco Massa
Mar 20, 2019
Browse files
Aspect ratio is now sampled from a logarithmic distribution. (#799)
Signed-off-by:
Michal Zientkiewicz
<
michalz@nvidia.com
>
parent
69382912
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
15 additions
and
8 deletions
+15
-8
torchvision/transforms/transforms.py
torchvision/transforms/transforms.py
+15
-8
No files found.
torchvision/transforms/transforms.py
View file @
6eac421c
...
@@ -572,24 +572,31 @@ class RandomResizedCrop(object):
...
@@ -572,24 +572,31 @@ class RandomResizedCrop(object):
for
attempt
in
range
(
10
):
for
attempt
in
range
(
10
):
target_area
=
random
.
uniform
(
*
scale
)
*
area
target_area
=
random
.
uniform
(
*
scale
)
*
area
aspect_ratio
=
random
.
uniform
(
*
ratio
)
log_ratio
=
(
math
.
log
(
ratio
[
0
]),
math
.
log
(
ratio
[
1
]))
aspect_ratio
=
math
.
exp
(
random
.
uniform
(
*
log_ratio
))
w
=
int
(
round
(
math
.
sqrt
(
target_area
*
aspect_ratio
)))
w
=
int
(
round
(
math
.
sqrt
(
target_area
*
aspect_ratio
)))
h
=
int
(
round
(
math
.
sqrt
(
target_area
/
aspect_ratio
)))
h
=
int
(
round
(
math
.
sqrt
(
target_area
/
aspect_ratio
)))
if
random
.
random
()
<
0.5
and
min
(
ratio
)
<=
(
h
/
w
)
<=
max
(
ratio
):
w
,
h
=
h
,
w
if
w
<=
img
.
size
[
0
]
and
h
<=
img
.
size
[
1
]:
if
w
<=
img
.
size
[
0
]
and
h
<=
img
.
size
[
1
]:
i
=
random
.
randint
(
0
,
img
.
size
[
1
]
-
h
)
i
=
random
.
randint
(
0
,
img
.
size
[
1
]
-
h
)
j
=
random
.
randint
(
0
,
img
.
size
[
0
]
-
w
)
j
=
random
.
randint
(
0
,
img
.
size
[
0
]
-
w
)
return
i
,
j
,
h
,
w
return
i
,
j
,
h
,
w
# Fallback
# Fallback to central crop
w
=
min
(
img
.
size
[
0
],
img
.
size
[
1
])
in_ratio
=
img
.
size
[
0
]
/
img
.
size
[
1
]
i
=
(
img
.
size
[
1
]
-
w
)
//
2
if
(
in_ratio
<
min
(
ratio
)):
w
=
img
.
size
[
0
]
h
=
w
/
min
(
ratio
)
elif
(
in_ratio
>
max
(
ratio
)):
h
=
img
.
size
[
1
]
w
=
h
*
max
(
ratio
)
else
:
# whole image
w
=
img
.
size
[
0
]
h
=
img
.
size
[
1
]
i
=
(
img
.
size
[
1
]
-
h
)
//
2
j
=
(
img
.
size
[
0
]
-
w
)
//
2
j
=
(
img
.
size
[
0
]
-
w
)
//
2
return
i
,
j
,
w
,
w
return
i
,
j
,
h
,
w
def
__call__
(
self
,
img
):
def
__call__
(
self
,
img
):
"""
"""
...
...
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