深度学习框架TensorFlow的基本介绍和安装

妖狐艹你老母 2022-06-08 00:18 257阅读 0赞

一、TensorFlow简介

2016年3月份,Google的围棋人工智能程序AlphaGo以4比1的大比分,战胜人类选手李世石,在全球成功引起广泛关注,引起了一波人工智能的热潮。从智能手机的语音助手,到相机的人脸识别,人工智能技术已经进入到我们生活的方方面面,在未来将深刻的影响我们的生活。

为了加速深度学习领域的发展,2015年11月9日,Google发布深度学习框架TensorFlow并宣布开源。在短时间内,在GitHub上,TensorFlow就成为了最流行的深度学习项目。

TensorFlow提供了非常丰富的深度学习相关的API,可以说目前所有深度学习框架里,提供的API最全的,包括基本的向量矩阵计算、各种优化算法、各种卷积神经网络和循环神经网络基本单元的实现、以及可视化的辅助工具、等等。

TensorFlow应用举例:

在澳大利亚,海洋生物学家与来自昆士兰大学(Queensland University)的计算机科学家合作,通过TensorFlow技术,使用探测器自动地在数以万计的航拍照片中寻找海牛;在日本,一位年轻人利用TensorFlow运用到农业上,按照黄瓜大小、形状、颜色以及其他特征来挑选黄瓜并对它们进行分类;在医学领域,发射科的医生通过采用TensorFlow,使其在医学扫描中能够识别帕金森病的迹象。湾区的数据科学家在树莓派上使用TensorFlow来追踪记录加州火车的动态。AlphaGo开发团队Deepmind也声称,将从Torch迁移到TensorFlow中,这无不印证了TensorFlow在业界的流行程度。

二、CentOS 7.3安装TensorFlow

1 安装python

因为CentOS 7自带python 2.7.5,这一步可以省略。

  1. [root@bogon ~]# python -V
  2. Python 2.7.5

2 安装python软件包管理工具pip(python index package)

(1)安装yum的第三方软件源epel(Extra Packages for Enterprise Linux)

  1. yum -y install epel-release

(2)安装pip

  1. yum install python-pip

(3)升级pip

  1. pip install --upgrade pip

3 安装基于linux和python 2.7的tensorflow 0.9

  1. pip install https://storage.googleapis.com/tensorflow/linux/cpu/tensorflow-0.9.0-cp27-none-linux_x86_64.whl

其他操作系统版本可以参照下表:

  1. # Ubuntu/Linux 64-bit, CPU only, Python 2.7
  2. export TF_BINARY_URL=https://storage.googleapis.com/tensorflow/linux/cpu/tensorflow-0.9.0-cp27-none-linux_x86_64.whl
  3. # Ubuntu/Linux 64-bit, GPU enabled, Python 2.7
  4. # Requires CUDA toolkit 7.5 and CuDNN v4. For other versions, see "Install from sources" below.
  5. export TF_BINARY_URL=https://storage.googleapis.com/tensorflow/linux/gpu/tensorflow-0.9.0-cp27-none-linux_x86_64.whl
  6. # Mac OS X, CPU only, Python 2.7:
  7. export TF_BINARY_URL=https://storage.googleapis.com/tensorflow/mac/tensorflow-0.9.0-py2-none-any.whl
  8. # Ubuntu/Linux 64-bit, CPU only, Python 3.4
  9. export TF_BINARY_URL=https://storage.googleapis.com/tensorflow/linux/cpu/tensorflow-0.9.0-cp34-cp34m-linux_x86_64.whl
  10. # Ubuntu/Linux 64-bit, GPU enabled, Python 3.4
  11. # Requires CUDA toolkit 7.5 and CuDNN v4. For other versions, see "Install from sources" below.
  12. export TF_BINARY_URL=https://storage.googleapis.com/tensorflow/linux/gpu/tensorflow-0.9.0-cp34-cp34m-linux_x86_64.whl
  13. # Ubuntu/Linux 64-bit, CPU only, Python 3.5
  14. export TF_BINARY_URL=https://storage.googleapis.com/tensorflow/linux/cpu/tensorflow-0.9.0-cp35-cp35m-linux_x86_64.whl
  15. # Ubuntu/Linux 64-bit, GPU enabled, Python 3.5
  16. # Requires CUDA toolkit 7.5 and CuDNN v4. For other versions, see "Install from sources" below.
  17. export TF_BINARY_URL=https://storage.googleapis.com/tensorflow/linux/gpu/tensorflow-0.9.0-cp35-cp35m-linux_x86_64.whl
  18. # Mac OS X, CPU only, Python 3.4 or 3.5:
  19. export TF_BINARY_URL=https://storage.googleapis.com/tensorflow/mac/tensorflow-0.9.0-py3-none-any.whl

4 验证安装是否成功

编写python脚本test.py

  1. # vi test.py
  2. import tensorflow as tf
  3. hello = tf.constant('Hello,TensorFlow!')
  4. session = tf.Session()
  5. print(session.run(hello))
  6. a = tf.constant(11)
  7. b = tf.constant(22)
  8. print(session.run(a + b))

运行结果

  1. # python test.py
  2. Hello, TensorFlow!
  3. 33

发表评论

表情:
评论列表 (有 0 条评论,257人围观)

还没有评论,来说两句吧...

相关阅读