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
d6c7900d
Commit
d6c7900d
authored
Jul 27, 2018
by
David Wade
Committed by
Soumith Chintala
Jul 27, 2018
Browse files
Use scandir in _find_classes (#557) (#559)
* Use scandir in _find_classes (#557) * fix lint
parent
f1b59075
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
6 additions
and
1 deletion
+6
-1
torchvision/datasets/folder.py
torchvision/datasets/folder.py
+6
-1
No files found.
torchvision/datasets/folder.py
View file @
d6c7900d
...
@@ -4,6 +4,7 @@ from PIL import Image
...
@@ -4,6 +4,7 @@ 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
):
...
@@ -110,7 +111,11 @@ class DatasetFolder(data.Dataset):
...
@@ -110,7 +111,11 @@ class DatasetFolder(data.Dataset):
Ensures:
Ensures:
No class is a subdirectory of another.
No class is a subdirectory of another.
"""
"""
classes
=
[
d
for
d
in
os
.
listdir
(
dir
)
if
os
.
path
.
isdir
(
os
.
path
.
join
(
dir
,
d
))]
if
sys
.
version_info
>=
(
3
,
5
):
# 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
...
...
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