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
867e5b4e
Commit
867e5b4e
authored
Jun 29, 2019
by
Ross Taylor
Committed by
Soumith Chintala
Jun 29, 2019
Browse files
Automatic extraction for Cityscapes Dataset (#1066)
* Automatic unzip logic * add new line end of file
parent
05ba3f53
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
20 additions
and
2 deletions
+20
-2
torchvision/datasets/cityscapes.py
torchvision/datasets/cityscapes.py
+20
-2
No files found.
torchvision/datasets/cityscapes.py
View file @
867e5b4e
import
json
import
json
import
os
import
os
from
collections
import
namedtuple
from
collections
import
namedtuple
import
zipfile
from
.vision
import
VisionDataset
from
.vision
import
VisionDataset
from
PIL
import
Image
from
PIL
import
Image
...
@@ -125,8 +126,19 @@ class Cityscapes(VisionDataset):
...
@@ -125,8 +126,19 @@ class Cityscapes(VisionDataset):
' or "color"'
)
' or "color"'
)
if
not
os
.
path
.
isdir
(
self
.
images_dir
)
or
not
os
.
path
.
isdir
(
self
.
targets_dir
):
if
not
os
.
path
.
isdir
(
self
.
images_dir
)
or
not
os
.
path
.
isdir
(
self
.
targets_dir
):
raise
RuntimeError
(
'Dataset not found or incomplete. Please make sure all required folders for the'
image_dir_zip
=
os
.
path
.
join
(
self
.
root
,
'leftImg8bit'
)
+
'_trainvaltest.zip'
' specified "split" and "mode" are inside the "root" directory'
)
if
self
.
mode
==
'gtFine'
:
target_dir_zip
=
os
.
path
.
join
(
self
.
root
,
self
.
mode
)
+
'_trainvaltest.zip'
elif
self
.
mode
==
'gtCoarse'
:
target_dir_zip
=
os
.
path
.
join
(
self
.
root
,
self
.
mode
)
if
os
.
path
.
isfile
(
image_dir_zip
)
and
os
.
path
.
isfile
(
target_dir_zip
):
extract_cityscapes_zip
(
zip_location
=
image_dir_zip
,
root
=
self
.
root
)
extract_cityscapes_zip
(
zip_location
=
target_dir_zip
,
root
=
self
.
root
)
else
:
raise
RuntimeError
(
'Dataset not found or incomplete. Please make sure all required folders for the'
' specified "split" and "mode" are inside the "root" directory'
)
for
city
in
os
.
listdir
(
self
.
images_dir
):
for
city
in
os
.
listdir
(
self
.
images_dir
):
img_dir
=
os
.
path
.
join
(
self
.
images_dir
,
city
)
img_dir
=
os
.
path
.
join
(
self
.
images_dir
,
city
)
...
@@ -189,3 +201,9 @@ class Cityscapes(VisionDataset):
...
@@ -189,3 +201,9 @@ class Cityscapes(VisionDataset):
return
'{}_color.png'
.
format
(
mode
)
return
'{}_color.png'
.
format
(
mode
)
else
:
else
:
return
'{}_polygons.json'
.
format
(
mode
)
return
'{}_polygons.json'
.
format
(
mode
)
def
extract_cityscapes_zip
(
zip_location
,
root
):
zip_file
=
zipfile
.
ZipFile
(
zip_location
,
'r'
)
zip_file
.
extractall
(
root
)
zip_file
.
close
()
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