mirror of
https://github.com/apachecn/ailearning.git
synced 2026-05-01 05:51:01 +08:00
2020-10-19 21:08:55
This commit is contained in:
@@ -10,7 +10,7 @@
|
||||
|
||||
首先是用 `anaconda` 安装 `theano`:
|
||||
|
||||
```
|
||||
```py
|
||||
conda install mingw libpython
|
||||
pip install theano
|
||||
```
|
||||
@@ -55,39 +55,39 @@ Cuda 的版本与电脑的显卡兼容。
|
||||
|
||||
In [1]:
|
||||
|
||||
```
|
||||
```py
|
||||
%%file test_theano.py
|
||||
from theano import config
|
||||
print 'using device:', config.device
|
||||
|
||||
```
|
||||
|
||||
```
|
||||
```py
|
||||
Writing test_theano.py
|
||||
|
||||
```
|
||||
|
||||
我们可以通过临时设置环境变量 `THEANO_FLAGS` 来改变 `theano` 的运行模式,在 linux 下,临时环境变量直接用:
|
||||
|
||||
```
|
||||
```py
|
||||
THEANO_FLAGS=xxx
|
||||
```
|
||||
|
||||
就可以完成,设置完成之后,该环境变量只在当前的命令窗口有效,你可以这样运行你的代码:
|
||||
|
||||
```
|
||||
```py
|
||||
THEANO_FLAGS=xxx python <your script>.py
|
||||
```
|
||||
|
||||
在 `Windows` 下,需要使用 `set` 命令来临时设置环境变量,所以运行方式为:
|
||||
|
||||
```
|
||||
```py
|
||||
set THEANO_FLAGS=xxx && python <your script>.py
|
||||
```
|
||||
|
||||
In [2]:
|
||||
|
||||
```
|
||||
```py
|
||||
import sys
|
||||
|
||||
if sys.platform == 'win32':
|
||||
@@ -97,14 +97,14 @@ else:
|
||||
|
||||
```
|
||||
|
||||
```
|
||||
```py
|
||||
using device: cpu
|
||||
|
||||
```
|
||||
|
||||
In [3]:
|
||||
|
||||
```
|
||||
```py
|
||||
if sys.platform == 'win32':
|
||||
!set THEANO_FLAGS=mode=FAST_RUN,device=gpu,floatX=float32 && python test_theano.py
|
||||
else:
|
||||
@@ -112,7 +112,7 @@ else:
|
||||
|
||||
```
|
||||
|
||||
```
|
||||
```py
|
||||
Using gpu device 0: Tesla C2075 (CNMeM is disabled)
|
||||
using device: gpu
|
||||
|
||||
@@ -122,7 +122,7 @@ using device: gpu
|
||||
|
||||
In [4]:
|
||||
|
||||
```
|
||||
```py
|
||||
%%file test_theano.py
|
||||
|
||||
from theano import function, config, shared, sandbox
|
||||
@@ -150,14 +150,14 @@ else:
|
||||
|
||||
```
|
||||
|
||||
```
|
||||
```py
|
||||
Overwriting test_theano.py
|
||||
|
||||
```
|
||||
|
||||
In [5]:
|
||||
|
||||
```
|
||||
```py
|
||||
if sys.platform == 'win32':
|
||||
!set THEANO_FLAGS=mode=FAST_RUN,device=cpu,floatX=float32 && python test_theano.py
|
||||
else:
|
||||
@@ -165,7 +165,7 @@ else:
|
||||
|
||||
```
|
||||
|
||||
```
|
||||
```py
|
||||
Looping 1000 times took 3.498123 seconds
|
||||
Result is [ 1.23178029 1.61879337 1.52278066 ..., 2.20771813 2.29967761
|
||||
1.62323284]
|
||||
@@ -175,7 +175,7 @@ Used the cpu
|
||||
|
||||
In [6]:
|
||||
|
||||
```
|
||||
```py
|
||||
if sys.platform == 'win32':
|
||||
!set THEANO_FLAGS=mode=FAST_RUN,device=gpu,floatX=float32 && python test_theano.py
|
||||
else:
|
||||
@@ -183,7 +183,7 @@ else:
|
||||
|
||||
```
|
||||
|
||||
```
|
||||
```py
|
||||
Using gpu device 0: Tesla C2075 (CNMeM is disabled)
|
||||
Looping 1000 times took 0.847006 seconds
|
||||
Result is [ 1.23178029 1.61879349 1.52278066 ..., 2.20771813 2.29967761
|
||||
@@ -198,7 +198,7 @@ Used the gpu
|
||||
|
||||
In [7]:
|
||||
|
||||
```
|
||||
```py
|
||||
%%file test_theano.py
|
||||
|
||||
from theano import function, config, shared, sandbox
|
||||
@@ -228,14 +228,14 @@ else:
|
||||
|
||||
```
|
||||
|
||||
```
|
||||
```py
|
||||
Overwriting test_theano.py
|
||||
|
||||
```
|
||||
|
||||
In [8]:
|
||||
|
||||
```
|
||||
```py
|
||||
if sys.platform == 'win32':
|
||||
!set THEANO_FLAGS=mode=FAST_RUN,device=gpu,floatX=float32 && python test_theano.py
|
||||
else:
|
||||
@@ -243,7 +243,7 @@ else:
|
||||
|
||||
```
|
||||
|
||||
```
|
||||
```py
|
||||
Using gpu device 0: Tesla C2075 (CNMeM is disabled)
|
||||
Looping 1000 times took 0.318359 seconds
|
||||
Result is <CudaNdarray object at 0x7f7bb701fb70>
|
||||
@@ -255,7 +255,7 @@ Used the gpu
|
||||
|
||||
In [9]:
|
||||
|
||||
```
|
||||
```py
|
||||
!rm test_theano.py
|
||||
|
||||
```
|
||||
@@ -266,7 +266,7 @@ In [9]:
|
||||
|
||||
例如我现在的 .theanorc.txt 配置为:
|
||||
|
||||
```
|
||||
```py
|
||||
[global]
|
||||
device = gpu
|
||||
floatX = float32
|
||||
|
||||
Reference in New Issue
Block a user