从0开始Ubuntu上搭深度学习框架
2016-07-16 13:10
411 查看
原文地址:https://github.com/saiprashanths/dl-setup
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
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):
Caffe Installation for Ubuntu
Running a Deep Learning Dream Machine
Nvidia Drivers
CUDA
cuDNN
Python Packages
Tensorflow
OpenBLAS
Common Tools
Caffe
Theano
Keras
Torch
X2Go
Go to the Nvidia website 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.
We will install the drivers using apt-get. Check if your latest driver exists in the
"Proprietary GPU Drivers" 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:
Restart your system
Check to ensure that the correct version of NVIDIA drivers are installed
Nvidia. Go to the Downloads directory and install CUDA
Add CUDA to the environment variables
Check to ensure the correct version of CUDA is installed
Restart your computer
Note: (
Run deviceQuery and ensure that it detects your graphics card and the tests pass
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.
Extract and copy the files
https://github.com/tensorflow/tensorflow/issues/2034)
here
Run a test to ensure your Tensorflow installation is successful. When you execute the
Add the path to your LD_LIBRARY_PATH variable
here. The first step is to install the pre-requisites
Clone the Caffe repo
If you installed cuDNN, uncomment the
If you installed OpenBLAS, modify the
Install the requirements, build Caffe, build the tests, run the tests and ensure that all tests pass. Note that all this takes a while
Build PyCaffe, the Python interface to Caffe
Add Caffe to your environment variable
Test to ensure that your Caffe installation is successful. There should be no warnings/errors when the import command is executed.
here
Test your Theano installation. There should be no warnings/errors when the import command is executed.
here for instructions on how to change this to Tensorflow.
here. The installation takes a little while
X2Go is a fantastic remote access solution. You can install the X2Go server on your Ubuntu machine using the instructions below.
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
Find the IP of your machine using
You can install a client on your main machine to connect to your deep learning server using the above IP. More instructions
here depending on your Client OS
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
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):
Caffe Installation for Ubuntu
Running a Deep Learning Dream Machine
Table of Contents
BasicsNvidia Drivers
CUDA
cuDNN
Python Packages
Tensorflow
OpenBLAS
Common Tools
Caffe
Theano
Keras
Torch
X2Go
Basics
First, open a terminal and run the following commands to make sure your OS is up-to-datesudo apt-get update sudo apt-get upgrade sudo apt-get install build-essential cmake g++ gfortran git pkg-config python-dev software-properties-common wget sudo apt-get autoremove sudo rm -rf /var/lib/apt/lists/*
Nvidia Drivers
Find your graphics card modellspci | grep -i nvidia
Go to the Nvidia website 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.
We will install the drivers using apt-get. Check if your latest driver exists in the
"Proprietary GPU Drivers" 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:
sudo add-apt-repository ppa:graphics-drivers/ppa sudo apt-get update sudo apt-get install nvidia-352
Restart your system
sudo shutdown -r now
Check to ensure that the correct version of NVIDIA drivers are installed
cat /proc/driver/nvidia/version
CUDA
Download CUDA 7.5 fromNvidia. Go to the Downloads directory and install CUDA
sudo dpkg -i cuda-repo-ubuntu1404*amd64.deb sudo apt-get update sudo apt-get install cuda
Add CUDA to the environment variables
echo 'export PATH=/usr/local/cuda/bin:$PATH' >> ~/.bashrc echo 'export LD_LIBRARY_PATH=/usr/local/cuda/lib64:$LD_LIBRARY_PATH' >> ~/.bashrc source ~/.bashrc
Check to ensure the correct version of CUDA is installed
nvcc -V
Restart your computer
sudo shutdown -r now
Checking your CUDA Installation (Optional)
Install the samples in the CUDA directory. Compile them (takes a few minutes):/usr/local/cuda/bin/cuda-install-samples-7.5.sh ~/cuda-samples cd ~/cuda-samples/NVIDIA*Samples make -j $(($(nproc) + 1))
Note: (
-j $(($(nproc) + 1))) executes the make command in parallel using the number of cores in your machine, so the compilation is faster
Run deviceQuery and ensure that it detects your graphics card and the tests pass
bin/x86_64/linux/release/deviceQuery
cuDNN
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 athttps://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.
Extract and copy the files
cd ~/Downloads/ tar xvf cudnn*.tgz cd cuda sudo cp */*.h /usr/local/cuda/include/ sudo cp */libcudnn* /usr/local/cuda/lib64/ sudo chmod a+r /usr/local/cuda/lib64/libcudnn*
Check
You can do a check to ensure everything is good so far using thenvidia-smicommand. This should output some stats about your GPU
Python Packages
Install some useful Python packages using apt-get. There are some version incompatibilities with using pip install and TensorFlow ( seehttps://github.com/tensorflow/tensorflow/issues/2034)
sudo apt-get update && apt-get install -y python-numpy python-scipy python-nose \ python-h5py python-skimage python-matplotlib \ python-pandas python-sklearn python-sympy sudo apt-get clean && sudo apt-get autoremove rm -rf /var/lib/apt/lists/*
Tensorflow
This installs v0.8 with GPU support. Instructions below are fromhere
sudo apt-get install python-pip python-dev sudo pip install --upgrade https://storage.googleapis.com/tensorflow/linux/gpu/tensorflow-0.8.0-cp27-none-linux_x86_64.whl
Run a test to ensure your Tensorflow installation is successful. When you execute the
importcommand, there should be no warning/error.
python >>> import tensorflow as tf >>> exit()
OpenBLAS
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.mkdir ~/git cd ~/git git clone https://github.com/xianyi/OpenBLAS.git cd OpenBLAS make FC=gfortran -j $(($(nproc) + 1)) sudo make PREFIX=/usr/local install
Add the path to your LD_LIBRARY_PATH variable
echo 'export LD_LIBRARY_PATH=/usr/local/lib:$LD_LIBRARY_PATH' >> ~/.bashrc
Common Tools
Install some common tools from the Scipy stacksudo apt-get install -y libfreetype6-dev libpng12-dev pip install -U matplotlib ipython[all] jupyter pandas scikit-image
Caffe
The following instructions are fromhere. The first step is to install the pre-requisites
sudo apt-get install libprotobuf-dev libleveldb-dev libsnappy-dev libopencv-dev libhdf5-serial-dev protobuf-compiler sudo apt-get install --no-install-recommends libboost-all-dev sudo apt-get install libgflags-dev libgoogle-glog-dev liblmdb-dev
Clone the Caffe repo
cd ~/git git clone https://github.com/BVLC/caffe.git cd caffe cp Makefile.config.example Makefile.config
If you installed cuDNN, uncomment the
USE_CUDNN := 1line in the Makefile
sed -i 's/# USE_CUDNN := 1/USE_CUDNN := 1/' Makefile.config
If you installed OpenBLAS, modify the
BLASparameter value to
open
sed -i 's/BLAS := atlas/BLAS := open/' Makefile.config
Install the requirements, build Caffe, build the tests, run the tests and ensure that all tests pass. Note that all this takes a while
sudo pip install -r python/requirements.txt make all -j $(($(nproc) + 1)) make test -j $(($(nproc) + 1)) make runtest -j $(($(nproc) + 1))
Build PyCaffe, the Python interface to Caffe
make pycaffe -j $(($(nproc) + 1))
Add Caffe to your environment variable
echo 'export CAFFE_ROOT=$(pwd)' >> ~/.bashrc echo 'export PYTHONPATH=$CAFFE_ROOT/python:$PYTHONPATH' >> ~/.bashrc source ~/.bashrc
Test to ensure that your Caffe installation is successful. There should be no warnings/errors when the import command is executed.
ipython >>> import caffe >>> exit()
Theano
Install the pre-requisites and install Theano. These instructions are sourced fromhere
sudo apt-get install python-numpy python-scipy python-dev python-pip python-nose g++ python-pygments python-sphinx python-nose sudo pip install Theano
Test your Theano installation. There should be no warnings/errors when the import command is executed.
python >>> import theano >>> exit()
Keras
Keras is a useful wrapper around Theano and Tensorflow. By default, it uses Theano as the backend. Seehere for instructions on how to change this to Tensorflow.
sudo pip install keras
Torch
Instructions to install Torch below are sourced fromhere. The installation takes a little while
git clone https://github.com/torch/distro.git ~/git/torch --recursive cd torch; bash install-deps; ./install.sh
X2Go
If your deep learning machine is not your primary work desktop, it helps to be able to access it remotely.X2Go is a fantastic remote access solution. You can install the X2Go server on your Ubuntu machine using the instructions below.
sudo apt-get install software-properties-common sudo add-apt-repository ppa:x2go/stable sudo apt-get update sudo apt-get install x2goserver x2goserver-xsession
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
sudo apt-get update sudo apt-get install -y xfce4 xfce4-goodies xubuntu-desktop
Find the IP of your machine using
hostname -I
You can install a client on your main machine to connect to your deep learning server using the above IP. More instructions
here depending on your Client OS
相关文章推荐
- Rotate List
- hive启动错误:[ERROR] Terminal initialization failed; falling back to unsupported
- 【方法】使C++的cout能在不设置locale的情况下正确输出wchar_t Unicode字符串
- GIS的一些看法(就业等)
- Qt自定义控件的创建与初步使用(一)之自定义控件的创建步骤
- 史上最全的“大数据”学习资源(下)
- 7、easyui 表单
- LINUX中的rfcomm命令工具的使用
- Escape noise
- 我的自我介绍以及决心书
- 李洪强iOS开发拓展篇—UIDynamic(重力行为+碰撞检测)
- javaSE学习笔记——接口
- 史上最全的“大数据”学习资源(上)
- 使用视频作为网页背景的技术探讨
- 一种新型内存(SCM)的简单应用思考
- Android:layout_weight
- 蓝牙模块在HHARM2410上的移植
- TFTP、NFS、FTP三种文件传送协议(附linux协议配置)
- 数据库恢复,记录一次全量数据文件丢失的恢复
- eclipse注释模板