Need help with SPADE?
Click the “chat” button below for chat support from the developer who created it, or find similar developers for support.

About the developer

6.7K Stars 878 Forks Other 103 Commits 84 Opened issues


Semantic Image Synthesis with SPADE

Services available


Need anything else?

Contributors list

License CC BY-NC-SA 4.0 Python 3.6

Semantic Image Synthesis with SPADE

GauGAN demo

New implementation available at imaginaire repository

We have a reimplementation of the SPADE method that is more performant. It is avaiable at Imaginaire

Project page | Paper | Online Interactive Demo of GauGAN | GTC 2019 demo | Youtube Demo of GauGAN

Semantic Image Synthesis with Spatially-Adaptive Normalization.
Taesung Park, Ming-Yu Liu, Ting-Chun Wang, and Jun-Yan Zhu.
In CVPR 2019 (Oral).


Copyright (C) 2019 NVIDIA Corporation.

All rights reserved. Licensed under the CC BY-NC-SA 4.0 (Attribution-NonCommercial-ShareAlike 4.0 International)

The code is released for academic research use only. For commercial use or business inquiries, please contact [email protected].

For press and other inquiries, please contact Hector Marinez


Clone this repo.

git clone

This code requires PyTorch 1.0 and python 3+. Please install dependencies by

pip install -r requirements.txt

This code also requires the Synchronized-BatchNorm-PyTorch rep.

cd models/networks/
git clone
cp -rf Synchronized-BatchNorm-PyTorch/sync_batchnorm .
cd ../../

To reproduce the results reported in the paper, you would need an NVIDIA DGX1 machine with 8 V100 GPUs.

Dataset Preparation

For COCO-Stuff, Cityscapes or ADE20K, the datasets must be downloaded beforehand. Please download them on the respective webpages. In the case of COCO-stuff, we put a few sample images in this code repo.

Preparing COCO-Stuff Dataset. The dataset can be downloaded here. In particular, you will need to download,,, and The images, labels, and instance maps should be arranged in the same directory structure as in

. In particular, we used an instance map that combines both the boundaries of "things instance map" and "stuff label map". To do this, we used a simple script
. Please install
pip install pycocotools
and refer to the script to generate instance maps.

Preparing ADE20K Dataset. The dataset can be downloaded here, which is from MIT Scene Parsing BenchMark. After unzipping the datgaset, put the jpg image files

and png label files
in the same directory.

There are different modes to load images by specifying

along with
. There are options such as
, which resizes the images into square images of side length
and randomly crops to
scales the image to have a short side of length
and crops to
square. To see all modes, please use
python --help
and take a look at
. By default at the training phase, the images are randomly flipped horizontally. To prevent this use

Generating Images Using Pretrained Model

Once the dataset is ready, the result images can be generated using pretrained models.

  1. Download the tar of the pretrained models from the Google Drive Folder, save it in 'checkpoints/', and run

    cd checkpoints
    tar xvf checkpoints.tar.gz
    cd ../
  2. Generate images using the pretrained model.

    python --name [type]_pretrained --dataset_mode [dataset] --dataroot [path_to_dataset]
    is the directory name of the checkpoint file downloaded in Step 1, which should be one of
    , and
    can be one of
    , and
    , and
    , is the path to the dataset. If you are running on CPU mode, append
    --gpu_ids -1
  3. The outputs images are stored at

    by default. You can view them using the autogenerated HTML file in the directory.

Generating Landscape Image using GauGAN

In the paper and the demo video, we showed GauGAN, our interactive app that generates realistic landscape images from the layout users draw. The model was trained on landscape images scraped from We released an online demo that has the same features. Please visit The model weights are not released.

Training New Models

New models can be trained with the following commands.

  1. Prepare dataset. To train on the datasets shown in the paper, you can download the datasets and use

    option, which will choose which subclass of
    is loaded. For custom datasets, the easiest way is to use
    by specifying the option
    --dataset_mode custom
    , along with
    --label_dir [path_to_labels] --image_dir [path_to_images]
    . You also need to specify options such as
    for the number of label classes in the dataset,
    to specify whether it has an unknown label, or
    to denote the dataset doesn't have instance maps.
  2. Train.

# To train on the Facades or COCO dataset, for example.
python --name [experiment_name] --dataset_mode facades --dataroot [path_to_facades_dataset]
python --name [experiment_name] --dataset_mode coco --dataroot [path_to_coco_dataset]

To train on your own custom dataset

python --name [experiment_name] --dataset_mode custom --label_dir [path_to_labels] -- image_dir [path_to_images] --label_nc [num_labels]

There are many options you can specify. Please use

python --help
. The specified options are printed to the console. To specify the number of GPUs to utilize, use
. If you want to use the second and third GPUs for example, use
--gpu_ids 1,2

To log training, use

for Tensorboard. The logs are stored at


Testing is similar to testing pretrained models.

python --name [name_of_experiment] --dataset_mode [dataset_mode] --dataroot [path_to_dataset]


to specify the output directory.
will specify the maximum number of images to generate. By default, it loads the latest checkpoint. It can be changed using

Code Structure

    : the entry point for training and testing.
  • trainers/
    : harnesses and reports the progress of training.
  • models/
    : creates the networks, and compute the losses
  • models/networks/
    : defines the architecture of all models
  • options/
    : creates option lists using
    package. More individuals are dynamically added in other files as well. Please see the section below.
  • data/
    : defines the class for loading images and label maps.


This code repo contains many options. Some options belong to only one specific model, and some options have different default values depending on other options. To address this, the

class dynamically loads and sets options depending on what model, network, and datasets are used. This is done by calling the static method
of various classes. It takes in the
package and modifies the list of options. For example, since COCO-stuff dataset contains a special label "unknown", when COCO-stuff dataset is used, it sets
automatically at
. You can take a look at
def gather_options()
, or
to get a sense of how this works.

VAE-Style Training with an Encoder For Style Control and Multi-Modal Outputs

To train our model along with an image encoder to enable multi-modal outputs as in Figure 15 of the paper, please use

. The model will create
in addition to
and train with KL-Divergence loss.


If you use this code for your research, please cite our papers.

  title={Semantic Image Synthesis with Spatially-Adaptive Normalization},
  author={Park, Taesung and Liu, Ming-Yu and Wang, Ting-Chun and Zhu, Jun-Yan},
  booktitle={Proceedings of the IEEE Conference on Computer Vision and Pattern Recognition},


This code borrows heavily from pix2pixHD. We thank Jiayuan Mao for his Synchronized Batch Normalization code.

We use cookies. If you continue to browse the site, you agree to the use of cookies. For more information on our use of cookies please see our Privacy Policy.