Ubuntu14.04上轻松安装与优化轻量级深度学习框架Theano[转]
来源:互联网 发布:ubuntu怎么看软件位置 编辑:程序博客网 时间:2024/06/05 04:53
徐海蛟教学
一,安装轻量级深度学习框架Theano
Warning
If you want to install the bleeding-edge or development version of Theano from GitHub, please make sure you are reading the latest version of this page.
For Ubuntu 11.10 through 14.04:
sudo apt-get install python-numpy python-scipy python-dev python-pip python-nose g++ libopenblas-dev gitsudo pip install Theano
Note
If you have error that contain “gfortran” in it, like this one:
ImportError: (‘/home/Nick/.theano/compiledir_Linux-2.6.35-31-generic-x86_64-with-Ubuntu-10.10-maverick–2.6.6/tmpIhWJaI/0c99c52c82f7ddc775109a06ca04b360.so: undefined symbol: _gfortran_st_write_done’
The problem is probably that NumPy is linked with a different blas then one currently available (probably ATLAS). There is 2 possible fixes:
- Uninstall ATLAS and install OpenBLAS.
- Use the Theano flag “blas.ldflags=-lblas -lgfortran”
1) is better as OpenBLAS is faster
then ATLAS and NumPy is probably already linked with it. So you won’t need any other change in Theano files or Theano configuration.
Note
We use pip
for 2 reasons. First, it allows “import module; module.test()
” to work correctly.
Second, the installation of NumPy 1.6 or 1.6.1 with easy_install
raises an ImportError at the end of the installation. To my knowledge we can ignore this error, but this is not completely safe.easy_install
with NumPy 1.5.1 does not raise this error.
Bleeding Edge Installs
If you would like, instead, to install the bleeding edge Theano (from github) such that you can edit and contribute to Theano, replace the pip install Theano command with:
git clone git://github.com/Theano/Theano.gitcd Theanopython setup.py develop --usercd ..
Test the newly installed packages
- NumPy (~30s):
python -c "import numpy; numpy.test()"
- SciPy (~1m):
python -c "import scipy; scipy.test()"
- Theano (~30m):
python -c "import theano; theano.test()"
Speed test Theano/BLAS
It is recommended to test your Theano/BLAS integration. There are many versions of BLAS that exist and there can be up to 10x speed difference between them. Also, having Theano link directly against BLAS instead of using NumPy/SciPy as an intermediate layer reduces the computational overhead. This is important for BLAS calls to ger
, gemv
and small gemm
operations (automatically called when needed when you use dot()
). To run the Theano/BLAS speed test:
python `python -c "import os, theano; print(os.path.dirname(theano.__file__))"`/misc/check_blas.py
This will print a table with different versions of BLAS/numbers of threads on multiple CPUs and GPUs. It will also print some Theano/NumPy configuration information. Then, it will print the running time of the same benchmarks for your installation. Try to find a CPU similar to yours in the table, and check that the single-threaded timings are roughly the same.
Theano should link to a parallel version of Blas and use all cores when possible. By default it should use all cores. Set the environment variable “OMP_NUM_THREADS=N” to specify to use N threads.
Note
It is possible to have a faster installation of Theano than the one these instructions provide, but this will make the installation more complicated and/or may require that you buy software. This is a simple set of installation instructions that will leave you with a relatively well-optimized version that uses only free software. With more work or by investing money (i.e. buying a license to a proprietary BLAS implementation), it is possible to gain further performance.
Updating Theano
If you followed these installation instructions, you can execute this command to update only Theano:
sudo pip install --upgrade --no-deps theano
If you want to also installed NumPy/SciPy with pip instead of the system package, you can run this:
sudo pip install --upgrade theano
Updating Bleeding Edge Installs
Change to the Theano directory and run:
git pull
Manual Openblas instruction
The openblas included in some older Ubuntu version is limited to 2 threads. Ubuntu 14.04 do not have this limit. If you want to use more cores at the same time, you will need to compile it yourself. Here is some code that will help you.
# remove openblas if you installed itsudo apt-get remove libopenblas-base# Download the development version of OpenBLASgit clone git://github.com/xianyi/OpenBLAScd OpenBLASmake FC=gfortransudo make PREFIX=/usr/local/ install# Tell Theano to use OpenBLAS.# This works only for the current user.# Each Theano user on that computer should run that line.echo -e "\n[blas]\nldflags = -lopenblas\n" >> ~/.theanorc
Contributed GPU instruction
Basic configuration for the GPU Using the GPU.
Ubuntu 14.04:
sudo apt-get install nvidia-currentsudo apt-get install nvidia-cuda-toolkit # As of October 31th, 2014, provide cuda 5.5, not the latest cuda 6.5
If you want cuda 6.5, you can download packages from nvidia for Ubuntu 14.04.
If you downloaded the run package (the only one available for CUDA 5.0 and older), you install it like this:
chmod a+x XXX.shsudo ./XXX.sh
Since CUDA 5.5, Nvidia provide a DEB package. If you don’t know how to intall it, just double click on it from the graphical interface. It should ask if you want to install it. On Ubuntu 14.04, you need to run this in your terminal:
sudo apt-get updatesudo apt-get install cuda
You must reboot the computer after the driver installation. To test that it was loaded correctly after the reboot, run the command nvidia-smi from the command line.
Test GPU configuration
THEANO_FLAGS=floatX=float32,device=gpu python /usr/lib/python2.*/site-packages/theano/misc/check_blas.py
Note
Ubuntu 14.04: default gcc version 4.8.2, gcc 4.4.7,, 4.6.4, and 4.7.3 available.
- Ubuntu14.04上轻松安装与优化轻量级深度学习框架Theano[转]
- ubuntu14.04安装Theano
- Ubuntu14.04安装theano
- Caffe深度学习框架安装(Ubuntu14.04+cuda8.0)
- theano深度框架的学习
- ubuntu 16.04 Anaconda+cuda+theano 深度学习框架安装
- 深度学习框架keras安装(后端基于Tensorflow/theano)
- ubuntu14.04安装CUDA+theano
- 基于Theano的深度学习(Deep Learning)框架Keras学习随笔-03-优化器
- 基于Theano的深度学习(Deep Learning)框架Keras学习随笔-03-优化器
- ubuntu14.04上安装深度音乐和深度影音
- 深度学习anaconda+theano使用框架配置
- 深度学习框架Theano利用GPU加速
- ubuntu14.04安装theano的二进制网络theano-xnor-net
- 【深度学习与Theano】Theano学习之初体验
- 零错误安装基于ubuntu14.04LTS的CUP版本深度学习框架Caffe
- Ubuntu14.04安装Theano详细教程
- ubuntu14.04安装theano,cuda7.5
- 寒假篇13-台阶问题
- Android系统分析之JobScheduler源码分析
- 387. First Unique Character in a String [LeetCode]
- SharePreference保存list
- 贝塞尔曲线扫盲
- Ubuntu14.04上轻松安装与优化轻量级深度学习框架Theano[转]
- android 添加商品到购物车简单动画工具类
- 压力测试工具
- google c++ style 阅读笔记
- Eclipse编辑保存时自动格式化配置
- 异步 FIFO 控制器 (Asynchronous FIFO Controller)
- java注释
- 道德经
- codemirror sql