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
1e369d3a
Unverified
Commit
1e369d3a
authored
Mar 16, 2020
by
NVS Abhilash
Committed by
GitHub
Mar 16, 2020
Browse files
Remove Python2.x code for os.makedirs (#1984)
parent
505cd695
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
12 additions
and
25 deletions
+12
-25
torchvision/datasets/caltech.py
torchvision/datasets/caltech.py
+3
-3
torchvision/datasets/mnist.py
torchvision/datasets/mnist.py
+7
-7
torchvision/datasets/utils.py
torchvision/datasets/utils.py
+2
-15
No files found.
torchvision/datasets/caltech.py
View file @
1e369d3a
...
@@ -4,7 +4,7 @@ import os
...
@@ -4,7 +4,7 @@ import os
import
os.path
import
os.path
from
.vision
import
VisionDataset
from
.vision
import
VisionDataset
from
.utils
import
download_and_extract_archive
,
makedir_exist_ok
,
verify_str_arg
from
.utils
import
download_and_extract_archive
,
verify_str_arg
class
Caltech101
(
VisionDataset
):
class
Caltech101
(
VisionDataset
):
...
@@ -35,7 +35,7 @@ class Caltech101(VisionDataset):
...
@@ -35,7 +35,7 @@ class Caltech101(VisionDataset):
super
(
Caltech101
,
self
).
__init__
(
os
.
path
.
join
(
root
,
'caltech101'
),
super
(
Caltech101
,
self
).
__init__
(
os
.
path
.
join
(
root
,
'caltech101'
),
transform
=
transform
,
transform
=
transform
,
target_transform
=
target_transform
)
target_transform
=
target_transform
)
makedir
_exist_ok
(
self
.
root
)
os
.
makedir
s
(
self
.
root
,
exist_ok
=
True
)
if
not
isinstance
(
target_type
,
list
):
if
not
isinstance
(
target_type
,
list
):
target_type
=
[
target_type
]
target_type
=
[
target_type
]
self
.
target_type
=
[
verify_str_arg
(
t
,
"target_type"
,
(
"category"
,
"annotation"
))
self
.
target_type
=
[
verify_str_arg
(
t
,
"target_type"
,
(
"category"
,
"annotation"
))
...
@@ -148,7 +148,7 @@ class Caltech256(VisionDataset):
...
@@ -148,7 +148,7 @@ class Caltech256(VisionDataset):
super
(
Caltech256
,
self
).
__init__
(
os
.
path
.
join
(
root
,
'caltech256'
),
super
(
Caltech256
,
self
).
__init__
(
os
.
path
.
join
(
root
,
'caltech256'
),
transform
=
transform
,
transform
=
transform
,
target_transform
=
target_transform
)
target_transform
=
target_transform
)
makedir
_exist_ok
(
self
.
root
)
os
.
makedir
s
(
self
.
root
,
exist_ok
=
True
)
if
download
:
if
download
:
self
.
download
()
self
.
download
()
...
...
torchvision/datasets/mnist.py
View file @
1e369d3a
...
@@ -9,7 +9,7 @@ import torch
...
@@ -9,7 +9,7 @@ import torch
import
codecs
import
codecs
import
string
import
string
from
.utils
import
download_url
,
download_and_extract_archive
,
extract_archive
,
\
from
.utils
import
download_url
,
download_and_extract_archive
,
extract_archive
,
\
makedir_exist_ok
,
verify_str_arg
verify_str_arg
class
MNIST
(
VisionDataset
):
class
MNIST
(
VisionDataset
):
...
@@ -129,8 +129,8 @@ class MNIST(VisionDataset):
...
@@ -129,8 +129,8 @@ class MNIST(VisionDataset):
if
self
.
_check_exists
():
if
self
.
_check_exists
():
return
return
makedir
_exist_ok
(
self
.
raw_folder
)
os
.
makedir
s
(
self
.
raw_folder
,
exist_ok
=
True
)
makedir
_exist_ok
(
self
.
processed_folder
)
os
.
makedir
s
(
self
.
processed_folder
,
exist_ok
=
True
)
# download files
# download files
for
url
,
md5
in
self
.
resources
:
for
url
,
md5
in
self
.
resources
:
...
@@ -274,8 +274,8 @@ class EMNIST(MNIST):
...
@@ -274,8 +274,8 @@ class EMNIST(MNIST):
if
self
.
_check_exists
():
if
self
.
_check_exists
():
return
return
makedir
_exist_ok
(
self
.
raw_folder
)
os
.
makedir
s
(
self
.
raw_folder
,
exist_ok
=
True
)
makedir
_exist_ok
(
self
.
processed_folder
)
os
.
makedir
s
(
self
.
processed_folder
,
exist_ok
=
True
)
# download files
# download files
print
(
'Downloading and extracting zip archive'
)
print
(
'Downloading and extracting zip archive'
)
...
@@ -377,8 +377,8 @@ class QMNIST(MNIST):
...
@@ -377,8 +377,8 @@ class QMNIST(MNIST):
"""
"""
if
self
.
_check_exists
():
if
self
.
_check_exists
():
return
return
makedir
_exist_ok
(
self
.
raw_folder
)
os
.
makedir
s
(
self
.
raw_folder
,
exist_ok
=
True
)
makedir
_exist_ok
(
self
.
processed_folder
)
os
.
makedir
s
(
self
.
processed_folder
,
exist_ok
=
True
)
split
=
self
.
resources
[
self
.
subsets
[
self
.
what
]]
split
=
self
.
resources
[
self
.
subsets
[
self
.
what
]]
files
=
[]
files
=
[]
...
...
torchvision/datasets/utils.py
View file @
1e369d3a
...
@@ -43,19 +43,6 @@ def check_integrity(fpath, md5=None):
...
@@ -43,19 +43,6 @@ def check_integrity(fpath, md5=None):
return
check_md5
(
fpath
,
md5
)
return
check_md5
(
fpath
,
md5
)
def
makedir_exist_ok
(
dirpath
):
"""
Python2 support for os.makedirs(.., exist_ok=True)
"""
try
:
os
.
makedirs
(
dirpath
)
except
OSError
as
e
:
if
e
.
errno
==
errno
.
EEXIST
:
pass
else
:
raise
def
download_url
(
url
,
root
,
filename
=
None
,
md5
=
None
):
def
download_url
(
url
,
root
,
filename
=
None
,
md5
=
None
):
"""Download a file from a url and place it in root.
"""Download a file from a url and place it in root.
...
@@ -72,7 +59,7 @@ def download_url(url, root, filename=None, md5=None):
...
@@ -72,7 +59,7 @@ def download_url(url, root, filename=None, md5=None):
filename
=
os
.
path
.
basename
(
url
)
filename
=
os
.
path
.
basename
(
url
)
fpath
=
os
.
path
.
join
(
root
,
filename
)
fpath
=
os
.
path
.
join
(
root
,
filename
)
makedir
_
exist_ok
(
root
)
os
.
makedir
s
(
root
,
exist_ok
=
True
)
# check if file is already present locally
# check if file is already present locally
if
check_integrity
(
fpath
,
md5
):
if
check_integrity
(
fpath
,
md5
):
...
@@ -164,7 +151,7 @@ def download_file_from_google_drive(file_id, root, filename=None, md5=None):
...
@@ -164,7 +151,7 @@ def download_file_from_google_drive(file_id, root, filename=None, md5=None):
filename
=
file_id
filename
=
file_id
fpath
=
os
.
path
.
join
(
root
,
filename
)
fpath
=
os
.
path
.
join
(
root
,
filename
)
makedir
_
exist_ok
(
root
)
os
.
makedir
s
(
root
,
exist_ok
=
True
)
if
os
.
path
.
isfile
(
fpath
)
and
check_integrity
(
fpath
,
md5
):
if
os
.
path
.
isfile
(
fpath
)
and
check_integrity
(
fpath
,
md5
):
print
(
'Using downloaded and verified file: '
+
fpath
)
print
(
'Using downloaded and verified file: '
+
fpath
)
...
...
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