文章作者:Tyan
博客:noahsnail.com
TensorFlow is an Open Source Software Library for Machine Intelligence
TensorFlow是一个关于机器智能的开源软件库
About TensorFlow
TensorFlow™ is an open source software library for numerical computation using data flow graphs. Nodes in the graph represent mathematical operations, while the graph edges represent the multidimensional data arrays (tensors) communicated between them. The flexible architecture allows you to deploy computation to one or more CPUs or GPUs in a desktop, server, or mobile device with a single API. TensorFlow was originally developed by researchers and engineers working on the Google Brain Team within Google’s Machine Intelligence research organization for the purposes of conducting machine learning and deep neural networks research, but the system is general enough to be applicable in a wide variety of other domains as well.
关于TensorFlow
TensorFlow™是一个用数据流图进行数值计算的开源软件库。数据流图中的结点表示数学运算,数据流图中的边表示多维数据数组(张量)之间的数据交互。这个灵活的结构让你可以通过单独的API将计算部署在一个或多个CPU或GPU上,这些CPU或GPU可以位于桌面端、服务器或移动设备上。TensorFlow最初是由Google大脑团队中的研究员和工程师开发的,Google大脑团队在Google的机器智能研究组织中主要是进行机器学习和深度神经网络研究的,TensorFlow系统具有足够的通用性,也可以应用在许多其它的领域。
What is a Data Flow Graph?
Data flow graphs describe mathematical computation with a directed graph of nodes & edges. Nodes typically implement mathematical operations, but can also represent endpoints to feed in data, push out results, or read/write persistent variables. Edges describe the input/output relationships between nodes. These data edges carry dynamically-sized multidimensional data arrays, or tensors. The flow of tensors through the graph is where TensorFlow gets its name. Nodes are assigned to computational devices and execute asynchronously and in parallel once all the tensors on their incoming edges becomes available.
什么是数据流图?
数据流图通过有向图的结点和边来描述数学计算。结点通常实现数学运算,但也能表示端点输入数据,推出结果,或读/写持续的变量。边表示结点之间的输入/输出关系。这些数据边携带动态大小的多维数据数组或张量。图中的张量流动是TensorFlow名字的来源。结点被分配到计算设备上,以异步方式执行,一旦结点输入边的所有张量可用便并行执行。
TensorFlow Features
TensorFlow的特性
Deep Flexibility
TensorFlow isn’t a rigid neural networks library. If you can express your computation as a data flow graph, you can use TensorFlow. You construct the graph, and you write the inner loop that drives computation. We provide helpful tools to assemble subgraphs common in neural networks, but users can write their own higher-level libraries on top of TensorFlow. Defining handy new compositions of operators is as easy as writing a Python function and costs you nothing in performance. And if you don’t see the low-level data operator you need, write a bit of C++ to add a new one.
深度灵活性
TensorFlow不是一个死板的神经网络库。如果你能将你的计算表示成数据流图,你就可以使用TensorFlow。你要构建数据流图,并且编写驱动计算的内部循环。我们将提供帮助工具来装配神经网络中的常见子图,但用户要能编写在TensorFlow之上的他们自己的更高层次的库。定义方便的操作符新组合就像定义一个Python函数那样容易,在性能上不会有任何损失。如果你不想看你需要的低层操作符,你可以写点C++添加一个新的操作符。
True Portability
TensorFlow runs on CPUs or GPUs, and on desktop, server, or mobile computing platforms. Want to play around with a machine learning idea on your laptop without need of any special hardware? TensorFlow has you covered. Ready to scale-up and train that model faster on GPUs with no code changes? TensorFlow has you covered. Want to deploy that trained model on mobile as part of your product? TensorFlow has you covered. Changed your mind and want to run the model as a service in the cloud? Containerize with Docker and TensorFlow just works.
真正的可移植性
TensorFlow运行在CPU或GPU上,在桌面端,服务器或移动计算平台上。想在笔记本上实现你的机器学习想法而不需要任何特定的硬件?TensorFlow可以帮你实现。准备扩大并在GPU上更快的训练模型而不改变任何结点?TensorFlow可以帮你实现。想在移动端部署训练的模型作为产品中的一部分?TensorFlow可以帮你实现。改变你的想法并且想在云上运行模型来作为服务?用Docker进行容器化,TensorFlow能很好的工作。
Connect Research and Production
Gone are the days when moving a machine learning idea from research to product require a major rewrite. At Google, research scientists experiment with new algorithms in TensorFlow, and product teams use TensorFlow to train and serve models live to real customers. Using TensorFlow allows industrial researchers to push ideas to products faster, and allows academic researchers to share code more directly and with greater scientific reproducibility.
连接研究与产品
当将机器学习想法从研究转化成产品时需要进行主要的重写的日子已经过去了。在Google,研究科学家在TensorFlow中进行新算法的实验,产品团队用TensorFlow来训练模型并实时的使用模型为真实的消费者服务。使用TensorFlow可以让产品研究人员更快的将想法变为产品,可以让学术研究人员更直接的共享代码,具有更大的科学再现性。
Auto-Differentiation
Gradient based machine learning algorithms will benefit from TensorFlow’s automatic differentiation capabilities. As a TensorFlow user, you define the computational architecture of your predictive model, combine that with your objective function, and just add data – TensorFlow handles computing the derivatives for you. Computing the derivative of some values w.r.t. other values in the model just extends your graph, so you can always see exactly what’s going on.
自动微分
基于梯度的机器学习算法将能从TensorFlow的自动微分能力中受益。作为一个TensorFlow用户,你可以定义你自己的预测模型的计算结构,结合你的目标函数,只需要添加数据——TensorFlow为你计算导数。计算一些值的导数,而模型中的其它值只是扩展你的图,因此你总是能确切的看到发生了什么。
Language Options
TensorFlow comes with an easy to use Python interface and a no-nonsense C++ interface to build and execute your computational graphs. Write stand-alone TensorFlow Python or C++ programs, or try things out in an interactive TensorFlow iPython notebook where you can keep notes, code, and visualizations logically grouped. This is just the start though – we’re hoping to entice you to contribute interfaces to your favorite language – be it Lua, JavaScript, or R.
语言选择
TensorFlow附带很容易使用的Python接口和使用的C++接口来构建并执行你的计算图。在交互的TensorFlow iPython笔记本中编写独立的TensorFlow Python或C++程序,或尝试一些东西,iPython笔记本可以存储笔记,代码和逻辑分组可视化。然而这仅仅只是一个开始——我们希望吸引你贡献你最爱的语言的接口——它可以是Lua,Javascript或R。
Maximize Performance
Want to use every ounce of muscle in that workstation with 32 CPU cores and 4 GPU cards? With first-class support for threads, queues, and asynchronous computation, TensorFlow allows you to make the most of your available hardware. Freely assign compute elements of your TensorFlow graph to different devices, and let TensorFlow handle the copies.
最大化性能
想要充分利用具有32核CPU和4块GPU的工作站的性能吗?TensorFlow对线程、队列和异步计算具有一流的支持,TensorFlow可以让你最大程度的利用你的可用硬件,可以自由的将你的TensorFlow图中计算元素分配到不同的设备上,让TensorFlow来处理副本。
Who Can Use TensorFlow?
TensorFlow is for everyone. It’s for students, researchers, hobbyists, hackers, engineers, developers, inventors and innovators and is being open sourced under the Apache 2.0 open source license.
TensorFlow is not complete; it is intended to be built upon and extended. We have made an initial release of the source code, and continue to work actively to make it better. We hope to build an active open source community that drives the future of this library, both by providing feedback and by actively contributing to the source code.
谁可以使用TensorFlow?
TensorFlow是给每一个人的。它是给学生、研究人员、业余爱好者、黑客、工程师、开发人员、发明家和创新者的,它是根据Apache 2.0开源协议开源的。
TensorFlow不是完整的;它将要建立和扩展。我们已经制作了源代码的初始版本,会继续积极的工作使它更好。我们希望建立一个主动的开源社区来推动这个库的未来,提供反馈并且积极的贡献源代码。
Why Did Google Open Source This?
If TensorFlow is so great, why open source it rather than keep it proprietary? The answer is simpler than you might think: We believe that machine learning is a key ingredient to the innovative products and technologies of the future. Research in this area is global and growing fast, but lacks standard tools. By sharing what we believe to be one of the best machine learning toolboxes in the world, we hope to create an open standard for exchanging research ideas and putting machine learning in products. Google engineers really do use TensorFlow in user-facing products and services, and our research group intends to share TensorFlow implementations along side many of our research publications.
为什么Google开源TensorFlow?
如果TensorFlow是如此之大,为什么对它开源而不是保留它的所有权?回答可能比你想象的简单:我们相信机器学习是将来产品创新和技术创新的一个关键要素。这个领域的研究是全球性的并且发展迅速,但是缺少标准的工具。通过分享TensorFow,我们认为它是世界上最好的机器学习工具之一,我们希望创建一个开放的标准来交流研究想法并把机器学习应用到产品中。Google工程师在面向用户的产品和服务中真正的在使用TensorFlow,我们的研究组计划与我们的许多研究出版物一起共享TensorFlow的实现。
Introduction
Let’s get you up and running with TensorFlow!
让我们开始学习并运行TensorFlow!
But before we even get started, let’s peek at what TensorFlow code looks like in the Python API, so you have a sense of where we’re headed.
但在我们开始之前,让我们先看一眼在Python API中TensorFlow代码什么样,对我们要学习的东西有点感觉。
Here’s a little Python program that makes up some data in two dimensions, and then fits a line to it.
下面是一个Python小程序,它在二维空间构造了一些数据,并用一条直线来拟合这些数据。
1 | import tensorflow as tf |
The first part of this code builds the data flow graph. TensorFlow does not actually run any computation until the session is created and the run function is called.
代码的第一部分构建数据流图。在session
创建和run
函数调用之后,TensorFlow才开始真正的进行计算。
To whet your appetite further, we suggest you check out what a classical machine learning problem looks like in TensorFlow. In the land of neural networks the most “classic” classical problem is the MNIST handwritten digit classification. We offer two introductions here, one for machine learning newbies, and one for pros. If you’ve already trained dozens of MNIST models in other software packages, please take the red pill. If you’ve never even heard of MNIST, definitely take the blue pill. If you’re somewhere in between, we suggest skimming blue, then red.
为了进一步提高你的兴趣,我们建议你查看一下在TensorFlow中经典的机器学习问题是什么样子。在神经网络领域,最经典的问题是MNIST手写字符识别问题。这儿我们有两个介绍,一个是为初学者准备的,一个是为专业人士准备的。如果你已经用其它的软件包训练了许多MNIST模型,请点红色的药丸。如果你从未听过MNIST,请点蓝色药丸。如果你介于两者之间,我们建议你先略读蓝色部分,再看红色部分。
图像许可CC BY-SA 4.0; 原作者W. Carter
If you’re already sure you want to learn and install TensorFlow you can skip these and charge ahead. Don’t worry, you’ll still get to see MNIST – we’ll also use MNIST as an example in our technical tutorial where we elaborate on TensorFlow features.
如果你已经确定你想学习并安装TensorFlow,你可以跳过这些直接看接下来的东西。不用担心,你仍会看到MNIST——我们也将使用MNIST作为技术教程中的一个例子来阐述TensorFlow的特性。