windows64 CPU python2.7 安装theano & keras

本文详细介绍了在Windows 64位系统上,使用Anaconda环境,通过手动步骤安装Theano和Keras的过程。首先从GitHub下载并解压Theano源码,然后通过conda安装mingw和libpython,接着执行Python setup.py安装Theano,并配置OpenBLAS路径。最后设置环境变量THEANO_FLAGS,确保Theano使用OpenBLAS,并通过pip安装Keras。

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

根据这里 完成安装了theano包


1. 从gitbub上下载并解压theano  地址

2. 在cmd中, 执行"conda install mingw libpython". 这将安装mingw g++ 和libpython (前提安装了Anaconda)

3. 在cmd中, 进入解压后的theano目录中执行"python setup.py install --record files.txt"

4. 在这里 下载OpenBLAS 我下载了OpenBLAS-v0.2.14-Win64-int64.zip 和 mingw64_dll.zip (电脑64位)

5. 创建C:\openblas文件夹, 将上述两个压缩包解压, 将mingw64_dll中的所有dll文件和OpenBLAS-v0.2.14-Win64-int64/bin中的dll文件放入C:\openblas中

6. 在环境变量path中添加C:\openblas

7. 创建一个新的环境变量 名为THEANO_FLAGS  值为device=cpu,blas.ldflags=-LC:/openblas -lopenblas

此时安装结束


运行:

import numpy as np
import time
import theano

print('blas.ldflags=', theano.config.blas.ldflags)

A = np.random.rand(1000, 10000).astype(theano.config.floatX)
B = np.random.rand(10000, 1000).astype(theano.config.floatX)
np_start = time.time()
AB = A.dot(B)
np_end = time.time()
X, Y = theano.tensor.matrices('XY')
mf = theano.function([X, Y], X.dot(Y))
t_start = time.time()
tAB = mf(A, B)
t_end = time.time()
print("NP time: %f[s], theano time: %f[s] (times should be close when run on CPU!)" % (
np_end - np_start, t_end - t_start))
print("Result difference: %f" % (np.abs(AB - tAB).max(), ))

输出 NP time: 0.454026[s], theano time: 0.553031[s]

安装theano成功


安装keras: 在cmd中输入pip install keras 即可

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值