# Theano 简介及其安装 # 简介 `Theano` 是一个 `Python` 科学计算库,允许我们进行符号运算,并在 `CPU` 和 `GPU` 上执行。 它最初由 `Montreal` 大学的机器学习研究者们所开发,用来进行机器学习的计算。 按照[官网](http://deeplearning.net/software/theano/)上的说明,它拥有以下几个方面的特点: * 与 **Numpy, Scipy** 的紧密结合 * **GPU** 加速 * 高效的符号计算 * 速度和稳定性 * 动态生成 **C** 代码 ## 使用 anaconda 安装 theano `windows` 下,使用 `anaconda` 安装 `theano` 的命令为: ```py conda install mingw libpython pip install theano ``` `linux` 下,使用 `anaconda` 安装的命令为 ```py conda install theano ``` 安装好之后,还需要安装 `Cuda` 并进行 `GPU` 环境的配置,否则是不能利用 `GPU` 进行计算的,推荐使用 `linux/mac` 进行配置,具体方法可以参考[官网](http://deeplearning.net/software/theano/)上的配置说明。 查看安装的版本: In [1]: ```py import theano theano.__version__ ``` Out[1]: ```py '0.7.0.dev-54186290a97186b9c6b76317e007844529a352f4' ``` 查看当前使用的 device: In [2]: ```py theano.config.device ``` Out[2]: ```py 'cpu' ``` 运行测试: In [3]: ```py theano.test() ``` ```py /usr/local/lib/python2.7/dist-packages/theano/misc/pycuda_init.py:34: UserWarning: PyCUDA import failed in theano.misc.pycuda_init warnings.warn("PyCUDA import failed in theano.misc.pycuda_init") ....................S............... ``` ```py Theano version 0.7.0.dev-54186290a97186b9c6b76317e007844529a352f4 theano is installed in /usr/local/lib/python2.7/dist-packages/theano NumPy version 1.10.1 NumPy relaxed strides checking option: True NumPy is installed in /usr/lib/python2.7/dist-packages/numpy Python version 2.7.6 (default, Jun 22 2015, 17:58:13) [GCC 4.8.2] nose version 1.3.7 ``` ```py ---------------------------------------------------------------------- Ran 37 tests in 37.919s OK (SKIP=1) ``` Out[3]: ```py ``` 这里我已经在本地 `Windows` 配好了 `GPU` 的设置,如果没有配好,显示的结果可能不一样。 `Windows` 下第一次运行可能会显示 `DEBUG: nvcc STDOUT` 等内容,**`Just ignore it!`**