.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "build/examples_datasets/cityscapes.py" .. LINE NUMBERS ARE GIVEN BELOW. .. only:: html .. note:: :class: sphx-glr-download-link-note Click :ref:`here ` to download the full example code .. rst-class:: sphx-glr-example-title .. _sphx_glr_build_examples_datasets_cityscapes.py: 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. .. image:: https://www.cityscapes-dataset.com/wordpress/wp-content/uploads/2015/07/stuttgart02-2040x500.png :width: 600 px Prepare the dataset ------------------- Please login and download the files `gtFine_trainvaltest.zip` and `leftImg8bit_trainvaltest.zip` to the current folder: +---------------------------------------+--------+ | File name | Size | +=======================================+========+ | gtFine_trainvaltest.zip | 253 MB | +---------------------------------------+--------+ | leftImg8bit_trainvaltest.zip | 12 GB | +---------------------------------------+--------+ Then run this script: :download:`Download script: cityscapes.py<../../../scripts/datasets/cityscapes.py>` .. code-block:: bash python cityscapes.py .. GENERATED FROM PYTHON SOURCE LINES 37-42 How to load the dataset ----------------------- Loading images and labels from Cityscapes is straight-forward with GluonCV's dataset utility: .. GENERATED FROM PYTHON SOURCE LINES 42-50 .. code-block:: default from gluoncv.data import CitySegmentation train_dataset = CitySegmentation(split='train') val_dataset = CitySegmentation(split='val') print('Training images:', len(train_dataset)) print('Validation images:', len(val_dataset)) .. rst-class:: sphx-glr-script-out Out: .. code-block:: none 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 .. GENERATED FROM PYTHON SOURCE LINES 51-54 Get the first sample -------------------- .. GENERATED FROM PYTHON SOURCE LINES 54-62 .. code-block:: default 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.save('mask.png') .. GENERATED FROM PYTHON SOURCE LINES 63-66 Visualize data and label ------------------------ .. GENERATED FROM PYTHON SOURCE LINES 66-79 .. code-block:: default from matplotlib import pyplot as plt import matplotlib.image as mpimg # subplot 1 for img fig = plt.figure() fig.add_subplot(1,2,1) plt.imshow(img.asnumpy().astype('uint8')) # subplot 2 for the mask mmask = mpimg.imread('mask.png') fig.add_subplot(1,2,2) plt.imshow(mmask) # display plt.show() .. image-sg:: /build/examples_datasets/images/sphx_glr_cityscapes_001.png :alt: cityscapes :srcset: /build/examples_datasets/images/sphx_glr_cityscapes_001.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-timing **Total running time of the script:** ( 0 minutes 10.063 seconds) .. _sphx_glr_download_build_examples_datasets_cityscapes.py: .. only :: html .. container:: sphx-glr-footer :class: sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: cityscapes.py ` .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: cityscapes.ipynb ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_