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
7499851f
Unverified
Commit
7499851f
authored
Apr 01, 2020
by
Philip Meier
Committed by
GitHub
Apr 01, 2020
Browse files
remove compability for sys.version < 3.5 (#2037)
parent
68fe4518
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
6 additions
and
43 deletions
+6
-43
test/test_datasets_utils.py
test/test_datasets_utils.py
+1
-7
test/test_io.py
test/test_io.py
+1
-5
torchvision/datasets/folder.py
torchvision/datasets/folder.py
+1
-6
torchvision/datasets/lsun.py
torchvision/datasets/lsun.py
+1
-7
torchvision/transforms/functional.py
torchvision/transforms/functional.py
+1
-9
torchvision/transforms/transforms.py
torchvision/transforms/transforms.py
+1
-9
No files found.
test/test_datasets_utils.py
View file @
7499851f
...
@@ -8,14 +8,10 @@ import tarfile
...
@@ -8,14 +8,10 @@ import tarfile
import
gzip
import
gzip
import
warnings
import
warnings
from
torch._utils_internal
import
get_file_path_2
from
torch._utils_internal
import
get_file_path_2
from
urllib.error
import
URLError
from
common_utils
import
get_tmp_dir
from
common_utils
import
get_tmp_dir
if
sys
.
version_info
<
(
3
,):
from
urllib2
import
URLError
else
:
from
urllib.error
import
URLError
TEST_FILE
=
get_file_path_2
(
TEST_FILE
=
get_file_path_2
(
os
.
path
.
dirname
(
os
.
path
.
abspath
(
__file__
)),
'assets'
,
'grace_hopper_517x606.jpg'
)
os
.
path
.
dirname
(
os
.
path
.
abspath
(
__file__
)),
'assets'
,
'grace_hopper_517x606.jpg'
)
...
@@ -62,7 +58,6 @@ class Tester(unittest.TestCase):
...
@@ -62,7 +58,6 @@ class Tester(unittest.TestCase):
warnings
.
warn
(
msg
,
RuntimeWarning
)
warnings
.
warn
(
msg
,
RuntimeWarning
)
raise
unittest
.
SkipTest
(
msg
)
raise
unittest
.
SkipTest
(
msg
)
@
unittest
.
skipIf
(
sys
.
version_info
<
(
3
,),
"Python2 doesn't raise error"
)
def
test_download_url_dont_exist
(
self
):
def
test_download_url_dont_exist
(
self
):
with
get_tmp_dir
()
as
temp_dir
:
with
get_tmp_dir
()
as
temp_dir
:
url
=
"http://github.com/pytorch/vision/archive/this_doesnt_exist.zip"
url
=
"http://github.com/pytorch/vision/archive/this_doesnt_exist.zip"
...
@@ -98,7 +93,6 @@ class Tester(unittest.TestCase):
...
@@ -98,7 +93,6 @@ class Tester(unittest.TestCase):
self
.
assertEqual
(
data
,
'this is the content'
)
self
.
assertEqual
(
data
,
'this is the content'
)
@
unittest
.
skipIf
(
'win'
in
sys
.
platform
,
'temporarily disabled on Windows'
)
@
unittest
.
skipIf
(
'win'
in
sys
.
platform
,
'temporarily disabled on Windows'
)
@
unittest
.
skipIf
(
sys
.
version_info
<
(
3
,),
"Extracting .tar.xz files is not supported under Python 2.x"
)
def
test_extract_tar_xz
(
self
):
def
test_extract_tar_xz
(
self
):
for
ext
,
mode
in
zip
([
'.tar.xz'
],
[
'w:xz'
]):
for
ext
,
mode
in
zip
([
'.tar.xz'
],
[
'w:xz'
]):
with
get_tmp_dir
()
as
temp_dir
:
with
get_tmp_dir
()
as
temp_dir
:
...
...
test/test_io.py
View file @
7499851f
...
@@ -6,15 +6,11 @@ import torchvision.datasets.utils as utils
...
@@ -6,15 +6,11 @@ import torchvision.datasets.utils as utils
import
torchvision.io
as
io
import
torchvision.io
as
io
from
torchvision
import
get_video_backend
from
torchvision
import
get_video_backend
import
unittest
import
unittest
import
sys
import
warnings
import
warnings
from
urllib.error
import
URLError
from
common_utils
import
get_tmp_dir
from
common_utils
import
get_tmp_dir
if
sys
.
version_info
<
(
3
,):
from
urllib2
import
URLError
else
:
from
urllib.error
import
URLError
try
:
try
:
import
av
import
av
...
...
torchvision/datasets/folder.py
View file @
7499851f
...
@@ -4,7 +4,6 @@ from PIL import Image
...
@@ -4,7 +4,6 @@ from PIL import Image
import
os
import
os
import
os.path
import
os.path
import
sys
def
has_file_allowed_extension
(
filename
,
extensions
):
def
has_file_allowed_extension
(
filename
,
extensions
):
...
@@ -119,11 +118,7 @@ class DatasetFolder(VisionDataset):
...
@@ -119,11 +118,7 @@ class DatasetFolder(VisionDataset):
Ensures:
Ensures:
No class is a subdirectory of another.
No class is a subdirectory of another.
"""
"""
if
sys
.
version_info
>=
(
3
,
5
):
classes
=
[
d
.
name
for
d
in
os
.
scandir
(
dir
)
if
d
.
is_dir
()]
# Faster and available in Python 3.5 and above
classes
=
[
d
.
name
for
d
in
os
.
scandir
(
dir
)
if
d
.
is_dir
()]
else
:
classes
=
[
d
for
d
in
os
.
listdir
(
dir
)
if
os
.
path
.
isdir
(
os
.
path
.
join
(
dir
,
d
))]
classes
.
sort
()
classes
.
sort
()
class_to_idx
=
{
classes
[
i
]:
i
for
i
in
range
(
len
(
classes
))}
class_to_idx
=
{
classes
[
i
]:
i
for
i
in
range
(
len
(
classes
))}
return
classes
,
class_to_idx
return
classes
,
class_to_idx
...
...
torchvision/datasets/lsun.py
View file @
7499851f
...
@@ -4,13 +4,7 @@ import os
...
@@ -4,13 +4,7 @@ import os
import
os.path
import
os.path
import
io
import
io
import
string
import
string
import
sys
from
collections.abc
import
Iterable
if
sys
.
version_info
<
(
3
,
3
):
from
collections
import
Iterable
else
:
from
collections.abc
import
Iterable
import
pickle
import
pickle
from
.utils
import
verify_str_arg
,
iterable_to_str
from
.utils
import
verify_str_arg
,
iterable_to_str
...
...
torchvision/transforms/functional.py
View file @
7499851f
import
torch
import
torch
import
sys
import
math
import
math
from
PIL
import
Image
,
ImageOps
,
ImageEnhance
,
__version__
as
PILLOW_VERSION
from
PIL
import
Image
,
ImageOps
,
ImageEnhance
,
__version__
as
PILLOW_VERSION
try
:
try
:
...
@@ -9,16 +8,9 @@ except ImportError:
...
@@ -9,16 +8,9 @@ except ImportError:
import
numpy
as
np
import
numpy
as
np
from
numpy
import
sin
,
cos
,
tan
from
numpy
import
sin
,
cos
,
tan
import
numbers
import
numbers
import
collections
from
collections
.abc
import
Sequence
,
Iterable
import
warnings
import
warnings
if
sys
.
version_info
<
(
3
,
3
):
Sequence
=
collections
.
Sequence
Iterable
=
collections
.
Iterable
else
:
Sequence
=
collections
.
abc
.
Sequence
Iterable
=
collections
.
abc
.
Iterable
def
_is_pil_image
(
img
):
def
_is_pil_image
(
img
):
if
accimage
is
not
None
:
if
accimage
is
not
None
:
...
...
torchvision/transforms/transforms.py
View file @
7499851f
import
torch
import
torch
import
math
import
math
import
sys
import
random
import
random
from
PIL
import
Image
from
PIL
import
Image
try
:
try
:
...
@@ -10,18 +9,11 @@ except ImportError:
...
@@ -10,18 +9,11 @@ except ImportError:
import
numpy
as
np
import
numpy
as
np
import
numbers
import
numbers
import
types
import
types
import
collections
from
collections
.abc
import
Sequence
,
Iterable
import
warnings
import
warnings
from
.
import
functional
as
F
from
.
import
functional
as
F
if
sys
.
version_info
<
(
3
,
3
):
Sequence
=
collections
.
Sequence
Iterable
=
collections
.
Iterable
else
:
Sequence
=
collections
.
abc
.
Sequence
Iterable
=
collections
.
abc
.
Iterable
__all__
=
[
"Compose"
,
"ToTensor"
,
"ToPILImage"
,
"Normalize"
,
"Resize"
,
"Scale"
,
"CenterCrop"
,
"Pad"
,
__all__
=
[
"Compose"
,
"ToTensor"
,
"ToPILImage"
,
"Normalize"
,
"Resize"
,
"Scale"
,
"CenterCrop"
,
"Pad"
,
"Lambda"
,
"RandomApply"
,
"RandomChoice"
,
"RandomOrder"
,
"RandomCrop"
,
"RandomHorizontalFlip"
,
"Lambda"
,
"RandomApply"
,
"RandomChoice"
,
"RandomOrder"
,
"RandomCrop"
,
"RandomHorizontalFlip"
,
...
...
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