Git Product home page Git Product logo

how_to_convert_text_to_images's Introduction

how_to_convert_text_to_images

This is the code for "How to Convert Text to Images - Intro to Deep Learning #16' by Siraj Raval on YouTube

Coding Challenge - Due Date Thursday, May 4th at 12 PM PST

This weeks coding challenge is to use this code to generate non-bird, non-flower images. Pick a captioned image dataset and train your StackGAN model on it! Post at least one image-text pair you generated in your README. If you want suggestions for a dataset try this or this.

Overview

This is the code for this video on Youtube by Siraj Raval as part of the Intro to Deep Learning Nanodegree with Udacity. This model is called StackGAN and this is the code for for reproducing main results in the paper StackGAN: Text to Photo-realistic Image Synthesis with Stacked Generative Adversarial Networks.

Dependencies

python 2.7

TensorFlow 0.11

[Optional] Torch is needed, if use the pre-trained char-CNN-RNN text encoder.

[Optional] skip-thought is needed, if use the skip-thought text encoder.

pip install the following packages:

  • prettytensor
  • progressbar
  • python-dateutil
  • easydict
  • pandas
  • torchfile

Usage

Data

  1. Download our preprocessed char-CNN-RNN text embeddings for birds and flowers and save them to Data/.
  • [Optional] Follow the instructions reedscot/icml2016 to download the pretrained char-CNN-RNN text encoders and extract text embeddings.
  1. Download the birds and flowers image data. Extract them to Data/birds/ and Data/flowers/, respectively.
  2. Preprocess images.
  • For birds: python misc/preprocess_birds.py
  • For flowers: python misc/preprocess_flowers.py

Training

  • The steps to train a StackGAN model on the CUB dataset using our preprocessed data for birds.
    • Step 1: train Stage-I GAN (e.g., for 600 epochs) python stageI/run_exp.py --cfg stageI/cfg/birds.yml --gpu 0
    • Step 2: train Stage-II GAN (e.g., for another 600 epochs) python stageII/run_exp.py --cfg stageII/cfg/birds.yml --gpu 1
  • Change birds.yml to flowers.yml to train a StackGAN model on Oxford-102 dataset using our preprocessed data for flowers.
  • *.yml files are example configuration files for training/testing our models.
  • If you want to try your own datasets, here are some good tips about how to train GAN. Also, we encourage to try different hyper-parameters and architectures, especially for more complex datasets.

Pretrained Model

  • StackGAN for birds trained from char-CNN-RNN text embeddings. Download and save it to models/.
  • StackGAN for flowers trained from char-CNN-RNN text embeddings. Download and save it to models/.
  • StackGAN for birds trained from skip-thought text embeddings. Download and save it to models/ (Just used the same setting as the char-CNN-RNN. We assume better results can be achieved by playing with the hyper-parameters).

Run Demos

  • Run sh demo/flowers_demo.sh to generate flower samples from sentences. The results will be saved to Data/flowers/example_captions/. (Need to download the char-CNN-RNN text encoder for flowers to models/text_encoder/. Note: this text encoder is provided by reedscot/icml2016).
  • Run sh demo/birds_demo.sh to generate bird samples from sentences. The results will be saved to Data/birds/example_captions/.(Need to download the char-CNN-RNN text encoder for birds to models/text_encoder/. Note: this text encoder is provided by reedscot/icml2016).
  • Run python demo/birds_skip_thought_demo.py --cfg demo/cfg/birds-skip-thought-demo.yml --gpu 2 to generate bird samples from sentences. The results will be saved to Data/birds/example_captions-skip-thought/. (Need to download vocabulary for skip-thought vectors to Data/skipthoughts/).

Examples for birds (char-CNN-RNN embeddings), more on youtube:

Examples for flowers (char-CNN-RNN embeddings), more on youtube:

Save your favorite pictures generated by the models since the randomness from noise z and conditioning augmentation makes them creative enough to generate objects with different poses and viewpoints from the same description ๐Ÿ˜ƒ

Credits

The credits for this code go to hanzhanggit. I've merely created a wrapper to get people started.

how_to_convert_text_to_images's People

Contributors

llsourcell 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

how_to_convert_text_to_images's Issues

Error Executing the command lines

Hi,
I have been trying to get this code to run but having the following problems.

After I download all the required files in a folder called data in the main folder.

When I run "python misc/preprocess_birds.py"
the error I get ### bartgs48:how_to_convert_text_to_images research$ python
misc/preprocess_birds.py
Traceback (most recent call last):
File "misc/preprocess_birds.py", line 10, in
from misc.utils import get_image
ImportError: No module named misc.utils

If I try and run the 1st Training command
"python stageI/run_exp.py --cfg stageI/cfg/birds.yml --gpu 0:
I get the following error
_Traceback (most recent call last):
File "stageI/run_exp.py", line 10, in
from misc.datasets import TextDataset
ImportError: No module named misc.datas_ets

I dont know what am I doing wrong. Please help

where to change type

Traceback (most recent call last): |ETA: --:--:--
File "run_exp.py", line 68, in
algo.train()
File "/home/sakshi/Documents/Project-Final/Sample/stageI/trainer.py", line 346, in train
num_embedding)
File "/home/sakshi/Documents/Project-Final/Sample/stageI/misc/datasets.py", line 144, in next_batch
sampled_images = self.transform(sampled_images)
File "/home/sakshi/Documents/Project-Final/Sample/stageI/misc/datasets.py", line 78, in transform
images[i][w1: w1 + self._imsize, h1: h1 + self._imsize, :]
TypeError: slice indices must be integers or None or have an index method

module 'cunn' not found:No LuaRocks module found for cunn

(tensorflow) oslab how_to_convert_text_to_images-master
$ sh demo/flowers_demo.sh
/home/oslab/torch-cl/install/bin/luajit: /home/oslab/torch-cl/install/share/lua/5.1/trepl/init.lua:384: module 'cunn' not found:No LuaRocks module found for cunn
no field package.preload['cunn']
no file '/home/oslab/.luarocks/share/lua/5.1/cunn.lua'
no file '/home/oslab/.luarocks/share/lua/5.1/cunn/init.lua'
no file '/home/oslab/torch-cl/install/share/lua/5.1/cunn.lua'
no file '/home/oslab/torch-cl/install/share/lua/5.1/cunn/init.lua'
no file '/home/oslab/torch/install/share/lua/5.1/cunn.lua'
no file '/home/oslab/torch/install/share/lua/5.1/cunn/init.lua'
no file './cunn.lua'
no file '/home/oslab/torch/install/share/luajit-2.1.0-beta1/cunn.lua'
no file '/usr/local/share/lua/5.1/cunn.lua'
no file '/usr/local/share/lua/5.1/cunn/init.lua'
no file '/home/oslab/.luarocks/lib/lua/5.1/cunn.so'
no file '/home/oslab/torch-cl/install/lib/lua/5.1/cunn.so'
no file '/home/oslab/torch-cl/install/lib/cunn.so'
no file '/home/oslab/torch/install/lib/cunn.so'
no file '/home/oslab/torch/install/lib/lua/5.1/cunn.so'
no file './cunn.so'
no file '/usr/local/lib/lua/5.1/cunn.so'
no file '/usr/local/lib/lua/5.1/loadall.so'
stack traceback:
[C]: in function 'error'
/home/oslab/torch-cl/install/share/lua/5.1/trepl/init.lua:384: in function 'require'
demo/get_embedding.lua:7: in main chunk
[C]: in function 'dofile'
...b/torch-cl/install/lib/luarocks/rocks/trepl/scm-1/bin/th:145: in main chunk
[C]: at 0x00405e90

No luarock module for cunn

(tensorflow) prasanna@prasanna-Inspiron-3558:~/tensorflow_programs/text$ sh demo/birds_demo.sh
/home/prasanna/torch/install/bin/lua: /home/prasanna/torch/install/share/lua/5.2/trepl/init.lua:389: module 'cunn' not found:No LuaRocks module found for cunn
no field package.preload['cunn']
no file '/home/prasanna/.luarocks/share/lua/5.2/cunn.lua'
no file '/home/prasanna/.luarocks/share/lua/5.2/cunn/init.lua'
no file '/home/prasanna/torch/install/share/lua/5.2/cunn.lua'
no file '/home/prasanna/torch/install/share/lua/5.2/cunn/init.lua'
no file '/home/prasanna/torch/install/lib/lua/5.2/cunn.lua'
no file '/home/prasanna/torch/install/lib/lua/5.2/cunn/init.lua'
no file './cunn.lua'
no file '/home/prasanna/.luarocks/lib/lua/5.2/cunn.so'
no file '/home/prasanna/torch/install/lib/lua/5.2/cunn.so'
no file '/home/prasanna/torch/install/lib/cunn.so'
no file '/home/prasanna/torch/install/lib/lua/5.2/loadall.so'
no file './cunn.so'
stack traceback:
[C]: in function 'error'
/home/prasanna/torch/install/share/lua/5.2/trepl/init.lua:389: in function 'require'
demo/get_embedding.lua:7: in main chunk
[C]: in function 'dofile'
...anna/torch/install/lib/luarocks/rocks/trepl/scm-1/bin/th:150: in main chunk
[C]: in ?
Traceback (most recent call last):
File "demo/demo.py", line 15, in
from misc.config import cfg, cfg_from_file
ImportError: No module named 'misc'

Error while converting .txt to .t7 format (example_captions.t7)

I'm trying to convert example_captions.txt to example_captions.t7 using get_embedding.lua file.

Output of th demo/get_embedding.lua

Found Environment variable CUDNN_PATH = /usr/local/cuda-8.0/lib64/libcudnn.so.6	
{
  doc_length : 201
  filenames : ""
  queries : "Data/flowers/example_captions.txt"
  net_txt : "Data/flowers/example_captions.t7"
}
/home/ubuntu/torch/install/bin/luajit: /home/ubuntu/torch/install/share/lua/5.1/torch/File.lua:259: read error: read 0 blocks instead of 1 at /home/ubuntu/torch/pkg/torch/lib/TH/THDiskFile.c:352
stack traceback:
	[C]: in function 'readInt'
	/home/ubuntu/torch/install/share/lua/5.1/torch/File.lua:259: in function 'readObject'
	/home/ubuntu/torch/install/share/lua/5.1/torch/File.lua:409: in function 'load'
	demo/get_embedding.lua:36: in main chunk
	[C]: in function 'dofile'
	...untu/torch/install/lib/luarocks/rocks/trepl/scm-1/bin/th:150: in main chunk
	[C]: at 0x00405d50

I am running this on EC2 Machine, and I've installed torch and required dependencies. I'm not sure about this error.

Note: There exists empty example_captions.t7 file in Data/flowers/

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.