Giter Site home page Giter Site logo

sg2layout's Introduction

Scene Graph to Layout

Reimplement part of sg2im in TensorFlow 2.3, and trained it on magazine dataset to generate layout data from scene graph.

Introduction

Scene graph is kind of data structure describing the relationships of different objects. And using scene graph to generate images has made a big breakthrough, e.g. Image Generation from Scene Graphs.

We notice that layout is a useful by-product of sg2im, which is important in the field of graphic design. So, it can be a good idea to use sg2im to generate layout of different design elements, which has been taken as baseline of Neural Design Network.

In this repo we implement this idea using TensorFlow 2.3.

Here we list some generated layouts using this model.

Scene Graph Layout
objects:
["header", "image", "text", "background"]

relationships:
[0, "above", 1]
[1, "above", 2]
[0, "inside", 3]
[1, "inside", 3]
[2, "inside", 3]
layout1
objects:
["header", "image", "text", "image", "background"]

relationships:
[0, "above", 1]
[1, "above", 2]
[3, "above", 0]
[0, "inside", 4]
[1, "inside", 4]
[2, "inside", 4]
[3, "inside", 4]
layout2

Setup

Download dataset (for training) or pre-trained model (for testing) from here.

Move ckpt-100.* to ./ckpt and magazine.zip to ./data.

Unzip magazine.zip if you need to train.

unzip magazine.zip

And the directory tree should be like this:

.
├── LICENSE
├── README.md
├── ckpt
│   ├── ckpt-100.data-00000-of-00001
│   └── ckpt-100.index
├── data
│   ├── magazine
│   └── magazine.zip
├── dataset.py
├── main.py
├── models
│   ├── __init__.py
│   ├── __pycache__
│   ├── graph.py
│   ├── layers.py
│   └── sg2im.py
├── requirements.txt
...

Prepare environment

python3 -m venv venv
source venv/bin/activate
pip install -r requirements.txt

Train

You need to specify data, checkpoint and output directory.

python main.py --mode train --data_dir ./data/magazine --checkpoint_dir %WHERE_YOU_WANT_TO_SAVE_CKPT --output_dir %WHERE_YOU_WANT_TO_SAVE_SAMPLES

Test

You need to specify checkpoint path and output directory.

python main.py --mode test --checkpoint_path ./ckpt/ckpt-100 --output_dir %WHERE_YOU_WANT_TO_SAVE_TEST

Future Work

  • Add more kinds of constrains, like size, between layout elements.
  • Add more features, like image feature extracted from ResNet.
  • Add VAE or GAN to generate diverse layouts for same input graph.

sg2layout's People

Contributors

zhuojg avatar

Stargazers

 avatar

Watchers

 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.