这个系列写了好几篇文章,这是相关文章的索引,仅供参考:

以下是相关深度学习工具包的安装,包括Theano, MXNet

4. Theano

Theano虽然官宣不在更新,但是它的价值依然很大,很多早期深度学习工具的底层依然依赖的是它。在Ubuntu下安装Theano有两种模式,一种是通过Conda安装,Theano的官方安装文档给得是这个方式;另外一种是pip安装模式,官方文档没有给出很好的描述,我参考了网上其他的文章,安装过程中遇到了几个小问题,不过顺利解决。首先安装相关的依赖:

sudo apt-get install python-numpy python-scipy python-dev python-pip python-nose g++ libopenblas-dev git

这个时候可以先尝试用pip的方式安装Theano:

pip install Theano

测试时会遇到类似找不到pygpu模块的提示,而这个模块,是无法用pip安装的,必须通过Theano提供的libgpuarray编译,官方安装文档也给了专门的说明

git clone https://github.com/Theano/libgpuarray.git
cd libgpuarray/
mkdir Build
cd Build/
cmake .. -DCMAKE_BUILD_TYPE=Release
make
sudo make install
cd ..
sudo pip install Cython(如果提示cython没有安装需要先安装Cython)
sudo python setup.py build
sudo python setup.py install
sudo ldconfig

还有最后一步,配置文件

vim ~/.theanorc

[global]
floatX=float32
device=cuda
[cuda]
root=/usr/local/cuda
[nvcc]
flags=-D_FORCE_INLINES

然后可以试一下在ipython中导入Theano是否ok:

Python 2.7.13 (default, Jan 19 2017, 14:48:08) 
Type "copyright", "credits" or "license" for more information.
 
IPython 5.1.0 -- An enhanced Interactive Python.
?         -> Introduction and overview of IPython's features.
%quickref -> Quick reference.
help      -> Python's own help system.
object?   -> Details about 'object', use 'object??' for extra details.
 
In [1]: import theano
Using cuDNN version 6021 on context None
Mapped name None to device cuda: GeForce GTX 1080 Ti (0000:05:00.0)

5. MXNet

MXNet的安装还是比较方便的,按照MXNet官方的安装指南,我是在Ubuntu17.04的环境下用virtualenv安装的:

Python2.x的安装方式如下:

如果没有安装python环境和virtualenv,可以先安装:
sudo apt-get update
sudo apt-get install -y python-dev python-virtualenv

然后用virtualenv生成MXNet的虚拟环境:
virtualenv --system-site-packages venv
source venv/bin/activate

要升级pip到最新版(不清楚是为什么):
pip install --upgrade pip

目前MXNet的最新版是1.0:
pip install mxnet-cu80==1.0.0

如果需要可视化训练过程,则可以选择安装graphviz:
sudo apt-get install graphviz
pip install graphviz

最后测试一下MXNet在GPU环境下是否生效:

Python 2.7.13 (default, Nov 23 2017, 15:37:09) 
[GCC 6.3.0 20170406] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import mxnet as mx
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/textminer/mxnet/venv/local/lib/python2.7/site-packages/mxnet/__init__.py", line 25, in <module>
    from . import engine
  File "/home/textminer/mxnet/venv/local/lib/python2.7/site-packages/mxnet/engine.py", line 23, in <module>
    from .base import _LIB, check_call
  File "/home/textminer/mxnet/venv/local/lib/python2.7/site-packages/mxnet/base.py", line 111, in <module>
    _LIB = _load_lib()
  File "/home/textminer/mxnet/venv/local/lib/python2.7/site-packages/mxnet/base.py", line 103, in _load_lib
    lib = ctypes.CDLL(lib_path[0], ctypes.RTLD_LOCAL)
  File "/usr/lib/python2.7/ctypes/__init__.py", line 362, in __init__
    self._handle = _dlopen(self._name, mode)
OSError: libgfortran.so.3: cannot open shared object file: No such file or directory

报了如上libgfortran.so.3的错误,google了一下,需要安装gfortran:

sudo apt-get install gfortran

再次测试,就没有问题了:

(venv) textminer@textminer:~/mxnet$ python
Python 2.7.13 (default, Nov 23 2017, 15:37:09) 
[GCC 6.3.0 20170406] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import mxnet as mx
>>> a = mx.nd.ones((2,3), mx.gpu())
>>> b = a * 2 + 1
>>> b.asnumpy()
array([[ 3.,  3.,  3.],
       [ 3.,  3.,  3.]], dtype=float32)

Python3.x下的安装基本上过程相同。

注:原创文章,转载请注明出处及保留链接“我爱自然语言处理”:https://www.52nlp.cn

本文链接地址:从零开始搭建深度学习服务器: 深度学习工具安装(Theano + MXNet) https://www.52nlp.cn/?p=10058

作者 52nlp

发表回复

您的电子邮箱地址不会被公开。 必填项已用 * 标注