人工智能[1]当下最火的技术,深刻改变人类社会生活、改变世界。攻城狮们自然不能落后时代,TensorFlow[2]是Google公司开发的人工智能开发框架,用于机器学习和深度神经网络,下面介绍如何安卓TensorFlow框架。
原文地址 http://mp.weixin.qq.com/s/c57z0GHUD7g4ooxkVOy8ZA
硬件环境
- 操作系统: Ubuntu 17.04 x64[3]
- CPU: Intel(R) Core(TM) i3-4130 CPU @ 3.40GHz
- python: Python 2.7.13[4], Ubuntu系统自带的
安装过程
下载安装文件 tensorflow-0.8.0-cp27-none-linux_x86_64.whl
文件保存到路径 ~/tensorflow/tensorflow-0.8.0-cp27-none-linux_x86_64.whl准备 VirtualEnv环境[5]
# 1. 安装python-virtualenv
$ sudo apt-get install python-pip python-dev python-virtualenv
# 2. 创建virtualenv 环境
$ virtualenv --system-site-packages ~/tensorflow
$ cd ~/tensorflow
# 3. 执行安装
pip install --upgrade ./tensorflow-0.8.0-cp27-none-linux_x86_64.whl
- 如果一切顺利,你会看到类似下面的过程
pip install --upgrade ./tensorflow-0.8.0-cp27-none-linux_x86_64.whl --trusted-host mirrors.aliyun.com
Processing ./tensorflow-0.8.0-cp27-none-linux_x86_64.whl
Collecting protobuf==3.0.0b2 (from tensorflow==0.8.0)
Downloading http://mirrors.aliyun.com/pypi/packages/00/8e/9a3feb39d464eb7aacc108e6e6e1f2368ec741821486964c4cd0f41baabb/protobuf-3.0.0b2-py2.py3-none-any.whl (326kB)
100% |████████████████████████████████| 327kB 1.9MB/s
Collecting wheel (from tensorflow==0.8.0)
Downloading http://mirrors.aliyun.com/pypi/packages/0c/80/16a85b47702a1f47a63c104c91abdd0a6704ee8ae3b4ce4afc49bc39f9d9/wheel-0.30.0-py2.py3-none-any.whl (49kB)
100% |████████████████████████████████| 51kB 624kB/s
Requirement already up-to-date: numpy>=1.8.2 in /home/ethink/.local/lib/python2.7/site-packages (from tensorflow==0.8.0)
Requirement already up-to-date: six>=1.10.0 in /home/ethink/.local/lib/python2.7/site-packages (from tensorflow==0.8.0)
Collecting setuptools (from protobuf==3.0.0b2->tensorflow==0.8.0)
Downloading http://mirrors.aliyun.com/pypi/packages/bb/e0/ea620f9ecbaaaf3ebb288cdbbe8cc20b6a789c17e42d8916662b218e3349/setuptools-38.2.4-py2.py3-none-any.whl (489kB)
100% |████████████████████████████████| 491kB 1.6MB/s
Installing collected packages: setuptools, protobuf, wheel, tensorflow
Found existing installation: setuptools 32.3.1
Uninstalling setuptools-32.3.1:
Successfully uninstalled setuptools-32.3.1
Found existing installation: wheel 0.29.0
Uninstalling wheel-0.29.0:
Successfully uninstalled wheel-0.29.0
Successfully installed protobuf-3.0.0b2 setuptools-38.2.4 tensorflow-0.8.0 wheel-0.30.0
OK,看到最后的Successfully表示大工告成,下面我们实际测试。笔者实际安装遇到了“Could not find a version”的错误,请点击查看解决方法。
写一段代码测试一下吧
$ python
>>> import tensorflow as tf
>>> hello = tf.constant('Hello, TensorFlow!')
>>> sess = tf.Session()
>>> print sess.run(hello)
Hello, TensorFlow!
>>> a = tf.constant(10)
>>> b = tf.constant(32)
>>> print sess.run(a+b)
42
>>>
安装遇到的问题Could not find a version {#myerror}
问题描述:
Processing ./tensorflow-0.8.0-cp27-none-linux_x86_64.whl
Collecting protobuf==3.0.0b2 (from tensorflow==0.8.0)
The repository located at mirrors.aliyun.com is not a trusted or secure host and is being ignored. If this repository is available via HTTPS it is recommended to use HTTPS instead, otherwise you may silence this warning and allow it anyways with '--trusted-host mirrors.aliyun.com'.
Could not find a version that satisfies the requirement protobuf==3.0.0b2 (from tensorflow==0.8.0) (from versions: )
No matching distribution found for protobuf==3.0.0b2 (from tensorflow==0.8.0)
解决方法:
添加选项,这里使用了阿里的镜像 trusted-host mirrors.aliyun.com
pip install --upgrade ./tensorflow-0.8.0-cp27-none-linux_x86_64.whl --trusted-host mirrors.aliyun.com
推荐阅读:史上最简单的TensorFlow安装指南