keras 在win10环境的安装(含theano 和mingw的安装)

参考:keras中文文档  http://keras-cn.readthedocs.io/en/latest/getting_started/keras_windows/

 版本

编译环境Microsoft Visual Studio 2010 - 2015

VS2015 只有cuda8.0支持, VS2013   只有cuda7.5  等。 可以在cuda 官网查询, cuda版本参考

环境

编译环境5. CUDA

cuda8.0  cudnn5.0  (5.1 比theano版本新,可能出问题)
cudnn5.0 解压缩后, 将三个 文件夹 bin, lib, include 的文件  拷贝到 cuda8.0安装的文件 对应的路径下

(可选)加速库CNN

对有问题的地方进行补充:

1.   MinGW的 安装     conda install mingw libpython 安装总是失败

输入命令
           conda config --add channelshttps://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free/
           conda config --set show_channel_urls yes
         第一句话的意思是告诉conda命令等会你别往境外找了,就找我给你的这个地址就可以了。这个是清华大学的anaconda免费package文件服务器
         第二句话的意思是告诉conda命令,让我看看你的url对不对(这句话执行后有可能不显示,这是正常的,不用急)

参考: http://www.cnblogs.com/hdu-zsk/p/5950924.html

2.以下参考教程,貌似是32位的 mingw安装,安装后,可以使用。 但貌似不符合64位的使用。

http://blog.csdn.net/u012997311/article/details/51423137

MinGW - Minimalist GNU for Windows

下载链接: https://sourceforge.net/projects/mingw/files/MinGW/Base/gcc/Version4/

我使用的 是64位的 安装包 mingw64安装包

MinGW-w64 - for 32 and 64 bit Windows

2.  mingw-e64-install.exe的使用    

这里的版本查资料说cuda8.0

ubuntu的gcc编译器是5.4.0,然而cuda8.0不支持5.0以上的编译器,因此需要降级,把编译器版本降到4.9:  

i686   32为/   X86_64   64位           posix  交叉编译   /win32   只在电脑上使用             Destination folder ->  位置自己定

例:  C:\mingw-w64\x86_64-6.3.0\mingw64


安装完成后。  gcc  -v   可以查看 版本

Keras 框架搭建

安装

命令: conda  install  keras  theano 

直接安装的 theano 貌似有问题  

参考:http://blog.csdn.net/chlele0105/article/details/40557259

按照上述安装,theano里除了convolutional_mlp.py以外的所有代码都可以运行,当运行convolutional_mlp.py时出现以下错误:
ValueError: Was not able to allocate output!
WARNING (theano.gof.compilelock): Overriding existing lock by dead process '5216' (I am process '5488')
Error allocating 5760000 bytes of device memory (unknown error).
调试之后发现是theano库中function_module.py代码出现了问题,

用自己下载的theano-mater中的theano子文件夹 theano-master下载替换掉theano_installer_latest.msi自动安装的theanoAnaconda\Lib\site-packages\theano

环境配置

C:\Anaconda2;C:\Anaconda2\Scripts;C:\Anaconda2\MinGW
\bin;C:\Anaconda2\MinGW\x86_64-w64-mingw32\lib;
之后并新建变量PYTHONPATH,并添加

C:\Anaconda2\Lib\site-packages\theano;

  • 修改默认后端
打开C:\Users\当前用户名\.keras,修改文件夹内的keras.json文件如下:
{
"image_dim_ordering":"th",
"epsilon":1e-07,
"floatx":"float32",
"backend":"theano"
}
  • Theano加速配置 在用户目录,也就是C:\Users\当前用户名\,新建.theanorc.txt。 (用户目录:C:\Users\Administrator\      这里建立文件后,复制下面内容即可)       (这里的意思是configparser.py会调用当前位置的文件.theanorc.txt这个路径可以通过修改Theano的configparser.py来改变。Theano装在Anaconda\Lib\site-packages里 .theanorc.txt的内容:
[global]
openmp=False 
device = gpu   
optimizer_including=cudnn #不用cudnn的话就不要这句,实际上不用加,只要刚刚配置到位就行  
floatX = float32  
allow_input_downcast=True  
[lib]
cnmem = 0.8  #theano黑科技,初始化显存比例
[blas]
ldflags=   #加速库
[gcc]
cxxflags=-IC:\Anaconda2\MinGW  
[nvcc]
fastmath = True  
--flags=-LC:\Anaconda2\libs #改成自己装的目录
--compiler_bindir=D:\Microsoft Visual Studio 12.0\VC\bin #改成自己装的目录
#最后记得把汉字全删了
个人的设置 

cuda8.0   cudnn5.1    vs2015    anaconda2    mingw64  

[global]
openmp=False 
device = gpu   
optimizer_including=cudnn
floatX = float32  
allow_input_downcast=True  
[lib]
cnmem = 0.8
[blas]
ldflags=
[gcc]
cxxflags=-IC:\mingw-w64\x86_64-6.3.0\mingw64
[nvcc]
fastmath = True  
--flags=-LC:\Anaconda2\libs
--compiler_bindir=C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\bin 

上面的个人配置可能有点儿问题,也可以运行

改进版本:mingw  使用conda install  mingw libpython  清华镜像

cuda8.0  cudnn5.0  vs2013  anaconda2     mingw4.7

[global]
openmp=False 
device = gpu   
optimizer_including=cudnn
floatX = float32  
allow_input_downcast=True  
[lib]
cnmem = 0.8
[blas]
ldflags=
[gcc]
cxxflags=-IC:\Anaconda2\MinGW
[nvcc]
fastmath = True  
--flags=-LC:\Anaconda2\libs
--compiler_bindir=C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\bin 


然后, 运行python  =>  import keras 测试。 没有报错,则成功。

出现问题:

cmath:203:11: error: '::hypot' has not been declared

The problem is, that pyconfig.h has the following define:     

  #define hypot _hypot         

It should probably just be removed when using gcc.

地方在    C:\Anaconda2\include\pyconfig.h

/* ------------------------------------------------------------------------*/
/* egcs/gnu-win32 defines __GNUC__ and _WIN32 */
#if defined(__GNUC__) && defined(_WIN32)
/* XXX These defines are likely incomplete, but should be easy to fix.
   They should be complete enough to build extension modules. */
/* Suggested by Rene Liebscher <R.Liebscher@gmx.de> to avoid a GCC 2.91.*
   bug that requires structure imports.  More recent versions of the
   compiler don't exhibit this bug.
*/
#if (__GNUC__==2) && (__GNUC_MINOR__<=91)
#warning "Please use an up-to-date version of gcc! (>2.91 recommended)"
#endif

#define COMPILER "[gcc]"
//#define hypot _hypot
#define PY_LONG_LONG long long
#define PY_LLONG_MIN LLONG_MIN
#define PY_LLONG_MAX LLONG_MAX
#define PY_ULLONG_MAX ULLONG_MAX
#endif /* GNUC */

http://stackoverflow.com/questions/29450016/o1-2-3-with-std-c1y-11-98-if-cmath-is-included-im-getting-error-hypo

这个参考没看懂,没用上

下载Keras开发包

git clone https://github.com/fchollet/keras.git
cd keras/examples/
python mnist_mlp.py

程序无错进行,至此,keras安装完成。






  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值