zoukankan      html  css  js  c++  java
  • centos7(python2.7) 安装tensorflow+keras过程

    最近找到一台电脑,装了centos7,所以打算装一个keras玩啊。

    主要过程如下,参考博客已在文中注明:

    1. 安装centos7 , 自带python2.7,但是没有pip命令

    根据(https://blog.csdn.net/boooobcsdn/article/details/79969270)解决问题:

    执行命令 yum -y install epel-release ;

    然后再执行 yum install python-pip;

    安装好后对pip进行升级 pip install --upgrade pip

    2. 新建用户imap

    useradd imap

    passwd imap

    将imap用户添加到/etc/sudoers的步骤:

     root下,chmod 777/etc/sudoers;

    然后vim /etc/sudoers,在root ALL=(ALL:ALL) ALL 下面添加一行imap ALL=(ALL:ALL) ALL,保存并退出;

    最后修改sudoers文件权限chmod 440 /etc/sudoers

    3. pip安装tf

    https://pypi.org/project/tensorflow/#files

    命令: sudo pip install tensorflow

    自动下载并安装

    4. 测试安装好的tf

    1.  
      [imap@localhost keras-work]$ python
    2.  
      Python 2.7.5 (default, Jul 13 2018, 13:06:57)
    3.  
      [GCC 4.8.5 20150623 (Red Hat 4.8.5-28)] on linux2
    4.  
      Type "help", "copyright", "credits" or "license" for more information.
    5.  
      >>> import tensorflow as tf
    6.  
      >>> hello=tf.constant("hello,tf")
    7.  
      >>> sess=tf.Session()
    8.  
      2019-02-15 11:46:34.105782: I tensorflow/core/platform/cpu_feature_guard.cc:141]
    9.  
      Your CPU supports instructions that this TensorFlow binary was not compiled to use: AVX2
    10.  
      >>> print sess.run(hello)
    11.  
      hello,tf
    12.  
      >>> a =tf.constant(10)
    13.  
      >>> b=tf.constant(32)
    14.  
      >>> print sess.run(a+b)
    15.  
      42

    其中有个warning告警,根据(https://blog.csdn.net/zaczoom/article/details/80359185)表示,如果只是cpu版本只是部分指令用不了,会影响效率,但是本身cpu版本效率就不高,可以忽略。

    5. 安装keras

    根据主页(https://keras.io/zh/#_2)安装方法

    预先安装可选依赖:

    cuDNN (如果你计划在 GPU 上运行 Keras,建议安装)。

    HDF5 和 h5py (如果你需要将 Keras 模型保存到磁盘,则需要这些)。

    >> pip install h5py

    graphviz 和 pydot (用于可视化工具绘制模型图)。

    >> pip install pydot

    其他一些依赖:scipy,

    然后选择使用github源码安装:

    git clone https://github.com/keras-team/keras.git

    sudo python setup.py install

    6.测试keras

    (1)

    import tensorflow

    import keras

    会显示使用tensorflow作为后端

    (2)

    ./keras/examples目录下有示例程序,进入目录,输入命令:

    python mnist_mlp.py

    若运行成功则表示安装成功!

    期间的出错:

    (1)缺少python.h;因为这些库使用了c扩展,需要编译,然后又找不到头文件和静态库导致的。编译这些c库需要的依赖库由python dev提供

    #centos

    sudo yum -y install python-devel

    #python3使用python3-dev

    https://blog.csdn.net/max_ss/article/details/87378970

  • 相关阅读:
    sql server delete语句
    sql server 通配符
    sql server join联结
    windows下如何使用两个版本的nodejs
    PHP的Trait 特性
    PHP错误与异常处理try和catch
    laravel belongsTo()&hasOne()用法详解
    Laravel Model 的 fillable (白名单)与 guarded (黑名单)
    js原生,缓动动画封装
    js原生轮播图
  • 原文地址:https://www.cnblogs.com/montai/p/13437584.html
Copyright © 2011-2022 走看看