Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cityscapes Dataset Extraction (Follow-up PR to #1066) #1068

Merged
merged 1 commit into from
Jul 1, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 7 additions & 9 deletions torchvision/datasets/cityscapes.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from collections import namedtuple
import zipfile

from .utils import extract_archive
from .vision import VisionDataset
from PIL import Image

Expand Down Expand Up @@ -126,16 +127,19 @@ def __init__(self, root, split='train', mode='fine', target_type='instance',
' or "color"')

if not os.path.isdir(self.images_dir) or not os.path.isdir(self.targets_dir):
image_dir_zip = os.path.join(self.root, 'leftImg8bit') + '_trainvaltest.zip'
if split == 'train_extra':
image_dir_zip = os.path.join(self.root, 'leftImg8bit') + '_trainextra.zip'
else:
image_dir_zip = os.path.join(self.root, 'leftImg8bit') + '_trainvaltest.zip'

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)
extract_archive(from_path=image_dir_zip, to_path=self.root)
extract_archive(from_path=target_dir_zip, to_path=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')
Expand Down Expand Up @@ -201,9 +205,3 @@ def _get_target_suffix(self, mode, target_type):
return '{}_color.png'.format(mode)
else:
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()