zoukankan      html  css  js  c++  java
  • 在原生Windows安装Keras

    既然要深入学习,就不能和时代脱节,所以选择了keras,资源相对比较丰富。由于Windows饱受歧视,各种文档都不推荐使用。但我又没有换系统的成本,所以还是凑合下,毕竟他们给出了方法,稍微折腾一下还是可以的。参考整合了链接[1-2]的tensorflow安装教程和链接[4]的keras安装教程,感谢原作者!

    一、python。

    单纯的肯定不方便:所以先装上anaconda。集成度很高,非常给力,不然各种scipy啥的会搞得很麻烦。注意版本的选择,python 3.5~3.6可以,因为tensorflow只支持3.5+的。

    二、cuda/cudnn。(CPU版本TensorFlow忽略)

    TensorFlow分为CPU版和GPU版,如果你打算安装GPU版,请先安装如下两个驱动:

    1、CUDA安装:https://developer.nvidia.com/cudnn(要注册Nvidia用户,并加入CuDNN开发组,填若干问卷就可以下载了)选择下载版本时要注意和Cuda版本匹配。解压后覆盖至CUDA的安装目录下

    例如:C:Program FilesNVIDIA GPU Computing ToolkitCUDAv8.0

    三、pip。

    需要切换到国内的镜像,过会才能提高安装的速度和成功率。win7在user目录中创建一个pip目录,如:C:Usersxxpip,创建pip.ini,写入以下内容:

        [global]  
        index-url = http://mirrors.aliyun.com/pypi/simple/  
        [install]  
        trusted-host=mirrors.aliyun.com 

    上面是阿里云,其它的国内镜像还有以下,其他设置详见文后链接[3]:

    清华:https://pypi.tuna.tsinghua.edu.cn/simple

    阿里云:http://mirrors.aliyun.com/pypi/simple/

    中国科技大学 https://pypi.mirrors.ustc.edu.cn/simple/

    华中理工大学:http://pypi.hustunique.com/

    山东理工大学:http://pypi.sdutlinux.org/ 

    豆瓣:http://pypi.douban.com/simple/

    四、tensorflow。

    官方说明链接[1]给出了安装最新tf的方法,如果遇到问题可以参考。但他用conda命令,所以我们用pip快点。打开anaconda prompt输入pip install --upgrade tensorflow回车。如果是GPU版本,输入pip install --upgrade tensorflow-gpu即可。装完了测试下(IPython中),能输出结果32就是成功的。

    >>>import tensorflow as tf  
    >>>sess = tf.Session()  
    >>>a = tf.constant(10)  
    >>>b = tf.constant(22)  
    >>>print(sess.run(a + b)) 

    五、keras。

    文档给的方法是输入pip install keras -U --pre,可是我试了多次失败,后来去掉参数-U可以了,因为-U会强制更新相关的包,有时候就怎么都装不好了。我下的最新anaconda,里面的包应该不需要强制更新,所以用pip install keras --pre即可安装。装完了测试下,能正常运行就是成功,他给的示例数据下载的比较慢,需要开启科学上网才行:

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

    附上anaconda添加国内镜像的方法:

    >>>conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free/
    >>>conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/conda-forge
    >>>conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/msys2/

    add改成remove可以删除。顺便可以开启地址显示

    >>>conda config --set show_channel_urls yes

    上海大学的镜像也开通了,见[5]。

    推荐链接:

    [1]https://www.tensorflow.org/install/install_windows

    [2]http://blog.csdn.net/include1224/article/details/53452824

    [3]http://www.cnblogs.com/microman/p/6107879.html

    [4]http://keras-cn.readthedocs.io/en/latest/for_beginners/keras_windows/

    [5]https://www.v2ex.com/t/407892

  • 相关阅读:
    ZTree id值太大,ZTree没有生成树,ZTree的id值过大
    Spring NamedParameterJdbcTemplate命名参数查询条件封装, NamedParameterJdbcTemplate查询封装
    Linux Redis 重启数据丢失解决方案,Linux重启后Redis数据丢失解决方
    Linux Redis自动启动,Redis开机启动,Linux Redis设置开机启动
    Linux Redis安装,Linux如何安装Redis,Linux Redis自动启动,Redis开机启动
    springJdbc in 查询,Spring namedParameterJdbcTemplate in查询
    Sublime的插件Color Highlighter的安装方法
    Sublime的Package Control安装方法
    JavaScript实现最简单的拖拽效果
    css抠图之background-position-背景定位
  • 原文地址:https://www.cnblogs.com/ancoyoli/p/7507878.html
Copyright © 2011-2022 走看看