anaconda 安装Theano、tensorflow的CPU(win10)和GPU(linux服务器)版本

本文详细介绍了在Windows和Linux环境下安装配置TensorFlow和Theano的过程,包括创建依赖环境、激活环境、安装包的具体命令,以及在Theano中使用GPU的配置方法。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

 一、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')

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值