https://github.com/tensorflow/tensorflow

原文地址

Machine Learning in the Cloud, with TensorFlow

Wednesday, March 23, 2016
 
Posted by Slaven Bilac, Software Engineer, Google Research
用TensorFlow在云端进行机器学习
At Google, researchers collaborate closely with product teams, applying the latest advances in Machine Learning to existing products and services - such as speech recognition in the Google app,search in Google Photos and the Smart Reply feature in Inbox by Gmail - in order to make them more useful. A growing number of Google products are using TensorFlow, our open source Machine Learning system, to tackle ML challenges and we would like to enable others do the same.
在Google,研究人员和产品团队密切协作,把最新的机器学习的进展融入到了现有的产品和服务中,比如:Google应用中的语音识别、Google照片的查找和Gmail收件箱的智能回复特征,这都是为了让这些产品和服务更加的实用。Google产品中使用TensorFlow(我们开源的机器学习系统)的数量正在增加,同时为了掌控机器学习的挑战,我们将确保更多的产品使用TensorFlow.
Today, at GCP NEXT 2016, we announced the alpha release of Cloud Machine Learning, a framework for building and training custom models to be used in intelligent applications. 
今天,在GCP NEXT 2016上,我们宣布正式发布云机器学习的alpha版本,它是一个框架,这个框架将用来构建和训练客户模型,这些客户模型将应用在人工智能应用程序中。

Machine Learning projects can come in many sizes, and as we’ve seen with our open source offering TensorFlow, projects often need to scale up. Some small tasks are best handled with a local solution running on one’s desktop, while large scale applications require both the scale and dependability of a hosted solution. Google Cloud Machine Learning aims to support the full range and provide a seamless transition from local to cloud environment.
机器学习项目可以是各种大小的,就像我们已经看到的我们提供的开源的TensorFlow,项目通常需要去向上扩展。一些运行在个人的电脑上的本地解决方案的小项目是最容易掌握的;与此同时,大规模的应用需要较大的规模和hosted依赖的解决方案。Google的云机器学习,目标是为了支持全领域的解决方案,并且提供一个从本地到云环境的无缝过度。

The Cloud Machine Learning offering allows users to run custom distributed learning algorithms based on TensorFlow. In addition to the deep learning capabilities that power Cloud Translate API,Cloud Vision API, and Cloud Speech API, we provide easy-to-adopt samples for common tasks like linear regression/classification with very fast convergence properties (based on the SDCAalgorithm) and building a custom image classification model with few hundred training examples (based on the DeCAF algorithm).
云机器学习提供了允许用户在TensorFlow的基础上运行客户的分布式学习算法的功能。在深度学习的容量之上,增强了Cloud Translate API,Cloud Vision API, and Cloud Speech API,我们提供了一些易于用于常用任务中的例子,比如:采用非常快的趋于一致属性的linear regression/classification(基于SDCA算法)和用几百个训练例子构建一个客户图像分类模型 (基于DeCAF算法)。
We are excited to bring the best of Google Research to Google Cloud Platform. Learn more about this release and more from GCP Next 2016 on the Google Cloud Platform blog.
我们非常兴奋的把Google研究的最好的内容带到了Google云平台上。希望更多的了解这次发布和GCP Next 2016更多的内容,可以到Google云平台博客。
 

通过阅读TensorFlow的论文和相关博文之后,接下来,对TensorFlow进行一个简单的初步运行。

1、安装了Ubuntu 16.04.(ubuntu-16.04-desktop-amd64.iso)

2、sudo apt-get update

3、# Ubuntu/Linux 64-bit      $ sudo apt-get install Python-pip python-dev

4、# Ubuntu/Linux 64-bit, CPU only:      $ sudo pip install --upgrade https://storage.googleapis.com/tensorflow/linux/cpu/tensorflow-0.8.0-cp27-none-linux_x86_64.whl

5、测试安装结果:

$ 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
>>>

6、测试结果运行正常,结合之前的论文,可以在这里明显的看到Session的用法,包括它的run()接口

Github上除了有TensorFlow的源码库之外,还有一些很不错的适合入门的资源。现在将目前已经接触到的资源整理出来,和大家分享。

1、TensorFlow源码库

https://github.com/tensorflow/tensorflow

2、TensorFlow中文文档

https://github.com/jikexueyuanwiki/tensorflow-zh

3、TensorFlow入门例子库1,每个例子都有对应的Notebook说明。

https://github.com/pkmital/tensorflow_tutorials

4、TensorFlow入门例子库2

https://github.com/nlintz/TensorFlow-Tutorials

5、TensorFlow入门例子库3,每个例子都有对应的Notebook说明。

https://github.com/aymericdamien/TensorFlow-Examples

TensorFlow学习课程:

http://learningtensorflow.com/index.html

这个网站按照入门的顺序,安排课程介绍如何学习TensorFlow,并且配备了一些例子和资料,很适合入门初学者学习。

http://blog.csdn.net/snsn1984/article/details/51372501#

例子源码地址:

https://github.com/aymericdamien/TensorFlow-Examples/blob/master/examples/1%20-%20Introduction/basic_operations.py

根据网上的入门例子,一点点的熟悉代码和TensorFlow。对这个基本的例子,做一个注释,备忘之余分享给同样入门的初学者。

import tensorflow as tf

a = tf.constant(2)
b = tf.constant(3) #把a,b定义为tensorflow的常量,并且赋值。 with tf.Session() as sess:
print "a=2, b=3"
print "Addition with constants: %i" % sess.run(a+b)
print "Multiplication with constants: %i" % sess.run(a*b) #使用Session的run()输出a+b和a*b的结果。使用with <span style="font-family: Arial, Helvetica, sans-serif;">tf.Session() as sess这种用法,在sess.run()结束之后,不用调用sess.close()释放资源 a = tf.placeholder(tf.int16)
b = tf.placeholder(tf.int16) #把a,b定义成为tf.int16类型的占位符,并没有放具体的数值进去。 add = tf.add(a, b)
mul = tf.mul(a, b) <span style="font-family: Arial, Helvetica, sans-serif;">#在a,b两个占位符之上,定义了两个操作,add和mul。</span> with tf.Session() as sess:
print "Addition with variables: %i" % sess.run(add, feed_dict={a: 2, b: 3})
print "Multiplication with variables: %i" % sess.run(mul, feed_dict={a: 2, b: 3}) #给a,b赋值,并且对他们进行前文定义的add和mul操作。 matrix1 = tf.constant([[3., 3.]])
matrix2 = tf.constant([[2.],[2.]])
product = tf.matmul(matrix1, matrix2) #定义两个常量矩阵,并且为这两个矩阵定义了一个matmul操作product。 with tf.Session() as sess:
result = sess.run(product)
print result #运行product操作,并且将结果result输出。

五、

import numpy as np
import tensorflow as tf # Import MINST data
import input_data
mnist = input_data.read_data_sets("/tmp/data/", one_hot=True)
#这里主要是导入数据,数据通过input_data.py已经下载到/tmp/data/目录之下了,这里下载数据的时候,需要提前用浏览器尝试是否可以打开
#http://yann.lecun.com/exdb/mnist/,如果打不开,下载数据阶段会报错。而且一旦数据下载中断,需要将之前下载的未完成的数据清空,重新
#进行下载,否则会出现CRC Check错误。read_data_sets是input_data.py里面的一个函数,主要是将数据解压之后,放到对应的位置。
# In this example, we limit mnist data
Xtr, Ytr = mnist.train.next_batch(5000) #5000 for training (nn candidates)
Xte, Yte = mnist.test.next_batch(200) #200 for testing
#mnist.train.next_batch,其中train和next_batch都是在input_data.py里定义好的数据项和函数。此处主要是取得一定数量的数据。 # Reshape images to 1D
Xtr = np.reshape(Xtr, newshape=(-1, 28*28))
Xte = np.reshape(Xte, newshape=(-1, 28*28))
#将二维的图像数据一维化,利于后面的相加操作。
# tf Graph Input
xtr = tf.placeholder("float", [None, 784])
xte = tf.placeholder("float", [784])
#设立两个空的类型,并没有给具体的数据。这也是为了基于这两个类型,去实现部分的graph。 # Nearest Neighbor calculation using L1 Distance
# Calculate L1 Distance
distance = tf.reduce_sum(tf.abs(tf.add(xtr, tf.neg(xte))), reduction_indices=1)
# Predict: Get min distance index (Nearest neighbor)
pred = tf.arg_min(distance, 0)
#最近邻居算法,算最近的距离的邻居,并且获取该邻居的下标,这里只是基于空的类型,实现的graph,并未进行真实的计算。
accuracy = 0.
# Initializing the variables
init = tf.initialize_all_variables()
#初始化所有的变量和未分配数值的占位符,这个过程是所有程序中必须做的,否则可能会读出随机数值。
# Launch the graph
with tf.Session() as sess:
sess.run(init) # loop over test data
for i in range(len(Xte)):
# Get nearest neighbor
nn_index = sess.run(pred, feed_dict={xtr: Xtr, xte: Xte[i,:]})
# Get nearest neighbor class label and compare it to its true label
print "Test", i, "Prediction:", np.argmax(Ytr[nn_index]), "True Class:", np.argmax(Yte[i])
# Calculate accuracy
if np.argmax(Ytr[nn_index]) == np.argmax(Yte[i]):
accuracy += 1./len(Xte)
print "Done!"
print "Accuracy:", accuracy
#for循环迭代计算每一个测试数据的预测值,并且和真正的值进行对比,并计算精确度。该算法比较经典的是不需要提前训练,直接在测试阶段进行识别。

源代码地址:https://github.com/aymericdamien/TensorFlow-Examples/blob/master/examples/2%20-%20Basic%20Classifiers/nearest_neighbor.py

相关API:

tf.reduce_sum(input_tensor, reduction_indices=None, keep_dims=False, name=None)

Computes the sum of elements across dimensions of a tensor.

Reduces input_tensor along the dimensions given in reduction_indices. Unless keep_dims is true, the rank of the tensor is reduced by 1 for each entry in reduction_indices. If keep_dims is true, the reduced dimensions are retained with length 1.

If reduction_indices has no entries, all dimensions are reduced, and a tensor with a single element is returned.

For example:

# 'x' is [[1, 1, 1]
# [1, 1, 1]]
tf.reduce_sum(x) ==> 6
tf.reduce_sum(x, 0) ==> [2, 2, 2]
tf.reduce_sum(x, 1) ==> [3, 3]
tf.reduce_sum(x, 1, keep_dims=True) ==> [[3], [3]]
tf.reduce_sum(x, [0, 1]) ==> 6
Args:
  • input_tensor: The tensor to reduce. Should have numeric type.
  • reduction_indices: The dimensions to reduce. If None (the default), reduces all dimensions.
  • keep_dims: If true, retains reduced dimensions with length 1.
  • name: A name for the operation (optional).
Returns:

The reduced tensor.

点评:这个API主要是降维使用,在这个例子中,将测试图片和所有图片相加后的二维矩阵,降为每个图片只有一个最终结果的一维矩阵。

http://blog.csdn.net/snsn1984/article/details/51482787

TensorFlow博客翻译——用TensorFlow在云端进行机器学习的更多相关文章

  1. CSDN博客积分规则

    1.博客积分规则 博客积分是CSDN对用户努力的认可和奖励,也是衡量博客水平的重要标准.博客等级也将由博客积分唯一决定.积分规则具体如下: 每发布一篇原创或者翻译文章:可获得10分: 每发布一篇转载文 ...

  2. paper 92:图像视觉博客资源2之MIT斯坦福CMU

    收录的图像视觉(也包含机器学习等)领域的博客资源的第二部分,包含:美国MIT.斯坦福.CMU三所高校 1)这些名人大家一般都熟悉,本文仅收录了包含较多资料的个人博客,并且有不少更新,还有些名人由于分享 ...

  3. (转) OpenCV学习笔记大集锦 与 图像视觉博客资源2之MIT斯坦福CMU

          首页 视界智尚 算法技术 每日技术 来打我呀 注册     OpenCV学习笔记大集锦 整理了我所了解的有关OpenCV的学习笔记.原理分析.使用例程等相关的博文.排序不分先后,随机整理的 ...

  4. TensorFlow相关博客

    Tensor官方教程 极客学院TensorFlow中文文档 xf__mao的博客

  5. 13 Tensorflow机制(翻译)

    代码: tensorflow/examples/tutorials/mnist/ 本文的目的是来展示如何使用Tensorflow训练和评估手写数字识别问题.本文的观众是那些对使用Tensorflow进 ...

  6. 原创翻译-值得关注的10个python语言博客

    原文链接 原文链接的网页感觉网络不是很好,不容易上.我在这里就给大家做个翻译吧. 大家好,还记得我当时学习python的时候,我一直努力地寻找关于python的博客,但我发现它们的数量很少.这也是我建 ...

  7. Redisql: the lightning fast data polyglot【翻译】 - Linvo's blog - 博客频道 - CSDN.NET

    Redisql: the lightning fast data polyglot[翻译] - Linvo's blog - 博客频道 - CSDN.NET Redisql: the lightnin ...

  8. 精通 TensorFlow 1.x·翻译完成

    原文:Mastering TensorFlow 1.x 协议:CC BY-NC-SA 4.0 不要担心自己的形象,只关心如何实现目标.--<原则>,生活原则 2.3.c 在线阅读 Apac ...

  9. [翻译] TensorFlow 分布式之论文篇 "TensorFlow : Large-Scale Machine Learning on Heterogeneous Distributed Systems"

    [翻译] TensorFlow 分布式之论文篇 "TensorFlow : Large-Scale Machine Learning on Heterogeneous Distributed ...

随机推荐

  1. 只有代码不会撒谎,如何通过Spring boot源码查看其对于各个框架的默认配置

    我发现很多开发对于看源码都有种恐惧心理,其实不必这样,大部分优秀的源码写的都挺直观的,很多时候,你在搜索引擎上搜到的一些东西并不一定是对的,但源码肯定造不了假,毕竟不管你怎么想,它就在那里,该是什么意 ...

  2. 【BZOJ1211】树的计数(Prufer编码)

    题意:一个有n个结点的树,设它的结点分别为v1, v2, …, vn, 已知第i个结点vi的度数为di,问满足这样的条件的不同的树有多少棵. 其中1<=n<=150,输入数据保证满足条件的 ...

  3. msp430项目编程30

    msp430中项目---电压检测系统 1.SVS工作原理 2.电路工作原理 3.代码(显示部分) 4.代码(功能实现) 5.项目总结

  4. poj2723 2sat判断解+二分

    典型的2-sat问题,题意:有m个门,每个门上俩把锁,开启其中一把即可,现在给n对钥匙(所有 钥匙编号0123456...2n-1),每对钥匙只能用一把,要求尽可能开门多(按顺序,前max个). 关键 ...

  5. linux用户列表

    centos上面不知道添加了多少个账户,今天想清理一下,但是以前还未查看过linux用户列表, 一般情况下是 cat /etc/passwd 可以查看所有用户的列表 w 可以查看当前活跃的用户列表 c ...

  6. Cocostudio 1.4 实现的DemoShop

    开发环境是CocoStudio 1.4 + Cocos2dx 2.2  把项目文件放到Cocos2dx下的projects文件夹下就可以执行了 压缩包里面包括了 源码 和资源文件 执行效果: 初始化界 ...

  7. 微信小程序-setData()方法

    一般setData方法多用于点击后改变页面信息或者刷新后与后台交互获取最新的信息 注意: 直接修改 this.data 而不调用 this.setData 是无法改变页面的状态的,还会造成数据不一致 ...

  8. Pacemaker 安装与使用

    Pacemaker 仅仅做资源管理器(CRM).底下的消息系统採用 corosync. 安装 以 ubuntu 为例, sudo aptitude install -y pacemaker coros ...

  9. Oracle11g表空间导入dmp数据

    如果你的表数据没有附带表空间和用户名,那么只要一句话 Imp {u_name}/{u_pwd}@{local_svrname} fromuser={from_user} touser={u_name} ...

  10. Effective JavaScript Item 39 绝不要重用父类型中的属性名

    本系列作为Effective JavaScript的读书笔记. 假设须要向Item 38中的Actor对象加入一个ID信息: function Actor(scene, x, y) { this.sc ...