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
3b8a1403
Unverified
Commit
3b8a1403
authored
Jun 20, 2019
by
Francisco Massa
Committed by
GitHub
Jun 20, 2019
Browse files
Fix TypeError due to float instead of int in RandomResizedCrop.get_params (#1036)
parent
f6262182
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
7 additions
and
3 deletions
+7
-3
test/test_transforms.py
test/test_transforms.py
+5
-1
torchvision/transforms/transforms.py
torchvision/transforms/transforms.py
+2
-2
No files found.
test/test_transforms.py
View file @
3b8a1403
...
@@ -147,10 +147,14 @@ class Tester(unittest.TestCase):
...
@@ -147,10 +147,14 @@ class Tester(unittest.TestCase):
aspect_min
=
max
(
round
(
random
.
random
(),
2
),
epsilon
)
aspect_min
=
max
(
round
(
random
.
random
(),
2
),
epsilon
)
aspect_ratio_range
=
(
aspect_min
,
aspect_min
+
round
(
random
.
random
(),
2
))
aspect_ratio_range
=
(
aspect_min
,
aspect_min
+
round
(
random
.
random
(),
2
))
randresizecrop
=
transforms
.
RandomResizedCrop
(
size
,
scale_range
,
aspect_ratio_range
)
randresizecrop
=
transforms
.
RandomResizedCrop
(
size
,
scale_range
,
aspect_ratio_range
)
_
,
_
,
h
,
w
=
randresizecrop
.
get_params
(
img
,
scale_range
,
aspect_ratio_range
)
i
,
j
,
h
,
w
=
randresizecrop
.
get_params
(
img
,
scale_range
,
aspect_ratio_range
)
aspect_ratio_obtained
=
w
/
h
aspect_ratio_obtained
=
w
/
h
assert
(
min
(
aspect_ratio_range
)
-
epsilon
<=
aspect_ratio_obtained
<=
max
(
aspect_ratio_range
)
+
epsilon
or
assert
(
min
(
aspect_ratio_range
)
-
epsilon
<=
aspect_ratio_obtained
<=
max
(
aspect_ratio_range
)
+
epsilon
or
aspect_ratio_obtained
==
1.0
)
aspect_ratio_obtained
==
1.0
)
assert
isinstance
(
i
,
int
)
assert
isinstance
(
j
,
int
)
assert
isinstance
(
h
,
int
)
assert
isinstance
(
w
,
int
)
def
test_randomperspective
(
self
):
def
test_randomperspective
(
self
):
for
_
in
range
(
10
):
for
_
in
range
(
10
):
...
...
torchvision/transforms/transforms.py
View file @
3b8a1403
...
@@ -652,10 +652,10 @@ class RandomResizedCrop(object):
...
@@ -652,10 +652,10 @@ class RandomResizedCrop(object):
in_ratio
=
img
.
size
[
0
]
/
img
.
size
[
1
]
in_ratio
=
img
.
size
[
0
]
/
img
.
size
[
1
]
if
(
in_ratio
<
min
(
ratio
)):
if
(
in_ratio
<
min
(
ratio
)):
w
=
img
.
size
[
0
]
w
=
img
.
size
[
0
]
h
=
w
/
min
(
ratio
)
h
=
int
(
round
(
w
/
min
(
ratio
)
))
elif
(
in_ratio
>
max
(
ratio
)):
elif
(
in_ratio
>
max
(
ratio
)):
h
=
img
.
size
[
1
]
h
=
img
.
size
[
1
]
w
=
h
*
max
(
ratio
)
w
=
int
(
round
(
h
*
max
(
ratio
)
))
else
:
# whole image
else
:
# whole image
w
=
img
.
size
[
0
]
w
=
img
.
size
[
0
]
h
=
img
.
size
[
1
]
h
=
img
.
size
[
1
]
...
...
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