GithubHelp home page GithubHelp logo

ashnkumar / sketch-code Goto Github PK

View Code? Open in Web Editor NEW
5.1K 215.0 689.0 2.88 MB

Keras model to generate HTML code from hand-drawn website mockups. Implements an image captioning architecture to drawn source images.

Shell 0.93% Python 99.07%
keras tensorflow image-processing deep-learning augmentation

sketch-code's Introduction

SketchCode

Generating HTML Code from a hand-drawn wireframe

Preview

SketchCode is a deep learning model that takes hand-drawn web mockups and converts them into working HTML code. It uses an image captioning architecture to generate its HTML markup from hand-drawn website wireframes.

For more information, check out this post: Automating front-end development with deep learning

This project builds on the synthetically generated dataset and model architecture from pix2code by Tony Beltramelli and the Design Mockups project from Emil Wallner.

Note: This project is meant as a proof-of-concept; the model isn't (yet) built to generalize to the variability of sketches seen in actual wireframes, and thus its performance relies on wireframes resembling the core dataset.

Setup

Prerequisites

  • Python 3 (not compatible with python 2)
  • pip

Install dependencies

pip install -r requirements.txt

Example Usage

Download the data and pretrained weights:

# Getting the data, 1,700 images, 342mb
git clone https://github.com/ashnkumar/sketch-code.git
cd sketch-code
cd scripts

# Get the data and pretrained weights
sh get_data.sh
sh get_pretrained_model.sh

Converting an example drawn image into HTML code, using pretrained weights:

cd src

python convert_single_image.py --png_path ../examples/drawn_example1.png \
      --output_folder ./generated_html \
      --model_json_file ../bin/model_json.json \
      --model_weights_file ../bin/weights.h5

General Usage

Converting a single image into HTML code, using weights:

cd src

python convert_single_image.py --png_path {path/to/img.png} \
      --output_folder {folder/to/output/html} \
      --model_json_file {path/to/model/json_file.json} \
      --model_weights_file {path/to/model/weights.h5}

Converting a batch of images in a folder to HTML:

cd src

python convert_batch_of_images.py --pngs_path {path/to/folder/with/pngs} \
      --output_folder {folder/to/output/html} \
      --model_json_file {path/to/model/json_file.json} \
      --model_weights_file {path/to/model/weights.h5}

Train the model:

cd src

# training from scratch
# <augment_training_data> adds Keras ImageDataGenerator augmentation for training images
python train.py --data_input_path {path/to/folder/with/pngs/guis} \
      --validation_split 0.2 \
      --epochs 10 \
      --model_output_path {path/to/output/model}
      --augment_training_data 1

# training starting with pretrained model
python train.py --data_input_path {path/to/folder/with/pngs/guis} \
      --validation_split 0.2 \
      --epochs 10 \
      --model_output_path {path/to/output/model} \
      --model_json_file ../bin/model_json.json \
      --model_weights_file ../bin/pretrained_weights.h5 \
      --augment_training_data 1

Evalute the generated prediction using the BLEU score

cd src

# evaluate single GUI prediction
python evaluate_single_gui.py --original_gui_filepath  {path/to/original/gui/file} \
      --predicted_gui_filepath {path/to/predicted/gui/file}

# training starting with pretrained model
python evaluate_batch_guis.py --original_guis_filepath  {path/to/folder/with/original/guis} \
      --predicted_guis_filepath {path/to/folder/with/predicted/guis}

License

The MIT License (MIT)

Copyright (c) 2018 Ashwin Kumar<ash.nkumar@[email protected]>

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

sketch-code's People

Contributors

an-hyeonyoung avatar ashnkumar avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

sketch-code's Issues

installation error

Hi,

I am getting below errors while installing this. Can you please help me in fixing this issue.

C:\sketch-code\sketch-code>pip install -r requirements.txt
Collecting Keras==2.1.2
Using cached Keras-2.1.2-py2.py3-none-any.whl (304 kB)
Collecting tensorflow==2.2.0rc1
Using cached tensorflow-2.2.0rc1-cp38-cp38-win_amd64.whl (459.1 MB)
Collecting nltk==3.2.5
Using cached nltk-3.2.5.tar.gz (1.2 MB)
Collecting opencv-python==3.4.8.29
Using cached opencv_python-3.4.8.29-cp38-cp38-win_amd64.whl (31.1 MB)
Collecting h5py==2.7.1
Using cached h5py-2.7.1.tar.gz (264 kB)
Collecting matplotlib==2.0.2
Using cached matplotlib-2.0.2.tar.gz (53.9 MB)
ERROR: Command errored out with exit status 1:
command: 'c:\users\ratikant\appdata\local\programs\python\python38\python.exe' -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'C:\Users\ratikant\AppData\Local\Temp\pip-install-5g3axj_i\matplotlib\setup.py'"'"'; file='"'"'C:\Users\ratikant\AppData\Local\Temp\pip-install-5g3axj_i\matplotlib\setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(file);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, file, '"'"'exec'"'"'))' egg_info --egg-base 'C:\Users\ratikant\AppData\Local\Temp\pip-pip-egg-info-vvl3p_rm'
cwd: C:\Users\ratikant.sahoo\AppData\Local\Temp\pip-install-5g3axj_i\matplotlib
Complete output (67 lines):
============================================================================
Edit setup.cfg to change the build options

BUILDING MATPLOTLIB
            matplotlib: yes [2.0.2]
                python: yes [3.8.2 (tags/v3.8.2:7b3ab59, Feb 25 2020,
                        23:03:10) [MSC v.1916 64 bit (AMD64)]]
              platform: yes [win32]

REQUIRED DEPENDENCIES AND EXTENSIONS
                 numpy: yes [version 1.18.3]
                   six: yes [using six version 1.14.0]
              dateutil: yes [using dateutil version 2.8.1]
           functools32: yes [Not required]
          subprocess32: yes [Not required]
                  pytz: yes [pytz was not found. pip will attempt to install
                        it after matplotlib.]
                cycler: yes [cycler was not found. pip will attempt to
                        install it after matplotlib.]
               tornado: yes [using tornado version 6.0.4]
             pyparsing: yes [pyparsing was not found. It is required for
                        mathtext support. pip/easy_install may attempt to
                        install it after matplotlib.]
                libagg: yes [pkg-config information for 'libagg' could not
                        be found. Using local copy.]
              freetype: no  [The C/C++ header for freetype (ft2build.h)
                        could not be found.  You may need to install the
                        development package.]
                   png: no  [The C/C++ header for png (png.h) could not be
                        found.  You may need to install the development
                        package.]
                 qhull: yes [pkg-config information for 'qhull' could not be
                        found. Using local copy.]

OPTIONAL SUBPACKAGES
           sample_data: yes [installing]
              toolkits: yes [installing]
                 tests: no  [skipping due to configuration]
        toolkits_tests: no  [skipping due to configuration]

OPTIONAL BACKEND EXTENSIONS
                macosx: no  [Mac OS-X only]
                qt5agg: no  [PyQt5 not found]
                qt4agg: no  [PySide not found; PyQt4 not found]
               gtk3agg: no  [Requires pygobject to be installed.]
             gtk3cairo: no  [Requires cairocffi or pycairo to be installed.]
                gtkagg: no  [Requires pygtk]
                 tkagg: yes [installing; run-time loading from Python Tcl /
                        Tk]
                 wxagg: no  [requires wxPython]
                   gtk: no  [Requires pygtk]
                   agg: yes [installing]
                 cairo: no  [cairocffi or pycairo not found]
             windowing: yes [installing]

OPTIONAL LATEX DEPENDENCIES
                dvipng: no
           ghostscript: no
                 latex: no
               pdftops: no

OPTIONAL PACKAGE DATA
                  dlls: no  [skipping due to configuration]

============================================================================
                        * The following required packages can not be built:
                        * freetype, png
----------------------------------------

ERROR: Command errored out with exit status 1: python setup.py egg_info Check the logs for full command output.

Unable to open file

environment: centos7
python version:3.5.1
All packages in requirements.txt were installed without error.
And files in data/ & bin/ were downloaded.
run scripts :
python3 convert_single_image.py --png_path ../examples/drawn_example1.png --output_folder ./generated_html --model_json_file ../bin/model_json.json --model_weights_file ../bin/weights.h5

raise error below:
Traceback (most recent call last):
File "convert_single_image.py", line 53, in
main()
File "convert_single_image.py", line 49, in main
model_weights_path = model_weights_file)
File "/home/apps/git/sketch-code/src/classes/inference/Sampler.py", line 23, in init
self.model = self.load_model(model_json_path, model_weights_path)
File "/home/apps/git/sketch-code/src/classes/inference/Sampler.py", line 74, in load_model
loaded_model.load_weights(model_weights_path)
File "/root/.local/share/virtualenvs/sketch-code-_Pp_OLh1/lib/python3.5/site-packages/keras/engine/topology.py", line 2616, in load_weights
f = h5py.File(filepath, mode='r')
File "/root/.local/share/virtualenvs/sketch-code-_Pp_OLh1/lib/python3.5/site-packages/h5py/_hl/files.py", line 269, in init
fid = make_fid(name, mode, userblock_size, fapl, swmr=swmr)
File "/root/.local/share/virtualenvs/sketch-code-_Pp_OLh1/lib/python3.5/site-packages/h5py/_hl/files.py", line 99, in make_fid
fid = h5f.open(name, flags, fapl=fapl)
File "h5py/_objects.pyx", line 54, in h5py._objects.with_phil.wrapper
File "h5py/_objects.pyx", line 55, in h5py._objects.with_phil.wrapper
File "h5py/h5f.pyx", line 78, in h5py.h5f.open
OSError: Unable to open file (truncated file: eof = 138280960, sblock->base_addr = 0, stored_eoa = 558939120)

convert_single_image generates the same results regardless of the input

image

image

I tried converting a silly doodle into html, but it generates the same output as drawn_example1.png

used this command

 python convert_single_image.py --png_path rofl.png \
       --output_folder ./generated_html \
       --model_json_file ../bin/model_json.json \
       --model_weights_file ../bin/weights.h5

Turning screenshots to sketches

Hi, we are working on a similar project and we are trying to generate more data by converting additional screenshots to sketches.

If possible, would you mind elaborating on the following part of your blog post?

My final pipeline added one further step, which augmented these images by adding skews, shifts, and rotations to mimic the variability in actual drawn sketches.

We managed to get the contours of a screenshot, but we are having a hard time adding skews, shifts, and rotations to the contours.
Thanks so much and my email is [email protected] just in case

unsupport python 3.6

the ubuntu 16.04 Comes with 3.6,Downgrading is very troublesome

Using TensorFlow backend.
/usr/lib/python3.6/importlib/_bootstrap.py:219: RuntimeWarning: compiletime version 3.5 of module 'tensorflow.python.framework.fast_tensor_util' does not match runtime version 3.6
``

No module named inference.Sampler

This line in convert_single_image.py is causing problems.

from classes.inference.Sampler import *
Traceback (most recent call last):
  File "convert_single_image.py", line 7, in <module>
    from classes.inference.Sampler import *
ImportError: No module named inference.Sampler

Adding new elements to the dataset Images

Hi,
I am trying to add a new component 'Dropdown' to the dataset. Following are the steps performed:

  1. Used opencv to add a new bootstrap element in the images and made changes in the respective gui files.
  2. Included 'dropdown' in the vocab file.

But, the model is still not able to generate dropdown tags for the example images. The validation error also has increased while training the model.

Has anyone else tried to add new elements to the dataset?
Example Image:
515d8294-2e0d-491b-acb0-ecd1edd1dc55

Thanks and Regards,
Karan

[Dataset Added] : 100 + images and their lables

Hi guys ,

I found 100+ hand-drawn wireframe dataset and some wireframes are drawn by myself

How I train model for new wireframe dataset and used them in this project from scratch ?

From beginning of installion of packages to generate HTML code

Thank you :)

Dataset and Pre-trained Model Files Not Accessible

Dataset and the pre-trained model files are not accessible. Getting 403 Forbidden from the server

$ sh get_data.sh mkdir: cannot create directory ‘../data’: File exists --2022-03-18 12:14:57-- http://sketch-code.s3.amazonaws.com/data/all_data.zip Resolving sketch-code.s3.amazonaws.com (sketch-code.s3.amazonaws.com)... 52.217.16.188 Connecting to sketch-code.s3.amazonaws.com (sketch-code.s3.amazonaws.com)|52.217.16.188|:80... connected. HTTP request sent, awaiting response... 403 Forbidden 2022-03-18 12:14:57 ERROR 403: Forbidden.

Algorithm used?

hello, I am referring to ur sketch-code project. May i know what's the name of the algorithm used?

kindly respond soon,

thanks in advance

Is this project active?

Hi all.

I want to help, but I want to know if this project is active. Is this project active?

I can not found any zip file from data folder

Hi, when I execute sh scripts/get_data.sh, then it says , cannot find or open ../data/all_data.zip, ../data/all_data.zip.zip or ../data/all_data.zip.ZIP. and I ready can not found any file from data folder, Then how can I do for this? thank you.

What does "ImagePreprocessor.augment_and_save_images" mean?

Augmentation is used to generate more data? Isn't it? But this function augment_and_save_images does not generate more training data, it just changes the meta data and the data length of result is equal to the length of input data? Is it just used to improve adaptive performance?

Code for making the images look hand-drawn

Hi,

I am not able to find the code for making the images look hand-drawn. Is that code not released? Will it be possible for you to release that pipeline?

Thank you!

ValueError: GRU(reset_after=False) is not compatible with GRU(reset_after=True)

This Error occurred when try to execute even on example png file included in examples folder:-

Traceback (most recent call last):
File "convert_single_image.py", line 53, in
main()
File "convert_single_image.py", line 49, in main
model_weights_path = model_weights_file)
File "/content/drive/My Drive/testp2c/sketch-code/src/classes/inference/Sampler.py", line 23, in init
self.model = self.load_model(model_json_path, model_weights_path)
File "/content/drive/My Drive/testp2c/sketch-code/src/classes/inference/Sampler.py", line 74, in load_model
loaded_model.load_weights(model_weights_path)
File "/usr/local/lib/python3.6/dist-packages/tensorflow/python/keras/engine/training.py", line 2234, in load_weights
hdf5_format.load_weights_from_hdf5_group(f, self.layers)
File "/usr/local/lib/python3.6/dist-packages/tensorflow/python/keras/saving/hdf5_format.py", line 700, in load_weights_from_hdf5_group
layer, weight_values, original_keras_version, original_backend)
File "/usr/local/lib/python3.6/dist-packages/tensorflow/python/keras/saving/hdf5_format.py", line 410, in preprocess_weights_for_loading
return _convert_rnn_weights(layer, weights)
File "/usr/local/lib/python3.6/dist-packages/tensorflow/python/keras/saving/hdf5_format.py", line 571, in _convert_rnn_weights
raise ValueError('%s is not compatible with %s' % types)
ValueError: GRU(reset_after=False) is not compatible with GRU(reset_after=True)

dataset creation

Hi, many thanks for sharing the data and code. how can we take it forward, how can we generate more data apart from synthesised data. can we create same kind of dataset for real time html page. if so, then how can we generate .gui files for that. if you have any resource or any thoughts please do share us.

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.