Teach you to play with the torch hand in hand

Learn wang Feng to write words, automatic chat robot, image coloring, image generation, look at pictures and speak, generate subtitles

\

\

\

Authors: Xiao Zhe, Li Wei, Xiao CAI, July. Description: this tutorial is produced by the July online teaching assistant team and the July online deep learning online class. If you have any questions, please add Q group communication: 472899334. To explore the principles behind the experiment, see Deep Learning Online Classes. Date: October 12, 2016. \

\

\

preface

After the release of our tutorial on van Gogh painting, on the 7th day of the National Day, hundreds of friends began to try one by one, showing a sense of nationwide DL and nationwide experiment. Especially from DL XiaoCai classmate of class, the National Day 7 day 10 open experiment, and the ten simple tutorial experiments (including automated bot) released on the community: ask.julyedu.com/explore/cat… . Praise.

In order for everyone (yes, everyone, blogs, tutorials, and courses) to play with, this tutorial focuses on the torch environment (because in our experience, once the environment is set up, the experiments are pretty smooth), based on CAI’s simple tutorial. In addition, everything that can be thought of, done, and written down (even a sudo-i command) has been written out in great detail so that everyone can play, infinitely lowering the threshold of experimentation for beginners.

Still, welcome more friends to do experiments with us and play together. Including seven experiments to paint like Van Gogh: Van Gogh painting, text generation, automatic chatbot, image coloring, image generation, look AT pictures and speak, subtitle generation. Within this year 2016, you will receive 100 class tickets if you perform any of these seven experiments and post your experience on twitter AT @researcher July. And 100 class tickets.

In addition, we will explain the principles behind the experiments in our deep learning online class, so that you can know more about them.

\

\

First, preparation

1) Torch introduction

Torch, a scientific computing framework backed by machine learning algorithms, has been around for a decade, but it really took off when Facebook opened up a number of deep learning modules and extensions for Torch. Another special feature of Torch is its use of Lua, a programming language that has been used to develop video games.

Torch’s advantages:

  • Simple model building
  • Highly modular
  • Fast and efficient GPU support
  • Access C through LuaJIT
  • Numerical optimization program
  • Interface that can be embedded in the backend of iOS, Android, and FPGA

* information sources – www.leiphone.com/news/201608…

2. System description

This tutorial is based on the Ubuntu14.04 system, and it will teach you how to draw with DL. GTX 1070 CUDA 8.0 TensorFlow GPU version

3. Catalogue of experiments

(1) Text generation

(2) Automatic chat

(3) Image coloring

(4) Image generation

(5) Look at the pictures and speak

(6) Subtitle generation

\

\

2. Build the Torch

L making reference site: https://github.com/torch/torch7

L build torch7 website: http://torch.ch/docs/getting-started.html

Steps:

1. I assume that you have installed NVIDIA GPU driver and CUDA, CUDNN, if you have not installed, please see how to learn Van Gogh Painting using DL: GTX 1070 CUDA 8.0 TensorFlow GPU Version

2. In the Ubuntu terminal window, enter:

All the following commands are executed as user root

Apt-get update (apt-get update)

3, open build Torch7 website

\

git clone Github.com/torch/distr…~/torch –recursive (clone torch to ~/torch file)

cd ~/torch; bash install-deps; (Run install-deps)

./install.sh (Run the program)

\

Bashrc source ~/.bashrc (Ubuntu14.04)

Source ~/.zshrc

******* If the reader is using Lua5.2, perform the following, if not, skip *******

\

The first one is ignored by Git because it was downloaded at the start of the build

CD ~/torch (enter the torch file)

./clean.sh (Run clean.sh)

TORCH_LUA_VERSION=LUA52./install.sh

* * * * * * * * * * * * * * * * * end * * * * * * * * * * * * * * * * * * * * * * * * *

\

Luarocks install image (image)

Luarocks list (list luarocks installed packages, check whether the installation is successful)

\

Th (test whether torch7 can be used, if the logo like above appears, it can be used)

4. The author failed to add torch7’s environment variable to PATH during the installation process. The solution is as follows:

\

On the terminal, enter vi /etc/profile

After entering the file, add the following command at the end:

PATH=~/torch/install/bin:$PATH

\

Press Esc and then type: q to exit

Run source /etc/profile (update)

\

\

Three, 7 experiments

1. Text generated

Refer to the tutorial address: https://ask.julyedu.com/question/7405

Reference program: https://www.julyedu.com/video/play/18/130

Reference github:https://github.com/karpathy/char-rnn

L download package

luarocks install nngraph

luarocks install optim

luarocks install nn

L If a GPU is used, install the following packages

luarocks install cutorch

luarocks install cunn

L Download the char-rnn package

git clone –recursive https://github.com/karpathy/char-rnn****

cd char-rnn;

L Download the template (.txt file) you want to generate, such as 300 Tang Poems, Wang Feng lyrics, Han Han novels…

L Use cp command and mv command, the downloaded. TXT file overwrite data/tinyshakespeare input.txt

L training


Th train. Lua — Dataset 20000 –hiddenSize 100-data_DIR data/ Tinyshakespeare-RNn_SIZE 512-NUM_Layers 2-dropout 0.5

L generated

Th sample.lua CV/lm_LSTM_epoch (-gpuID-1) -gpuID-1 (-gpuID-1)

\

\

\

2. Automatic chatbot

Reference tutorial address: https://ask.julyedu.com/question/7410 (this tutorial basic content refer to the above address, you can directly go in to see)

Reference course: Online deep learning course in July

See Github: github.com/rustch3n/ch…

L Environment package download

sudo ~/torch/install/bin/luarocks install nn

sudo ~/torch/install/bin/luarocks install rnn

sudo ~/torch/install/bin/luarocks install async

L Download the code and corpus ****

Git clone git clone – recursive — recursive https://github.com/rustcbf/chatbot-zh-torch7 # code https://github.com/rustcbf/dgk_lost_conv # # corpora git clone — recursive https://github.com/chenb67/neuralconvo was improved, the above two in the source code For reference

L Select **** for corpus

Corpus In addition to the corpus provided above, CD dgk_lost_conv # reference cvgen. Py Python toraw.py a.cov B.txt CD chatbot-zh-torch7 At first, the author directly used Xiaohuangji50W_fencia.conv (estimated to be the little yellow chicken chatbot corpus with 50W data), but later the training time felt too long, so the author provided a small sample instead. The code in line 18 of Cornell_Movie_dialogs. lua is not recommended to be modified, because the author does not work well in the small sample provided by the author, and the data should not be processed. Download the template (.txt file) you want to generate, such as 300 Tang Poems, Wang Feng lyrics, Han Han novels…

L training

Th train. Lua (the author was prompted that memory was insufficient during the experiment. Lua –dataset 20000 –hiddenSize 100) # cuda, –opencl, –hiddenSize T7,model. T7, and vocab.t7 are generated

L began to

Modify eval. Lua to add \ after the source code

print(“\nType a sentence and hit enter to submit.”)

print(“CTRL+C then enter to quit.\n”)

while true do

 io.write(“you> “)

  io.flush()

 io.write(say(io.read()))

end

 

Th eval. Lua # direct command line

At first, the server with 64GB of memory ran 50W of corpus. After running, the results were ok

\

But if the ordinary desktop computer runs 50W corpus, it may be trouble. Because found in the process of training the desktop 8 gb of memory is not enough, then added 8 gb of memory, 16 gb of memory is not enough, but even the best had to give up part of the corpus, into the corpus of 20 w, but because of corpora, training the bot effect than 50 w materials training the effect is good, may force you to export the dirty.

\

\

3. Image coloring

Refer to the tutorial address: ask.julyedu.com/question/74…

Reference github:https://github.com/satoshiiizuka/siggraph2016_colorization

L Environment package download

sudo ~/torch/install/bin/luarocks install nn

sudo ~/torch/install/bin/luarocks install image

sudo ~/torch/install/bin/luarocks install nngraph

L Download model

./download_model.sh

L perform

Th colorize.lua *** (black and white image address) *** (generate image store address)

Example: th colorize.lua ansel_colorado_1941.png ansel_colorado_1941_out-png

\

\

\

4. Image generation

Refer to the tutorial address: ask.julyedu.com/question/74…

Reference github:https://github.com/soumith/dcgan.torch

L Environment package download

sudo ~/torch/install/bin/luarocks install optnet sudo ~/torch/install/bin/luarocks install display sudo ~ / torch/install/bin/luarocks install cudnn (GPU) sudo ~ / torch/install/bin/luarocks install https://raw.githubusercontent.com/szym/display/master/display-scm-0.rockspec#

L Download model

https://github.com/soumith/lfs/raw/master/dcgan.torch/celebA_25_net_G.t7

https://github.com/soumith/lfs/raw/master/dcgan.torch/bedrooms_4_net_G.t7

L perform

CD dcgan.torch GPU =0 batchSize=64 net= celeba_25_net_g.t7 th generate. Lua # CPU batchSize= 1 batchSize=64 Net = celeba_25_net_g.t7 th generate. Lua # CPU run

支那

支那

\

\

5. Look and speak

Refer to the tutorial address: https://ask.julyedu.com/question/7413

Reference github:https://github.com/karpathy/neuraltalk2

Environment Package Download

sudo ~/torch/install/bin/luarocks install nn sudo ~/torch/install/bin/luarocks install nngraph sudo ~ / torch/install/bin/luarocks install image sudo ~ / torch/install/bin/luarocks install sudo hdf5 # this is also a must ~ / torch/install/bin/luarocks install loadcaffe download model

No installation of gpu classmates can ignore the following command sudo ~ / torch/install/bin/luarocks install cutorch sudo ~ / torch/install/bin/luarocks install cunn

L Model download

http://cs.stanford.edu/people/karpathy/neuraltalk2/checkpoint_v1.zip

L Prepare pictures

CD neuraltalk2 mkdir images #

L Generate a picture description

T7_cpu.t7 -image_folder./images/ # Add parameter -num_images T7_cpu.t7-image_folder./images/ -gpuID-1 # CD vis Python -m SimpleHTTPServer # Visit http://localhost:8000 after startup

\

\

\

6. Subtitle generation

Refer to the tutorial address: https://ask.julyedu.com/question/7411

Reference github:https://github.com/jcjohnson/densecap

L Environment package download

Luarocks install nn Luarocks install image Luarocks install Lua-cjson Luarocks install raw.githubusercontent. … kspec luarocks install raw.githubusercontent. … Luarocks install cunn Luarocks install cudnn. Cunn luarocks install cudnn luarocks install cudnn

L Model download

sh scripts/download_pretrained_model.sh

L Modify code

In line 29 of run_model.lua code, modify the Model location

L run

Lua -input_image imgs/elephant.jpg – gpu-1 Gpu run th run_model.lua -input_image imgs/elephant.jpg

L View effect

CD vis python -m SimpleHTTPServer 8181 visit: http://localhost:8181/view_results.html

For example, given a picture, the system automatically generates the caption: a man riding a bicycle, wearing a white T-shirt..

\

\

Afterword.

Continue to play together later.

Released online in July, October 12, 2016.