Google人工智能平台TensorFlow介绍

来源:互联网 发布:淘宝卖家如何办理发票 编辑:程序博客网 时间:2024/05/14 20:54
tensorFlow是什么
官方英文介绍:TensorFlow™ is an open source software library for numerical computation using data flow graphs.
TensorFlow是谷歌2015年开源的一个人工智能平台。就如命名一样,TensorFlow为张量从图的一端流动到另一端计算过程。TensorFlow是将复杂的数据结构传输至人工智能神经网中进行分析和处理过程的系统。TensorFlow可被用于语音识别或图像识别等多项机器深度学习领域,它可在小到一部智能手机、大到数千台数据中心服务器的各种设备上运行。
与TensorFlow类似的库还有Caffe,Theano, MXNet.

什么是张量(tensor)
对于张量这个概念的理解很不容易。我看介绍TensorFlow的说明上说张量就是N维数组,百度百科上说它是一个可用来表示在一些矢量、标量和其他张量之间的线性关系的多线性函数。在不同的领域,张量有不同的理解。我认为这句话讲得比较好:张量是不随坐标系而改变的物理系统内在的量。在机器视觉领域,我个人理解为在不同坐标系/参考系下变的CV特征。

TensorFlow安装
环境:ubuntu14.04_64bit/Python2.7,TensorFlow当前版本r0.9
TensorFlow提供了多种安装方式,如下:
Pip方式:不推荐,容易对现有系统造成影响。
Virtualenv方式:推荐,能够隔离Python环境,对现有Python程序无影响。
Anaconda:类似VirtualEnv方式
Docker方式:推荐,运行在Docker容器中,有效隔离环境。
Source源代码方式:有兴趣的可尝试。
本来想采用Docker方式的,但我的虚拟机里安装失败,因此这里就选virtualenv的方式。

安装virtualenv相关包
dennis@ubuntu14:~$ sudo apt-get install python-pip python-dev python-virtualenv

创建tensorflow的virtualenv环境
dennis@ubuntu14:~$ virtualenv --system-site-packages ~/tensorflow

激活tensorflow虚拟环境
dennis@ubuntu14:~$ source ~/tensorflow/bin/activate
(tensorflow)dennis@ubuntu14:~$
(tensorflow)dennis@ubuntu14:~$ export TF_BINARY_URL=https://storage.googleapis.com/tensorflow/linux/cpu/tensorflow-0.9.0rc0-cp27-none-linux_x86_64.whl
(tensorflow)dennis@ubuntu14:~$ sudo pip install --upgrade $TF_BINARY_URL

测试TensorFlow
(tensorflow)dennis@ubuntu14:~$ pythonPython 2.7.6 (default, Jun 22 2015, 17:58:13)[GCC 4.8.2] on linux2Type "help", "copyright", "credits" or "license" for more information.>>> 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>>>
打印出tensorflow的安装路径
dennis@ubuntu14:~$ python -c 'import os; import inspect; import tensorflow; print(os.path.dirname(inspect.getfile(tensorflow)))'
/usr/local/lib/python2.7/dist-packages/tensorflow

运行TensorFlow的Demo
对于MNIST的分类demo模块的路径为:/usr/local/lib/python2.7/dist-packages/tensorflow/models/image/mnist/

执行如下命令运行demo
dennis@ubuntu14:~$ python -m tensorflow.models.image.mnist.convolutionalSuccessfully downloaded train-images-idx3-ubyte.gz 9912422 bytes.Successfully downloaded train-labels-idx1-ubyte.gz 28881 bytes.Successfully downloaded t10k-images-idx3-ubyte.gz 1648877 bytes.Successfully downloaded t10k-labels-idx1-ubyte.gz 4542 bytes.Extracting data/train-images-idx3-ubyte.gzExtracting data/train-labels-idx1-ubyte.gzExtracting data/t10k-images-idx3-ubyte.gzExtracting data/t10k-labels-idx1-ubyte.gzInitialized!Step 0 (epoch 0.00), 8.5 msMinibatch loss: 12.053, learning rate: 0.010000Minibatch error: 90.6%Validation error: 84.6%Step 100 (epoch 0.12), 455.4 msMinibatch loss: 3.283, learning rate: 0.010000Minibatch error: 6.2%Validation error: 6.8%...Step 8500 (epoch 9.89), 440.0 msMinibatch loss: 1.594, learning rate: 0.006302Minibatch error: 0.0%Validation error: 0.8%Test error: 0.8%dennis@ubuntu14:~$     
Demo的详情后续再分析!

参考资料:
[1] https://www.tensorflow.org/
[2] https://www.tensorflow.org/versions/r0.9/tutorials/index.html
[3] https://www.tensorflow.org/versions/r0.9/get_started/os_setup.html
[4] https://github.com/tensorflow/tensorflow

原创粉丝点击