Prepare Cityscapes dataset.

Cityscapes focuses on semantic understanding of urban street scenes. This tutorial help you to download Cityscapes and set it up for later experiments.

Prepare the dataset

Please login and download the files and to the current folder:

File name


253 MB

12 GB

Then run this script:


How to load the dataset

Loading images and labels from Cityscapes is straight-forward with GluonCV’s dataset utility:

from import CitySegmentation
train_dataset = CitySegmentation(split='train')
val_dataset = CitySegmentation(split='val')
print('Training images:', len(train_dataset))
print('Validation images:', len(val_dataset))


Found 2975 images in the folder /root/.mxnet/datasets/citys/leftImg8bit/train
Found 500 images in the folder /root/.mxnet/datasets/citys/leftImg8bit/val
Training images: 2975
Validation images: 500

Get the first sample

import numpy as np
img, mask = val_dataset[0]
# get pallete for the mask
from gluoncv.utils.viz import get_color_pallete
mask = get_color_pallete(mask.asnumpy(), dataset='citys')'mask.png')

Visualize data and label

from matplotlib import pyplot as plt
import matplotlib.image as mpimg
# subplot 1 for img
fig = plt.figure()
# subplot 2 for the mask
mmask = mpimg.imread('mask.png')
# display

Total running time of the script: ( 0 minutes 6.620 seconds)

Gallery generated by Sphinx-Gallery