TensorFlow,为什么选择python语言? [英] TensorFlow, why was python the chosen language?

查看:102
本文介绍了TensorFlow,为什么选择python语言?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

最近,我开始研究深度学习和其他ML技术,并开始寻找简化构建网络并对其进行培训的框架,然后我发现TensorFlow在该领域经验不足,对我来说,似乎如果使用深度学习,速度是使大型ML系统变得更大的一个重要因素,那么为什么Google选择python来制造TensorFlow?在可以编译且无法解释的语言上进行翻译会更好吗?

I recently started studying deep learning and other ML techniques, and I started searching for frameworks that simplify the process of build a net and training it, then I found TensorFlow, having little experience in the field, for me, it seems that speed is a big factor for making a big ML system even more if working with deep learning, so why python was chosen by Google to make TensorFlow? Wouldn't it be better to make it over an language that can be compiled and not interpreted?

相对于C ++这样的语言,使用Python进行机器学习有什么优势?

What are the advantages of using Python over a language like C++ for machine learning?

推荐答案

关于TensorFlow的最重要认识是,核心不是用Python编写的:结合高度优化的C ++和CUDA(NVIDIA用于GPU编程的语言).反过来,大多数情况是通过使用 Eigen (高性能C ++和CUDA数字库)和 NVidia的cuDNN (针对

The most important thing to realize about TensorFlow is that, for the most part, the core is not written in Python: It's written in a combination of highly-optimized C++ and CUDA (Nvidia's language for programming GPUs). Much of that happens, in turn, by using Eigen (a high-performance C++ and CUDA numerical library) and NVidia's cuDNN (a very optimized DNN library for NVidia GPUs, for functions such as convolutions).

TensorFlow的模型是程序员使用某种语言"(很可能是Python!)来表达模型.该模型以TensorFlow构造编写,例如:

The model for TensorFlow is that the programmer uses "some language" (most likely Python!) to express the model. This model, written in the TensorFlow constructs such as:

h1 = tf.nn.relu(tf.matmul(l1, W1) + b1)
h2 = ...

在运行Python时,实际上不会执行

.相反,实际上创建的是一个数据流图,其中说要接受特定的输入,应用特定的操作,供应结果作为其他操作的输入,依此类推. 此模型由快速的C ++代码执行,并且在大多数情况下,操作之间传递的数据永远不会复制回Python代码.

is not actually executed when the Python is run. Instead, what's actually created is a dataflow graph that says to take particular inputs, apply particular operations, supply the results as the inputs to other operations, and so on. This model is executed by fast C++ code, and for the most part, the data going between operations is never copied back to the Python code.

然后,程序员通过拉动节点来驱动"该模型的执行-通常在Python中进行训练,在Python中有时在原始C ++中进行服务:

Then the programmer "drives" the execution of this model by pulling on nodes -- for training, usually in Python, and for serving, sometimes in Python and sometimes in raw C++:

sess.run(eval_results)

此Python(或C ++函数调用)使用对C ++的进程内调用或 RPC ,以使分布式版本调用C ++ TensorFlow服务器以使其执行,然后将结果复制回去.

This one Python (or C++ function call) uses either an in-process call to C++ or an RPC for the distributed version to call into the C++ TensorFlow server to tell it to execute, and then copies back the results.

因此,话虽这么说,让我们重新表述一下这个问题:为什么TensorFlow选择Python作为表达和控制模型训练的第一种受支持的语言?

答案很简单:对于许多数据科学家和机器学习专家来说,Python可能是最舒适的语言,它们也易于集成并控制C ++后端,同时是通用的,在Google内部和外部广泛使用,并且是开源的.鉴于使用TensorFlow的基本模型,Python的性能并不那么重要,因此很自然.这也是一个巨大的优点, NumPy 使得在Python中进行预处理变得容易,而且性能很高- -在将其送入TensorFlow进行真正占用大量CPU的操作之前.

The answer to that is simple: Python is probably the most comfortable language for a large range of data scientists and machine learning experts that's also that easy to integrate and have control a C++ backend, while also being general, widely-used both inside and outside of Google, and open source. Given that with the basic model of TensorFlow, the performance of Python isn't that important, it was a natural fit. It's also a huge plus that NumPy makes it easy to do pre-processing in Python -- also with high performance -- before feeding it in to TensorFlow for the truly CPU-heavy things.

在表达执行模型时不使用的模型也有很多复杂性-形状推断(例如,如果您做matmul(A,B),结果数据的形状是什么?)并且自动渐变计算.事实证明,能够用Python表达这些内容真是太好了,尽管我认为从长远来看,它们可能会转移到C ++后端,从而使添加其他语言变得更加容易.

There's also a bunch of complexity in expressing the model that isn't used when executing it -- shape inference (e.g., if you do matmul(A, B), what is the shape of the resulting data?) and automatic gradient computation. It turns out to have been nice to be able to express those in Python, though I think in the long term they'll probably move to the C++ backend to make adding other languages easier.

(当然,希望是将来支持其他语言来创建和表达模型.使用其他几种语言进行推理已经非常简单了-C ++现在可以工作了,Facebook的某人提供了

(The hope, of course, is to support other languages in the future for creating and expressing models. It's already quite straightforward to run inference using several other languages -- C++ works now, someone from Facebook contributed Go bindings that we're reviewing now, etc.)

这篇关于TensorFlow,为什么选择python语言?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆