Git Product home page Git Product logo

layout2im's Introduction

layout2im

This repository provides a PyTorch implementation of layout2im, which can generate images from layouts.

Online demo can be found here.

Paper

Image Generation from Layout
Bo Zhao, Lili Meng,Weidong Yin, Leonid Sigal
The Univerisity of British Columbia, Vector Institute
IEEE Conference on Computer Vision and Pattern Recognition (CVPR), 2019, (Oral)

Network Architechture

Overview of our Layout2Im networks for generating images from layout during training.

Usage

1. Creating virtual environment (optional)

All code was developed and tested on Ubuntu 18.04 with Python 3.6 (Anaconda) and PyTorch 1.0.

$ conda create -n layout2im python=3.6
$ conda activate layout2im

2. Install COCO API

$ cd ~
$ git clone https://github.com/cocodataset/cocoapi.git
$ cd cocoapi/PythonAPI/
$ python setup.py install
$ cd ..

3. Cloning the repository

$ git clone [email protected]:zhaobozb/layout2im.git
$ cd layout2im

4. Installing dependencies

$ pip install -r requirements.txt

5. Downloading datasets

To download COCO dataset to datasets/coco:

$ bash scripts/download_coco.sh

To download Visual Genome dataset to datasets/vg and preprocess it:

$ bash scripts/download_vg.sh
$ python scripts/preprocess_vg.py

6. Downloading trained models

Download the trained models to checkpoints/pretrained/.

  1. trained model on COCO
  2. trained model on Visual Genome

7. Testing

Testing on COCO dataset:

$ python layout2im/test.py --dataset coco --coco_dir datasets/coco \
                           --saved_model checkpoints/pretrained/netG_coco.pt \
                           --results_dir checkpoints/pretrained_results_coco

Testing on Visual Genome dataset:

$ python layout2im/test.py --dataset vg --coco_dir datasets/vg \
                           --saved_model checkpoints/pretrained/netG_vg.pt \
                           --results_dir checkpoints/pretrained_results_vg

8. Training

$ python layout2im/train.py

The training script has a number of command-line flags that you can use to configure the model architecture, hyperparameters, and input / output settings:

  • dataset: The dataset to use for training; must be either coco or vg. Default is coco.
  • vg_dir: The directory of visual genome dataset. Default is datsets/vg.
  • coco_dir: The directory of coco dataset. Default is dataset/coco.
  • batch_size: How many pairs of (layout, image) to use in each minibatch during training. . Default is 8.
  • niter: How many iterations will the model be trained. Default is 300000.
  • image_size: The size of images to generate. Default is 64.
  • object_size: The size of object to be resized to. Default is 32.
  • embedding_dim: Integer giving the dimension for the word embedding for objects category. Default is 64.
  • z_dim: Integer giving the dimension for the appearance code for objects. Default is 64.
  • learning_rate: Learning rate to use in Adam optimizer for the generator and discriminators. Default is 1e-4.
  • resi_num: How many residual blocks are used before image decoder. Default is 6.
  • clstm_layers: How many layers are used for convolutional lstm. Default is 3.
  • lambda_img_adv: The weight to assign to adversarial loss for image. Default is 1.0.
  • lambda_obj_adv: The weight to assign to adversarial loss for object. Default is 1.0.
  • lambda_obj_cls: The weight to assign to auxiliary loss for object classification. Default is 1.0.
  • lambda_z_rec: The weight to assign to appearance code regression. Default is 10.0.
  • lambda_img_rec: The weight to assign to image reconstruction loss. Default is 1.0.
  • lambda_kl: The weight to assign to KL divergence. Default is 0.01.
  • resume_iter: Which iteration to resume from; must be either l, s or the integer of previously saved iteration. l means training from latest saved model, s means training from scratch. Default is s.
  • log_step: How many steps to print log information. Default is 10.
  • tensorboard_step: How many steps to update tensorboard. Default is 100.
  • save_step: How many steps to save models. Default is 1000.
  • use_tensorboard: Whether to use tensorboard. Default is true.

Results

1. Images generated from layouts

2. Diverse results generated from the same layout

3. Examples of interactive image generation

Citation

If you find this code useful in your research then please cite

@inproceedings{zhaobo2019layout2im,
  title={Image Generation from Layout},
  author={Zhao, Bo and Meng, Lili and Yin, Weidong and Sigal, Leonid},
  booktitle={CVPR},
  year={2019}
}

Acknowledgement

Our project borrows some source files from sg2im. We thank the authors. This research was partially supported by NSERC Discovery, NSERC DAS, NSERC CFI grants and Mitacs GlobaLink Award. We gratefully acknowledge the support of NVIDIA Corporation with the donation of the Titan V GPU used for this research.

layout2im's People

Contributors

zhaobozb avatar

Watchers

James Cloos avatar paper2code - bot avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.