参考:keras中文文档 http://keras-cn.readthedocs.io/en/latest/getting_started/keras_windows/
对有问题的地方进行补充:
1. MinGW的 安装 conda install mingw libpython 安装总是失败
参考: 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 可以查看 版本
直接安装的 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自动安装的theano(Anaconda\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"
}
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 */
这个参考没看懂,没用上
下载Keras开发包
git clone https://github.com/fchollet/keras.git
cd keras/examples/
python mnist_mlp.py
程序无错进行,至此,keras安装完成。