└── README.md /README.md: -------------------------------------------------------------------------------- 1 | [Website](https://www.floydhub.com) • [Docs](https://docs.floydhub.com) • [Forum](https://forum.floydhub.com) • [Twitter](https://twitter.com/floydhub_) • [We're Hiring](https://angel.co/floydhub) 2 | 3 | [![FloydHub Logo](https://github.com/floydhub/static/blob/master/Group.png)](https://www.floydhub.com) 4 | 5 | ## Update: I've built a quick tool based on this repo. Start running your Tensorflow project on AWS in <30seconds using Floyd. See [www.floydhub.com](https://www.floydhub.com). It's free to try out. 6 | ### Happy to take feature requests/feedback and answer questions - mail me sai@floydhub.com. 7 | 8 | ## Setting up a Deep Learning Machine from Scratch (Software) 9 | A detailed guide to setting up your machine for deep learning research. Includes instructions to install drivers, tools and various deep learning frameworks. This was tested on a 64 bit machine with Nvidia Titan X, running Ubuntu 14.04 10 | 11 | There are several great guides with a similar goal. Some are limited in scope, while others are not up to date. This guide is based on (with some portions copied verbatim from): 12 | * [Caffe Installation for Ubuntu](https://github.com/tiangolo/caffe/blob/ubuntu-tutorial-b/docs/install_apt2.md) 13 | * [Running a Deep Learning Dream Machine](http://graphific.github.io/posts/running-a-deep-learning-dream-machine/) 14 | 15 | ### Table of Contents 16 | * [Basics](#basics) 17 | * [Nvidia Drivers](#nvidia-drivers) 18 | * [CUDA](#cuda) 19 | * [cuDNN](#cudnn) 20 | * [Python Packages](#python-packages) 21 | * [Tensorflow](#tensorflow) 22 | * [OpenBLAS](#openblas) 23 | * [Common Tools](#common-tools) 24 | * [Caffe](#caffe) 25 | * [Theano](#theano) 26 | * [Keras](#keras) 27 | * [Torch](#torch) 28 | * [X2Go](#x2go) 29 | 30 | ### Basics 31 | * First, open a terminal and run the following commands to make sure your OS is up-to-date 32 | 33 | sudo apt-get update 34 | sudo apt-get upgrade 35 | sudo apt-get install build-essential cmake g++ gfortran git pkg-config python-dev software-properties-common wget 36 | sudo apt-get autoremove 37 | sudo rm -rf /var/lib/apt/lists/* 38 | 39 | ### Nvidia Drivers 40 | * Find your graphics card model 41 | 42 | lspci | grep -i nvidia 43 | 44 | * Go to the [Nvidia website](http://www.geforce.com/drivers) and find the latest drivers for your graphics card and system setup. You can download the driver from the website and install it, but doing so makes updating to newer drivers and uninstalling it a little messy. Also, doing this will require you having to quit your X server session and install from a Terminal session, which is a hassle. 45 | * We will install the drivers using apt-get. Check if your latest driver exists in the ["Proprietary GPU Drivers" PPA](https://launchpad.net/~graphics-drivers/+archive/ubuntu/ppa). Note that the latest drivers are necessarily the most stable. It is advisable to install the driver version recommended on that page. Add the "Proprietary GPU Drivers" PPA repository. At the time of this writing, the latest version is 361.42, however, the recommended version is 352: 46 | 47 | sudo add-apt-repository ppa:graphics-drivers/ppa 48 | sudo apt-get update 49 | sudo apt-get install nvidia-352 50 | 51 | * Restart your system 52 | 53 | sudo shutdown -r now 54 | 55 | * Check to ensure that the correct version of NVIDIA drivers are installed 56 | 57 | cat /proc/driver/nvidia/version 58 | 59 | ### CUDA 60 | * Download CUDA 7.5 from [Nvidia](https://developer.nvidia.com/cuda-toolkit). Go to the Downloads directory and install CUDA 61 | 62 | sudo dpkg -i cuda-repo-ubuntu1404*amd64.deb 63 | sudo apt-get update 64 | sudo apt-get install cuda 65 | 66 | * Add CUDA to the environment variables 67 | 68 | echo 'export PATH=/usr/local/cuda/bin:$PATH' >> ~/.bashrc 69 | echo 'export LD_LIBRARY_PATH=/usr/local/cuda/lib64:$LD_LIBRARY_PATH' >> ~/.bashrc 70 | source ~/.bashrc 71 | 72 | * Check to ensure the correct version of CUDA is installed 73 | 74 | nvcc -V 75 | 76 | * Restart your computer 77 | 78 | sudo shutdown -r now 79 | 80 | #### Checking your CUDA Installation (Optional) 81 | * Install the samples in the CUDA directory. Compile them (takes a few minutes): 82 | 83 | /usr/local/cuda/bin/cuda-install-samples-7.5.sh ~/cuda-samples 84 | cd ~/cuda-samples/NVIDIA*Samples 85 | make -j $(($(nproc) + 1)) 86 | 87 | **Note**: (`-j $(($(nproc) + 1))`) executes the make command in parallel using the number of cores in your machine, so the compilation is faster 88 | 89 | * Run deviceQuery and ensure that it detects your graphics card and the tests pass 90 | 91 | bin/x86_64/linux/release/deviceQuery 92 | 93 | ### cuDNN 94 | * cuDNN is a GPU accelerated library for DNNs. It can help speed up execution in many cases. To be able to download the cuDNN library, you need to register in the Nvidia website at [https://developer.nvidia.com/cudnn](https://developer.nvidia.com/cudnn). This can take anywhere between a few hours to a couple of working days to get approved. Once your registration is approved, download **cuDNN v4 for Linux**. The latest version is cuDNN v5, however, not all toolkits support it yet. 95 | 96 | * Extract and copy the files 97 | 98 | cd ~/Downloads/ 99 | tar xvf cudnn*.tgz 100 | cd cuda 101 | sudo cp */*.h /usr/local/cuda/include/ 102 | sudo cp */libcudnn* /usr/local/cuda/lib64/ 103 | sudo chmod a+r /usr/local/cuda/lib64/libcudnn* 104 | 105 | ### Check 106 | * You can do a check to ensure everything is good so far using the `nvidia-smi` command. This should output some stats about your GPU 107 | 108 | ### Python Packages 109 | * Install some useful Python packages using apt-get. There are some version incompatibilities with using pip install and TensorFlow ( see https://github.com/tensorflow/tensorflow/issues/2034) 110 | 111 | sudo apt-get update && apt-get install -y python-numpy python-scipy python-nose \ 112 | python-h5py python-skimage python-matplotlib \ 113 | python-pandas python-sklearn python-sympy 114 | sudo apt-get clean && sudo apt-get autoremove 115 | rm -rf /var/lib/apt/lists/* 116 | 117 | 118 | ### Tensorflow 119 | * This installs v0.8 with GPU support. Instructions below are from [here](https://www.tensorflow.org/versions/r0.8/get_started/os_setup.html) 120 | 121 | sudo apt-get install python-pip python-dev 122 | sudo pip install --upgrade https://storage.googleapis.com/tensorflow/linux/gpu/tensorflow-0.8.0-cp27-none-linux_x86_64.whl 123 | 124 | * Run a test to ensure your Tensorflow installation is successful. When you execute the `import` command, there should be no warning/error. 125 | 126 | python 127 | >>> import tensorflow as tf 128 | >>> exit() 129 | 130 | ### OpenBLAS 131 | * OpenBLAS is a linear algebra library and is faster than Atlas. This step is optional, but note that some of the following steps assume that OpenBLAS is installed. You'll need to install gfortran to compile it. 132 | 133 | mkdir ~/git 134 | cd ~/git 135 | git clone https://github.com/xianyi/OpenBLAS.git 136 | cd OpenBLAS 137 | make FC=gfortran -j $(($(nproc) + 1)) 138 | sudo make PREFIX=/usr/local install 139 | 140 | * Add the path to your LD_LIBRARY_PATH variable 141 | 142 | echo 'export LD_LIBRARY_PATH=/usr/local/lib:$LD_LIBRARY_PATH' >> ~/.bashrc 143 | 144 | ### Common Tools 145 | * Install some common tools from the Scipy stack 146 | 147 | sudo apt-get install -y libfreetype6-dev libpng12-dev 148 | pip install -U matplotlib ipython[all] jupyter pandas scikit-image 149 | 150 | ### Caffe 151 | * The following instructions are from [here](http://caffe.berkeleyvision.org/install_apt.html). The first step is to install the pre-requisites 152 | 153 | sudo apt-get install libprotobuf-dev libleveldb-dev libsnappy-dev libopencv-dev libhdf5-serial-dev protobuf-compiler 154 | sudo apt-get install --no-install-recommends libboost-all-dev 155 | sudo apt-get install libgflags-dev libgoogle-glog-dev liblmdb-dev 156 | 157 | * Clone the Caffe repo 158 | 159 | cd ~/git 160 | git clone https://github.com/BVLC/caffe.git 161 | cd caffe 162 | cp Makefile.config.example Makefile.config 163 | 164 | * If you installed cuDNN, uncomment the `USE_CUDNN := 1` line in the Makefile 165 | 166 | sed -i 's/# USE_CUDNN := 1/USE_CUDNN := 1/' Makefile.config 167 | 168 | * If you installed OpenBLAS, modify the `BLAS` parameter value to `open` 169 | 170 | sed -i 's/BLAS := atlas/BLAS := open/' Makefile.config 171 | 172 | * Install the requirements, build Caffe, build the tests, run the tests and ensure that all tests pass. Note that all this takes a while 173 | 174 | sudo pip install -r python/requirements.txt 175 | make all -j $(($(nproc) + 1)) 176 | make test -j $(($(nproc) + 1)) 177 | make runtest -j $(($(nproc) + 1)) 178 | 179 | * Build PyCaffe, the Python interface to Caffe 180 | 181 | make pycaffe -j $(($(nproc) + 1)) 182 | 183 | * Add Caffe to your environment variable 184 | 185 | echo 'export CAFFE_ROOT=$(pwd)' >> ~/.bashrc 186 | echo 'export PYTHONPATH=$CAFFE_ROOT/python:$PYTHONPATH' >> ~/.bashrc 187 | source ~/.bashrc 188 | 189 | * Test to ensure that your Caffe installation is successful. There should be no warnings/errors when the import command is executed. 190 | 191 | ipython 192 | >>> import caffe 193 | >>> exit() 194 | 195 | ### Theano 196 | * Install the pre-requisites and install Theano. These instructions are sourced from [here](http://deeplearning.net/software/theano/install_ubuntu.html) 197 | 198 | sudo apt-get install python-numpy python-scipy python-dev python-pip python-nose g++ python-pygments python-sphinx python-nose 199 | sudo pip install Theano 200 | 201 | * Test your Theano installation. There should be no warnings/errors when the import command is executed. 202 | 203 | python 204 | >>> import theano 205 | >>> exit() 206 | 207 | ### Keras 208 | * Keras is a useful wrapper around Theano and Tensorflow. By default, it uses Theano as the backend. See [here](http://keras.io/backend/) for instructions on how to change this to Tensorflow. 209 | 210 | sudo pip install keras 211 | 212 | ### Torch 213 | * Instructions to install Torch below are sourced from [here](http://torch.ch/docs/getting-started.html). The installation takes a little while 214 | 215 | git clone https://github.com/torch/distro.git ~/git/torch --recursive 216 | cd torch; bash install-deps; 217 | ./install.sh 218 | 219 | ### X2Go 220 | * If your deep learning machine is not your primary work desktop, it helps to be able to access it remotely. [X2Go](http://wiki.x2go.org/doku.php/doc:newtox2go) is a fantastic remote access solution. You can install the X2Go server on your Ubuntu machine using the instructions below. 221 | 222 | sudo apt-get install software-properties-common 223 | sudo add-apt-repository ppa:x2go/stable 224 | sudo apt-get update 225 | sudo apt-get install x2goserver x2goserver-xsession 226 | 227 | * X2Go does not support the Unity desktop environment (the default in Ubuntu). I have found XFCE to work pretty well. More details on the supported environmens [here](http://wiki.x2go.org/doku.php/doc:de-compat) 228 | 229 | sudo apt-get update 230 | sudo apt-get install -y xfce4 xfce4-goodies xubuntu-desktop 231 | 232 | * Find the IP of your machine using 233 | 234 | hostname -I 235 | 236 | * You can install a client on your main machine to connect to your deep learning server using the above IP. More instructions [here](http://wiki.x2go.org/doku.php/doc:usage:x2goclient) depending on your Client OS 237 | --------------------------------------------------------------------------------