Teach you how to play Flappy Bird automatically from start to finish using DQN (full command prompt, GPU+CPU)

\

\

Note: This article is divided into two parts, the first part is the GPU version of the tutorial, the second part is the CPU version of the tutorial, the two tutorials are mainly written by Xiao chur, Li Wei proofread, and the last run is Yenchenlin’s Github open source demo. In case of problems, welcome to add Q group communication: 472899334. And to explore the principles behind the experiments, see this course: Deep Learning Online. Date: October 13th, 2016. \

\

\

preface

In our last tutorial, Learn Wang Feng’s Lyrics in Torch, Chatbot, Image Coloring/Generation, Talk with Pictures, and Subtitle Generation: “Let everyone can play a game, infinitely lower the threshold of beginners’ friends”, that can reduce the difficulty again, for example, some students are not familiar with Linux commands, that is not familiar with Linux commands can not do STH over and over again? But since it is for everyone to play, it should take care of as many people as possible.

This tutorial provides command tips for those unfamiliar with Linux commands to build up. So playing Flappy Bird automatically takes three steps:

  1. Put the game up first, no matter what
  2. After building up, Linux commands follow slowly familiar, familiar, a hundred, build other experimental environment will immediately smooth a lot of
  3. After you’ve achieved a sense of accomplishment and peace of mind, delve deeper into the principles behind the experiment (as, of course, do deep learning online classes).

The Ubuntu 14.04 installation is omitted from this tutorial. If you haven’t installed Ubuntu before, see Part 4.1 of Van Gogh Painting from Start to finish with DL. In addition, this article started with a GPU version only, but for those who do not have a GPU, the second part of this article has a CPU version so that everyone can play it.

Again, welcome more friends to do experiments with us and play together. Eight experiments, including this Flappy Bird: Van Gogh painting, text generation, automated chatbot, image coloring, image generation, Talk with pictures, subtitle generation, Flappy Bird, make any one of these eight experiments this year and 2016 and tweet AT @researcher July, give 100 class tickets. You will receive 100 class vouchers after Posting your experience to ask.julyed.com. \

\

\

\

Part I, tutorial for GPU edition

1.1NVIDIA driver, CUDA, and CUDNN installation

Download the corresponding file for subsequent use, download address:

  • NVIDIA driver www.geforce.cn/drivers (search for the corresponding model)
  • CUDA driver developer.nvidia.com/cuda-toolki… (Search for the corresponding version)
  • CUDNN drive developer.nvidia.com/cudnn

Use the root account for the following operations

Apt-get update (apt-get update)

Apt-get install vim (emacs nano)

Vi /etc/default/grub (enter the GRUB file)

The character login function is enabled

Change quiet to text in the GRUB_CMDLINE_LINUX_DEFAULT=”quiet” line

GRUB_CMDLINE_LINUX_DEFAULT=”text”

Save the exit

Update -grub2

Reboot

1.1.1. Install the NVIDIA Driver Install the NVIDIA Driver

CD /**/**/** (CD to cudA file directory)

Run (install NVIDIA driver, this file requires execution permission, chmod +x NVIDIA- linux-x86_64-367.44.run)

Reboot

Install CUDA. Install CUDA

CD /**/**/** (CD to cudA file directory)

/cuda_8.0.27_linux.run (install CUDA, this file requires permission to execute, in case of permission problems can run chmod +x file name)

! After accept, fill in “n” for the first option (this option lets you choose whether to install NVIDIA Driver, it has already been installed, so you don’t need to), and then “green” all the way.

Vi /etc/default/grub (open grub)

The GUI login function is enabled

Change the text in the GRUB_CMDLINE_LINUX_DEFAULT=”text” line to quiet

Save the exit

Update -grub2

Reboot

Install cuDNN

Tar XVZF cudnn-7.5-linux-x64-v5.1-ga.tgz

Unzip CUDNN and copy the extracted files to the CUDA directory as follows

Sudo cp cuda/include/cudnn.h /usr/local/cuda/include

Sudo cp cuda/lib64/libcudnn* /usr/local/cuda/lib64

Sudo chmod a + r/usr/local/cuda/include/cudnn. H/usr/local/cuda/lib64 / libcudnn * (add permissions)

CUDA Environment Path Adds CUDA Environment variables

Terminal execution

  export LD_LIBRARY_PATH=”$LD_LIBRARY_PATH:/usr/local/cuda/lib64:/usr/local/cuda/extras/CUPTI/lib64″

  export CUDA_HOME=/usr/local/cuda

  export PATH=”$CUDA_HOME/bin:$PATH”  

 

\

1.2, source installation Tensorflow

apt-get install git 

Clone the TensorFlow Repository

Git clone github.com/tensorflow/…

Install Bazel

Install JDK8 Install JDK8

Sudo add-apt-repository ppa: webupd8Team/Java

Sudo apt-get update

Sudo apt-get install oracle-java8-installer

Add Bazel distribution URI as a package source (one time setup)

Echo “deb/arch = amd64 storage.googleapis.com/bazel-apt stable jdk1.8” | sudo tee/etc/apt/sources list. D/bazel. List

The curl bazel. IO/bazel – relea… | sudo apt-key add –

Update and install Bazel

  sudo apt-get update && sudo apt-get install bazel

  sudo apt-get upgrade bazel

1.2.2, Install other dependencies

  sudo apt-get install python-numpy swig python-dev python-wheel python-pip

Configure the installation (note the prompt after Configure, the prompt is given)

./configure (in the TensorFlow directory where the clone is located)

Please specify the location of python. [Default is /usr/bin/python]:

Do you wish to build TensorFlow with Google Cloud Platform support? [y/N] N

No Google Cloud Platform support will be enabled for TensorFlow

Do you wish to build TensorFlow with GPU support? [y/N] y

GPU support will be enabled for TensorFlow

Please specify which gcc nvcc should use as the host compiler. [Default is /usr/bin/gcc]:

Please specify the Cuda SDK version you want to use, e.g. 7.0. [Leave empty to use system default]: 8.0

Please specify the location where CUDA 7.5 Toolkit is installed. Refer to readme. md for more details. [Default is /usr/local/cuda]:

Please specify the cuDNN version you want to use. [Leave empty to use system default]: 5

Please specify the location where cuDNN 5 library is installed. Refer to README.md for more details. [Default is /usr/local/cuda]:

Please specify a list of comma-separated Cuda compute capabilities you want to build with.

You can find the compute capability of your device at: developer.nvidia.com/cuda-gpus.

Please note that each additional compute capability significantly increases your build time and binary size.

[Default is: “3.5, 5.2] : 3.0 (this value depending on the machine configuration, configuration, the higher the value, reference developer.nvidia.com/cuda-gpus#c… , while 3.0 is common)

Setting up Cuda include

Setting up Cuda lib

Setting up Cuda bin

Setting up Cuda nvvm

Setting up CUPTI include

Setting up CUPTI lib64

Configuration finished

Create the PIP package and install it

Bazel build-c opt //tensorflow/tools/pip_package:build_pip_package

  bazel build -c opt –config=cuda //tensorflow/tools/pip_package:build_pip_package

Bazel-bin /tensorflow/tools/pip_package/build_pip_package/TMP /tensorflow_pkg No module named setuptools, apt-get install python-pip, install python-pip

Sudo PIP install/TMP/tensorflow_pkg/tensorflow – 0.11.0 rc0 py2 – none – any. WHL

Setting up TensorFlow for Development

  bazel build -c opt //tensorflow/tools/pip_package:build_pip_package

  bazel build -c opt –config=cuda //tensorflow/tools/pip_package:build_pip_package

  mkdir _python_build

  cd _python_build

ln -s .. /bazel-bin/tensorflow/tools/pip_package/build_pip_package.runfiles/org_tensorflow/* .

ln -s .. /tensorflow/tools/pip_package/* .

  python setup.py develop

Test your first TensorFlow neural net model

  cd tensorflow/models/image/mnist

  export LD_LIBRARY_PATH=”$LD_LIBRARY_PATH:/usr/local/cuda/lib64:/usr/local/cuda/extras/CUPTI/lib64″

Export CUDA_HOME=/usr/local/cuda export CUDA_HOME=/usr/local/cuda

Python AttributeError: Type object ‘NewBase’ has no attribute ‘is_abstract’ Sudo PIP install six –upgrade — target=”/usr/lib/python2.7/dist-packages”)

 

\

1.3 Install OpenCV

Download OpenCV Download OpenCV

The browser opens opencv.org/

Download the Linux OpenCV on the right

CD to the download directory

Unzip opencv – 2.4.13. Zip

CD opencv – 2.4.13

  mkdir release  

Sudo apt-get install build-essential cmake libgtk2.0-dev pkg-config python-dev python-numpy libavcodec-dev libavformat-dev libswscale-dev

  cd release  

  cmake -D CMAKE_BUILD_TYPE=RELEASE -D CMAKE_INSTALL_PREFIX=/usr/local ..  

  sudo make install  

 

\

1.4. Download FlappyBird

Download DeepLearningFlappyBird

Git clone — recursive github.com/yenchenlin/…

 

\

Install PyGame

Install PyGame Installs PyGame

Wget www.pygame.org/ftp/pygame-… Download pygame

Sudo apt-get install libsdl1.2-dev sudo apt-get install libsdl1.2-dev

Sudo apt-get install libsdl-image1.2-dev libsdl-mixer1.2-dev libsDL-ttf2.0-dev libsdl-gfx1.2-dev libsdl-net1.2-dev sudo apt-get install libsdl-image1.2-dev libsdl-ttf2.0-dev libsdl-gfx1.2-dev libsdl-net1.2-dev Libsdl-sge -dev libsdl-sound1.2-dev libportmidi-dev libsmpeg-dev (install other dependencies)

CD pygame – 1.9.1 release

  python config.py

run deep_q_network.py

AttributeError:’module’ object has no attribute ‘stack’ sudo apt-get install python-numpy python-scipy python-matplotlib ipython ipython-notebook python-pandas python-sympy Python – the nose)

Git clone git://github.com/numpy/numpy.git numpy (the author here to run the CD numpy; Python setup.py install: apt-get install cython

cd numpy

python setup.py install

\

\

1.6, GPU version of the execution program

After the installation is complete, perform the operation again

  python  deep_q_network.py

Wait for a moment, GPU and CUDA need time to run..

Wait for a moment, the miracle appeared, the birds began to fly automatically, automatically jump up and down, automatically through the obstacle, to know the pure manual play is very difficult to adhere to 9s!

\

Still images may not show much effect, see the video here: weibo.com/1580904460/… .

So far, this game that has abused millions of people around the world is in our hands, using deep learning to play automatically! All embody the magic and charm of deep learning.

\

Part two: TUTORIAL for CPU Edition

If you have a GPU, follow the first part above. What can you do without a GPU? Can run without a GPU and with a CPU.

Use the root account for the following operations

2.1. Install Tensorflow

Source code installation

Clone the TensorFlow Repository

Git clone github.com/tensorflow/…

Install Bazel

Install JDK8 Install JDK8

Sudo add-apt-repository ppa: webupd8Team/Java

Sudo apt-get update

Sudo apt-get install oracle-java8-installer

Add Bazel distribution URI as a package source (one time setup)

Echo “deb/arch = amd64 storage.googleapis.com/bazel-apt stable jdk1.8” | sudo tee/etc/apt/sources list. D/bazel. List

The curl bazel. IO/bazel – relea… | sudo apt-key add –

Update and install Bazel

  sudo apt-get update && sudo apt-get install bazel

  sudo apt-get upgrade bazel

2.1.2. Install other dependencies

  sudo apt-get install python-numpy swig python-dev python-wheel python-pip

Configure the installation (note the prompt after Configure, the prompt is given)

/configure [Clone down tensorFlow

Directory execution]

Color-coded fonts need to be entered manually

Please specify the location of python. [Default is /usr/bin/python]:

Do you wish to build TensorFlow with Google Cloud Platform support? [y/N] N

No Google Cloud Platform support will be enabled for TensorFlow

Do you wish to build TensorFlow with GPU support? [y/N] N

Configuration finished

Create the PIP package and install it

Bazel build-c opt //tensorflow/tools/pip_package:build_pip_package

  bazel build -c opt –config=cuda //tensorflow/tools/pip_package:build_pip_package

Bazel-bin /tensorflow/tools/pip_package/build_pip_package/TMP /tensorflow_pkg No module named setuptools: apt-get install python-pip

Sudo PIP install /… /… / tensorflow – 0.11.0 rc0 py27 – none – any. WHL

The above tensorflow… WHL https://github.com/tensorflow/tensorflow#installation file download address

Select the corresponding version in linux_cpu-only

Setting up TensorFlow for Development

  bazel build -c opt //tensorflow/tools/pip_package:build_pip_package

  mkdir _python_build

  cd _python_build

ln -s .. /bazel-bin/tensorflow/tools/pip_package/build_pip_package.runfiles/org_tensorflow/* .

ln -s .. /tensorflow/tools/pip_package/* .

  python setup.py develop

Test your first TensorFlow neural net model

  cd tensorflow/models/image/mnist

Python AttributeError: Type object ‘NewBase’ has no attribute ‘is_abstract’ sudo pip install six –upgrade —

Target = “/ usr/lib/python2.7 / dist – packages”)

\

\

2.2 Install OpenCV

Download OpenCV Download OpenCV

The browser opens opencv.org/

Download the Linux OpenCV on the right

CD to the download directory

Unzip opencv – 2.4.13. Zip

CD opencv – 2.4.13

  mkdir release  

Sudo apt-get install build-essential cmake libgtk2.0-dev pkg-config python-dev python-numpy libavcodec-dev libavformat-dev libswscale-dev

  cd release  

  cmake -D CMAKE_BUILD_TYPE=RELEASE -D CMAKE_INSTALL_PREFIX=/usr/local ..  

  sudo make install  

 

 

2.3. Download FlappyBird

Download DeepLearningFlappyBird

Git clone — recursive github.com/yenchenlin/…

 

 

Install PyGame

Install PyGame Installs PyGame

Wget www.pygame.org/ftp/pygame-… Download pygame

Sudo apt-get install libsdl1.2-dev sudo apt-get install libsdl1.2-dev

Sudo apt-get install libsdl-image1.2-dev libsdl-mixer1.2-dev libsDL-ttf2.0-dev libsdl-gfx1.2-dev libsdl-net1.2-dev sudo apt-get install libsdl-image1.2-dev libsdl-ttf2.0-dev libsdl-gfx1.2-dev libsdl-net1.2-dev Libsdl-sge -dev libsdl-sound1.2-dev libportmidi-dev libsmpeg-dev (install other dependencies)

CD pygame – 1.9.1 release

  python config.py

run deep_q_network.py

AttributeError:’module’ object has no attribute ‘stack’

sudo apt-get install python-numpy python-scipy python-matplotlib ipython ipython-notebook python-pandas  

python-sympy python-nose

Git clone git://github.com/numpy/numpy.git numpy (the author here to run the CD numpy; Python setup.py install

Error: cython is missing

apt-get install cython

cd numpy

Python setup. Py install)

\

\

2.6, the CPU version of the execution program

After the installation is complete, perform the operation again

  python  deep_q_network.py

The screen will not be stuck, the CPU version will immediately appear results (I here for the first time did not execute root, will report an error, students remember to execute the last command before must root!)

FlappyBird: FlappyBird: FlappyBird: Van Gogh: Van Gogh: Van Gogh: Van Gogh: Van Gogh: Van Gogh: Van Gogh: Van Gogh: Van Gogh: Van Gogh: Van Gogh: Van Gogh: Van Gogh: Van Gogh: Van Gogh: Van Gogh: Van Gogh

\

reference

  1. Learn van Gogh Painting from start to finish using the DL: GTX 1070 CUDa 8.0 TensorFlow GPU Edition \

  2. A simple tutorial written by Xiao CAI, a student of deep learning class in May: Play Flappy Bird\ with MAC DQN

  3. Github.com/yenchenlin/… \

\

\

Afterword.

July Online Development/marketing team, October 13, 2016.