|
| 1 | +{ |
| 2 | + "cells": [ |
| 3 | + { |
| 4 | + "cell_type": "markdown", |
| 5 | + "metadata": {}, |
| 6 | + "source": [ |
| 7 | + "# Theano 简介及其安装" |
| 8 | + ] |
| 9 | + }, |
| 10 | + { |
| 11 | + "cell_type": "markdown", |
| 12 | + "metadata": {}, |
| 13 | + "source": [ |
| 14 | + "# 简介" |
| 15 | + ] |
| 16 | + }, |
| 17 | + { |
| 18 | + "cell_type": "markdown", |
| 19 | + "metadata": {}, |
| 20 | + "source": [ |
| 21 | + "`Theano` 是一个 `Python` 科学计算库,允许我们进行符号运算,并在 `CPU` 和 `GPU` 上执行。\n", |
| 22 | + "\n", |
| 23 | + "它最初由 `Montreal` 大学的机器学习研究者们所开发,用来进行机器学习的计算。\n", |
| 24 | + "\n", |
| 25 | + "按照[官网](http://deeplearning.net/software/theano/)上的说明,它拥有以下几个方面的特点:\n", |
| 26 | + "\n", |
| 27 | + "- 与 **Numpy, Scipy** 的紧密结合\n", |
| 28 | + "- **GPU** 加速\n", |
| 29 | + "- 高效的符号计算\n", |
| 30 | + "- 速度和稳定性\n", |
| 31 | + "- 动态生成 **C** 代码" |
| 32 | + ] |
| 33 | + }, |
| 34 | + { |
| 35 | + "cell_type": "markdown", |
| 36 | + "metadata": {}, |
| 37 | + "source": [ |
| 38 | + "## 使用 anaconda 安装 theano" |
| 39 | + ] |
| 40 | + }, |
| 41 | + { |
| 42 | + "cell_type": "markdown", |
| 43 | + "metadata": {}, |
| 44 | + "source": [ |
| 45 | + "`windows` 下,使用 `anaconda` 安装 `theano` 的命令为:\n", |
| 46 | + "\n", |
| 47 | + " conda install mingw libpython\n", |
| 48 | + " pip install theano\n", |
| 49 | + " \n", |
| 50 | + "`linux` 下,使用 `anaconda` 安装的命令为\n", |
| 51 | + " \n", |
| 52 | + " conda install theano\n", |
| 53 | + "\n", |
| 54 | + "安装好之后,还需要安装 `Cuda` 并进行 `GPU` 环境的配置,否则是不能利用 `GPU` 进行计算的,推荐使用 `linux/mac` 进行配置,具体方法可以参考[官网](http://deeplearning.net/software/theano/)上的配置说明。\n", |
| 55 | + "\n", |
| 56 | + "查看安装的版本:" |
| 57 | + ] |
| 58 | + }, |
| 59 | + { |
| 60 | + "cell_type": "code", |
| 61 | + "execution_count": 1, |
| 62 | + "metadata": { |
| 63 | + "collapsed": false, |
| 64 | + "scrolled": true |
| 65 | + }, |
| 66 | + "outputs": [ |
| 67 | + { |
| 68 | + "data": { |
| 69 | + "text/plain": [ |
| 70 | + "'0.7.0.dev-54186290a97186b9c6b76317e007844529a352f4'" |
| 71 | + ] |
| 72 | + }, |
| 73 | + "execution_count": 1, |
| 74 | + "metadata": {}, |
| 75 | + "output_type": "execute_result" |
| 76 | + } |
| 77 | + ], |
| 78 | + "source": [ |
| 79 | + "import theano\n", |
| 80 | + "\n", |
| 81 | + "theano.__version__" |
| 82 | + ] |
| 83 | + }, |
| 84 | + { |
| 85 | + "cell_type": "markdown", |
| 86 | + "metadata": {}, |
| 87 | + "source": [ |
| 88 | + "查看当前使用的 device:" |
| 89 | + ] |
| 90 | + }, |
| 91 | + { |
| 92 | + "cell_type": "code", |
| 93 | + "execution_count": 2, |
| 94 | + "metadata": { |
| 95 | + "collapsed": false |
| 96 | + }, |
| 97 | + "outputs": [ |
| 98 | + { |
| 99 | + "data": { |
| 100 | + "text/plain": [ |
| 101 | + "'cpu'" |
| 102 | + ] |
| 103 | + }, |
| 104 | + "execution_count": 2, |
| 105 | + "metadata": {}, |
| 106 | + "output_type": "execute_result" |
| 107 | + } |
| 108 | + ], |
| 109 | + "source": [ |
| 110 | + "theano.config.device" |
| 111 | + ] |
| 112 | + }, |
| 113 | + { |
| 114 | + "cell_type": "markdown", |
| 115 | + "metadata": {}, |
| 116 | + "source": [ |
| 117 | + "运行测试:" |
| 118 | + ] |
| 119 | + }, |
| 120 | + { |
| 121 | + "cell_type": "code", |
| 122 | + "execution_count": 3, |
| 123 | + "metadata": { |
| 124 | + "collapsed": false |
| 125 | + }, |
| 126 | + "outputs": [ |
| 127 | + { |
| 128 | + "name": "stderr", |
| 129 | + "output_type": "stream", |
| 130 | + "text": [ |
| 131 | + "/usr/local/lib/python2.7/dist-packages/theano/misc/pycuda_init.py:34: UserWarning: PyCUDA import failed in theano.misc.pycuda_init\n", |
| 132 | + " warnings.warn(\"PyCUDA import failed in theano.misc.pycuda_init\")\n", |
| 133 | + "....................S..............." |
| 134 | + ] |
| 135 | + }, |
| 136 | + { |
| 137 | + "name": "stdout", |
| 138 | + "output_type": "stream", |
| 139 | + "text": [ |
| 140 | + "Theano version 0.7.0.dev-54186290a97186b9c6b76317e007844529a352f4\n", |
| 141 | + "theano is installed in /usr/local/lib/python2.7/dist-packages/theano\n", |
| 142 | + "NumPy version 1.10.1\n", |
| 143 | + "NumPy relaxed strides checking option: True\n", |
| 144 | + "NumPy is installed in /usr/lib/python2.7/dist-packages/numpy\n", |
| 145 | + "Python version 2.7.6 (default, Jun 22 2015, 17:58:13) [GCC 4.8.2]\n", |
| 146 | + "nose version 1.3.7\n" |
| 147 | + ] |
| 148 | + }, |
| 149 | + { |
| 150 | + "name": "stderr", |
| 151 | + "output_type": "stream", |
| 152 | + "text": [ |
| 153 | + "\n", |
| 154 | + "----------------------------------------------------------------------\n", |
| 155 | + "Ran 37 tests in 37.919s\n", |
| 156 | + "\n", |
| 157 | + "OK (SKIP=1)\n" |
| 158 | + ] |
| 159 | + }, |
| 160 | + { |
| 161 | + "data": { |
| 162 | + "text/plain": [ |
| 163 | + "<nose.result.TextTestResult run=37 errors=0 failures=0>" |
| 164 | + ] |
| 165 | + }, |
| 166 | + "execution_count": 3, |
| 167 | + "metadata": {}, |
| 168 | + "output_type": "execute_result" |
| 169 | + } |
| 170 | + ], |
| 171 | + "source": [ |
| 172 | + "theano.test()" |
| 173 | + ] |
| 174 | + }, |
| 175 | + { |
| 176 | + "cell_type": "markdown", |
| 177 | + "metadata": {}, |
| 178 | + "source": [ |
| 179 | + "这里我已经在本地 `Windows` 配好了 `GPU` 的设置,如果没有配好,显示的结果可能不一样。\n", |
| 180 | + "\n", |
| 181 | + "`Windows` 下第一次运行可能会显示 `DEBUG: nvcc STDOUT` 等内容,**`Just ignore it!`**" |
| 182 | + ] |
| 183 | + } |
| 184 | + ], |
| 185 | + "metadata": { |
| 186 | + "kernelspec": { |
| 187 | + "display_name": "Python 2", |
| 188 | + "language": "python", |
| 189 | + "name": "python2" |
| 190 | + }, |
| 191 | + "language_info": { |
| 192 | + "codemirror_mode": { |
| 193 | + "name": "ipython", |
| 194 | + "version": 2 |
| 195 | + }, |
| 196 | + "file_extension": ".py", |
| 197 | + "mimetype": "text/x-python", |
| 198 | + "name": "python", |
| 199 | + "nbconvert_exporter": "python", |
| 200 | + "pygments_lexer": "ipython2", |
| 201 | + "version": "2.7.6" |
| 202 | + } |
| 203 | + }, |
| 204 | + "nbformat": 4, |
| 205 | + "nbformat_minor": 0 |
| 206 | +} |
0 commit comments