一、tensorflow
1、注意win10安装tensorflow需要创建 TensorFlow 依赖环境:
conda create -n tensorflow python=3.6
2、然后在Anaconda Prompt中激活tensorflow环境:
activate tensorflow
3、最后在这个环境下安装tensorflow(cpu)
conda install tensorflow
如果直接进入第3步,会报错误。需要重新创建环境,再在此环境下安装tensorflow。pycharm运行时需更换tensorflow的python
错误及更换步骤见:https://blog.youkuaiyun.com/lzbmc/article/details/88196667
二、Theano
numpy>=1.7.1 scipy>=0.11
1、win10 CPU
conda install mingw libpython
conda install theano
2、linux GPU
conda install theano
在自家目录(home/你的用户名)下创建文件 .theanorc 注意点不能去,然后打开进行配置
vim ~/.theanorc
[global]
floatX = float32
device = cuda0
[lib]
cnmem = 1
[nvcc]
flags=-D_FORCE_INLINES
fastmath = True
[blas]
ldflags = -lopenblas
[cuda]
root = /usr/local/cuda-9.1/bin
[dnn]
include_path = /usr/local/cuda/include
library_path = /usr/local/cuda/lib64
source ~/.theanorc
测试代码:
from theano import function, config, shared, sandbox
import theano.tensor as T
import numpy
import time
vlen = 10 * 30 * 768 # 10 x #cores x # threads per core
iters = 1000
rng = numpy.random.RandomState(22)
x = shared(numpy.asarray(rng.rand(vlen), config.floatX))
f = function([], T.exp(x))
print (f.maker.fgraph.toposort())
t0 = time.time()
for i in range(iters):
r = f()
t1 = time.time()
print ('Looping %d times took' % iters, t1 - t0, 'seconds')
print ('Result is', r)
if numpy.any([isinstance(x.op, T.Elemwise) for x in f.maker.fgraph.toposort()]):
print ('Used the cpu')
else:
print ('Used the gpu')